1 /* Copyright 2020 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_RESHAPE_OP_BUILDER_H_ 16 #define TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_BUILDERS_RESHAPE_OP_BUILDER_H_ 17 18 #include "tensorflow/lite/c/common.h" 19 #include "tensorflow/lite/delegates/coreml/builders/op_builder.h" 20 21 namespace tflite { 22 namespace delegates { 23 namespace coreml { 24 // Builder for Reshape op in CoreML. 25 class ReshapeOpBuilder : public OpBuilder { 26 public: ReshapeOpBuilder(GraphBuilder * graph_builder)27 explicit ReshapeOpBuilder(GraphBuilder* graph_builder) 28 : OpBuilder(graph_builder) {} 29 const std::string& DebugName() override; 30 31 CoreML::Specification::NeuralNetworkLayer* Build() override; 32 33 TfLiteStatus RegisterInputs(const TfLiteIntArray* inputs, 34 TfLiteContext* context) override; 35 TfLiteStatus RegisterOutputs(const TfLiteIntArray* outputs, 36 TfLiteContext* context) override; 37 38 // Sets output shape of the Core ML reshape layer, given output shape and 39 // the input tensor's shape. 40 void SetShapeFromTensor(const TfLiteTensor* output_shape, 41 const TfLiteIntArray* input_shape); 42 void SetShapeFromIntArray(const TfLiteIntArray* output_shape, 43 const TfLiteIntArray* input_shape); 44 45 private: 46 std::vector<int> shape_; 47 // When channel dimension is changed, reshape should be done with HWC layout, 48 // thus transpose is required. (set with ReshapeLayerParams.mode) 49 bool need_transpose_ = false; 50 }; 51 52 } // namespace coreml 53 } // namespace delegates 54 } // namespace tflite 55 56 #endif // TENSORFLOW_LITE_EXPERIMENTAL_DELEGATES_COREML_BUILDERS_RESHAPE_OP_BUILDER_H_ 57