• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #ifndef TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_BUILDERS_ACTIVATION_LAYER_BUILDER_H_
16 #define TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_BUILDERS_ACTIVATION_LAYER_BUILDER_H_
17 
18 #include "tensorflow/lite/c/builtin_op_data.h"
19 #include "tensorflow/lite/delegates/coreml/builders/op_builder.h"
20 
21 namespace tflite {
22 namespace delegates {
23 namespace coreml {
24 
25 class ActivationLayerBuilder : public OpBuilder {
26  public:
ActivationLayerBuilder(GraphBuilder * graph_builder)27   explicit ActivationLayerBuilder(GraphBuilder* graph_builder)
28       : OpBuilder(graph_builder) {}
29 
ActivationLayerBuilder(GraphBuilder * graph_builder,TfLiteFusedActivation activation)30   explicit ActivationLayerBuilder(GraphBuilder* graph_builder,
31                                   TfLiteFusedActivation activation)
32       : OpBuilder(graph_builder), activation_(activation) {}
33 
34   const std::string& DebugName() override;
35 
36   CoreML::Specification::NeuralNetworkLayer* Build() override;
37 
SetActivation(TfLiteFusedActivation activation)38   void SetActivation(TfLiteFusedActivation activation) {
39     activation_ = activation;
40   }
41 
SetAlpha(float alpha)42   void SetAlpha(float alpha) { alpha_ = alpha; }
43 
44   TfLiteStatus PopulateSubgraph(TfLiteContext* context) override;
45 
46   TfLiteStatus RegisterInputs(const TfLiteIntArray* inputs,
47                               TfLiteContext* context) override;
48 
49   TfLiteStatus RegisterOutputs(const TfLiteIntArray* outputs,
50                                TfLiteContext* context) override;
51 
52  private:
53   TfLiteFusedActivation activation_;
54   float alpha_ = 1.0f;
55 };
56 
57 }  // namespace coreml
58 }  // namespace delegates
59 }  // namespace tflite
60 #endif  // TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_BUILDERS_ACTIVATION_LAYER_BUILDER_H_
61