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