• 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_THRESHOLD_LAYER_BUILDER_H_
16 #define TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_BUILDERS_THRESHOLD_LAYER_BUILDER_H_
17 
18 #include "tensorflow/lite/delegates/coreml/builders/op_builder.h"
19 
20 namespace tflite {
21 namespace delegates {
22 namespace coreml {
23 
24 // Layer that provides threshold operation. Depending on scale, this can be used
25 // as max (scale > 0) or min (scale < 0), in combination with another negative
26 // linear activation layer) operation.
27 // TODO(karimnosseir): Generalize to other unary operators.
28 class ThresholdLayerBuilder : public OpBuilder {
29  public:
ThresholdLayerBuilder(GraphBuilder * graph_builder)30   explicit ThresholdLayerBuilder(GraphBuilder* graph_builder)
31       : OpBuilder(graph_builder) {}
32 
33   const std::string& DebugName() override;
34 
35   CoreML::Specification::NeuralNetworkLayer* Build() override;
36 
SetAlpha(float alpha)37   void SetAlpha(float alpha) { alpha_ = alpha; }
38 
SetScale(float scale)39   void SetScale(float scale) { scale_ = scale; }
40 
41   TfLiteStatus RegisterInputs(const TfLiteIntArray* inputs,
42                               TfLiteContext* context) override;
43 
44   TfLiteStatus RegisterOutputs(const TfLiteIntArray* outputs,
45                                TfLiteContext* context) override;
46 
47  private:
48   float alpha_ = 0.0f;
49   float scale_ = 1.0f;
50 };
51 
52 }  // namespace coreml
53 }  // namespace delegates
54 }  // namespace tflite
55 
56 #endif  // TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_BUILDERS_THRESHOLD_LAYER_BUILDER_H_
57