• 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 #include "tensorflow/lite/delegates/coreml/builders/threshold_layer_builder.h"
16 
17 #include "tensorflow/lite/c/common.h"
18 
19 namespace tflite {
20 namespace delegates {
21 namespace coreml {
22 
DebugName()23 const std::string& ThresholdLayerBuilder::DebugName() {
24   if (debug_name_.empty()) SetDebugName("ThresholdLayerBuilder", node_id_);
25   return debug_name_;
26 }
27 
Build()28 CoreML::Specification::NeuralNetworkLayer* ThresholdLayerBuilder::Build() {
29   if (layer_ == nullptr) {
30     layer_.reset(new CoreML::Specification::NeuralNetworkLayer);
31   }
32   layer_->set_name(DebugName());
33   layer_->mutable_unary()->set_alpha(alpha_);
34   layer_->mutable_unary()->set_scale(scale_);
35   layer_->mutable_unary()->set_type(
36       CoreML::Specification::UnaryFunctionLayerParams::THRESHOLD);
37   return layer_.release();
38 }
39 
RegisterInputs(const TfLiteIntArray * inputs,TfLiteContext * context)40 TfLiteStatus ThresholdLayerBuilder::RegisterInputs(const TfLiteIntArray* inputs,
41                                                    TfLiteContext* context) {
42   if (inputs->size != 1) {
43     TF_LITE_KERNEL_LOG(context, "Threshold: Wrong # of inputs!.");
44     return kTfLiteError;
45   }
46   AddInput(inputs->data[0]);
47   return kTfLiteOk;
48 }
49 
RegisterOutputs(const TfLiteIntArray * outputs,TfLiteContext * context)50 TfLiteStatus ThresholdLayerBuilder::RegisterOutputs(
51     const TfLiteIntArray* outputs, TfLiteContext* context) {
52   if (outputs->size != 1) {
53     TF_LITE_KERNEL_LOG(context, "Threshold: Wrong # of outputs!.");
54     return kTfLiteError;
55   }
56   graph_builder_->AddTensorWithID(outputs->data[0], GetOutput(context));
57   return kTfLiteOk;
58 }
59 
CreateThresholdLayerBuilder(GraphBuilder * graph_builder)60 OpBuilder* CreateThresholdLayerBuilder(GraphBuilder* graph_builder) {
61   return new ThresholdLayerBuilder(graph_builder);
62 }
63 
64 }  // namespace coreml
65 }  // namespace delegates
66 }  // namespace tflite
67