diff options
Diffstat (limited to 'tensorflow/contrib/lite/python/interpreter_wrapper/interpreter_wrapper.h')
-rw-r--r-- | tensorflow/contrib/lite/python/interpreter_wrapper/interpreter_wrapper.h | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tensorflow/contrib/lite/python/interpreter_wrapper/interpreter_wrapper.h b/tensorflow/contrib/lite/python/interpreter_wrapper/interpreter_wrapper.h index febfd2dc56..3e03751da4 100644 --- a/tensorflow/contrib/lite/python/interpreter_wrapper/interpreter_wrapper.h +++ b/tensorflow/contrib/lite/python/interpreter_wrapper/interpreter_wrapper.h @@ -15,13 +15,13 @@ limitations under the License. #ifndef TENSORFLOW_CONTRIB_LITE_PYTHON_INTERPRETER_WRAPPER_INTERPRETER_WRAPPER_H_ #define TENSORFLOW_CONTRIB_LITE_PYTHON_INTERPRETER_WRAPPER_INTERPRETER_WRAPPER_H_ +// Place `<locale>` before <Python.h> to avoid build failures in macOS. +#include <locale> #include <memory> #include <string> #include <vector> -// Place `<locale>` before <Python.h> to avoid build failures in macOS. #include <Python.h> -#include <locale> // We forward declare TFLite classes here to avoid exposing them to SWIG. namespace tflite { @@ -69,14 +69,28 @@ class InterpreterWrapper { PyObject* tensor(PyObject* base_object, int i); private: - InterpreterWrapper(std::unique_ptr<tflite::FlatBufferModel> model, - std::unique_ptr<PythonErrorReporter> error_reporter); + // Helper function to construct an `InterpreterWrapper` object. + // It only returns InterpreterWrapper if it can construct an `Interpreter`. + // Otherwise it returns `nullptr`. + static InterpreterWrapper* CreateInterpreterWrapper( + std::unique_ptr<tflite::FlatBufferModel> model, + std::unique_ptr<PythonErrorReporter> error_reporter, + std::string* error_msg); + + InterpreterWrapper( + std::unique_ptr<tflite::FlatBufferModel> model, + std::unique_ptr<PythonErrorReporter> error_reporter, + std::unique_ptr<tflite::ops::builtin::BuiltinOpResolver> resolver, + std::unique_ptr<tflite::Interpreter> interpreter); // InterpreterWrapper is not copyable or assignable. We avoid the use of // InterpreterWrapper() = delete here for SWIG compatibility. InterpreterWrapper(); InterpreterWrapper(const InterpreterWrapper& rhs); + // The public functions which creates `InterpreterWrapper` should ensure all + // these member variables are initialized successfully. Otherwise it should + // report the error and return `nullptr`. const std::unique_ptr<tflite::FlatBufferModel> model_; const std::unique_ptr<PythonErrorReporter> error_reporter_; const std::unique_ptr<tflite::ops::builtin::BuiltinOpResolver> resolver_; |