Home | History | Annotate | Download | only in tools
      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_CONTRIB_LITE_TOOLS_MUTABLE_OP_RESOLVER_H_
     16 #define TENSORFLOW_CONTRIB_LITE_TOOLS_MUTABLE_OP_RESOLVER_H_
     17 
     18 #include <map>
     19 #include "tensorflow/contrib/lite/context.h"
     20 #include "tensorflow/contrib/lite/model.h"
     21 
     22 // Needed to resolve unordered_set hash on older compilers.
     23 namespace std {
     24 template <>
     25 struct hash<tflite::BuiltinOperator> {
     26   size_t operator()(const tflite::BuiltinOperator& op) const {
     27     return std::hash<int>()(op);
     28   }
     29 };
     30 }  // namespace std
     31 
     32 namespace tflite {
     33 
     34 // An OpResolver that is mutable, also used as the op in gen_op_registration.
     35 // A typical usage:
     36 //   MutableOpResolver resolver;
     37 //   resolver.AddBuiltin(BuiltinOperator_ADD, Register_ADD());
     38 //   resolver.AddCustom("CustomOp", Register_CUSTOM_OP());
     39 //   InterpreterBuilder(model, resolver)(&interpreter);
     40 class MutableOpResolver : public OpResolver {
     41  public:
     42   MutableOpResolver() {}
     43   TfLiteRegistration* FindOp(tflite::BuiltinOperator op) const override;
     44   TfLiteRegistration* FindOp(const char* op) const override;
     45   void AddBuiltin(tflite::BuiltinOperator op, TfLiteRegistration* registration);
     46   void AddCustom(const char* name, TfLiteRegistration* registration);
     47 
     48  private:
     49   std::map<int, TfLiteRegistration*> builtins_;
     50   std::map<std::string, TfLiteRegistration*> custom_ops_;
     51 };
     52 
     53 }  // namespace tflite
     54 
     55 #endif  // TENSORFLOW_CONTRIB_LITE_TOOLS_MUTABLE_OP_RESOLVER_H_
     56