1 /* Copyright 2017 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_TOCO_TFLITE_SIMPLE_OPERATOR_H_ 16 #define TENSORFLOW_LITE_TOCO_TFLITE_SIMPLE_OPERATOR_H_ 17 18 #include "tensorflow/lite/toco/tflite/operator.h" 19 20 namespace toco { 21 22 namespace tflite { 23 24 // Simple operators don't have any configuration options and can be trivially 25 // serialized and deserialized. Note that most of toco's operators will 26 // likely be supported as builtin operators in TF Lite. Simple (and custom) 27 // operators are mostly a convenience for the times when tf.mini supports more 28 // operators than TF Lite. 29 // 30 // Template argument T must derive from ::toco::Operator. 31 template <typename T> 32 class SimpleOperator : public BaseOperator { 33 public: 34 using BaseOperator::BaseOperator; Serialize(const Operator & op,flatbuffers::FlatBufferBuilder * builder)35 Options Serialize(const Operator& op, 36 flatbuffers::FlatBufferBuilder* builder) const override { 37 return Options(); 38 } Deserialize(const BuiltinOptions * builtin_options,const CustomOptions * custom_options)39 std::unique_ptr<Operator> Deserialize( 40 const BuiltinOptions* builtin_options, 41 const CustomOptions* custom_options) const override { 42 return std::unique_ptr<Operator>(new T); 43 } 44 GetVersion(const OperatorSignature & op_signature)45 int GetVersion(const OperatorSignature& op_signature) const override { 46 return 1; 47 } 48 }; 49 50 } // namespace tflite 51 52 } // namespace toco 53 54 #endif // TENSORFLOW_LITE_TOCO_TFLITE_SIMPLE_OPERATOR_H_ 55