swish.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/node.hpp"
8 #include "ngraph/op/op.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace v4
15  {
16  /// \brief A Swish Activation Function
17  /// f(x) = x / (1.0 + exp(-beta * x)) or
18  /// f(x) = x * sigmoid(beta * x)
19  ///
20  class NGRAPH_API Swish : public ngraph::op::Op
21  {
22  public:
23  static constexpr NodeTypeInfo type_info{"Swish", 4};
24  const NodeTypeInfo& get_type_info() const override { return type_info; }
25  Swish() = default;
26 
27  /// \brief Constructs an Swish operation.
28  ///
29  /// \param data Input tensor
30  /// \param beta Scalar with beta value. If the argument is not specified then use
31  /// the default value 1.0
32  Swish(const Output<Node>& arg, const Output<Node>& beta);
33  explicit Swish(const Output<Node>& arg);
34 
35  bool visit_attributes(AttributeVisitor& visitor) override;
36  void validate_and_infer_types() override;
37 
38  virtual std::shared_ptr<Node>
39  clone_with_new_inputs(const OutputVector& new_args) const override;
40  bool evaluate(const HostTensorVector& outputs,
41  const HostTensorVector& inputs) const override;
42  bool has_evaluate() const override;
43  };
44  } // namespace v4
45  } // namespace op
46 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
A Swish Activation Function f(x) = x / (1.0 + exp(-beta * x)) or f(x) = x * sigmoid(beta * x)
Definition: swish.hpp:21
Swish(const Output< Node > &arg, const Output< Node > &beta)
Constructs an Swish operation.
const NodeTypeInfo & get_type_info() const override
Definition: swish.hpp:24
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27