swish.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 
17 #pragma once
18 
19 #include "ngraph/node.hpp"
20 #include "ngraph/op/op.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace v4
27  {
28  /// \brief A Swish Activation Function
29  /// f(x) = x / (1.0 + exp(-beta * x)) or
30  /// f(x) = x * sigmoid(beta * x)
31  ///
32  class NGRAPH_API Swish : public ngraph::op::Op
33  {
34  public:
35  static constexpr NodeTypeInfo type_info{"Swish", 4};
36  const NodeTypeInfo& get_type_info() const override { return type_info; }
37  Swish() = default;
38 
39  /// \brief Constructs an Swish operation.
40  ///
41  /// \param data Input tensor
42  /// \param beta Scalar with beta value. If the argument is not specified then use
43  /// the default value 1.0
44  Swish(const Output<Node>& arg, const Output<Node>& beta);
45  explicit Swish(const Output<Node>& arg);
46 
47  bool visit_attributes(AttributeVisitor& visitor) override;
48  void validate_and_infer_types() override;
49 
50  virtual std::shared_ptr<Node>
51  clone_with_new_inputs(const OutputVector& new_args) const override;
52  bool evaluate(const HostTensorVector& outputs,
53  const HostTensorVector& inputs) const override;
54  };
55  }
56  }
57 }
ngraph::op::v4::Swish::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: swish.hpp:36
ngraph::op::v4::Swish::Swish
Swish(const Output< Node > &arg, const Output< Node > &beta)
Constructs an Swish operation.
ngraph::op::v4::Swish::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v4::Swish
A Swish Activation Function f(x) = x / (1.0 + exp(-beta * x)) or f(x) = x * sigmoid(beta * x)
Definition: swish.hpp:33
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29