Tflite模型引发加载时没有名为“ _tensorflow_wrap_interpreter_wrapper”的模块错误

时间:2019-04-15 08:48:43

标签: python object-detection tensorflow-lite

我正在尝试在jupyter笔记本上运行从keras模型转换而来的tflite模型(keras模型已通过coreml部署到iphone并运行良好),并尝试了question中的解决方案,但我坚持使用代码的第五行。 并得到下面的错误。

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
c:\users\appdata\local\programs\python\python35\lib\site-        packages\tensorflow\contrib\lite\python\interpreter_wrapper\tensorflow_wrap_inte    rpreter_wrapper.py in swig_import_helper()
     17         try:
---> 18             fp, pathname, description =     imp.find_module('_tensorflow_wrap_interpreter_wrapper', [dirname(__file__)])    
 19         except ImportError:

c:\users\appdata\local\programs\python\python35\lib\imp.py in     find_module(name, path)
    295     else:
--> 296         raise ImportError(_ERR_MSG.format(name), name=name)
297 

ImportError: No module named '_tensorflow_wrap_interpreter_wrapper'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-6-2686a893d9f6> in <module>
----> 1 interpreter =     tf.contrib.lite.Interpreter(model_path="coco_ssd_mobilenet_v1_1.0_quant_2018_06_    29/detect.tflite")
      2 #interpreter =     tf.contrib.lite.Interpreter(model_path="cembugra.tflite")
      3 
      4 #interpreter =     tf.contrib.lite.Interpreter(model_path="converted_model.tflite")

c:\users\appdata\local\programs\python\python35\lib\site-    packages\tensorflow\contrib\lite\python\interpreter.py in __init__(self,     model_path, model_content)
     50     if model_path and not model_content:
     51       self._interpreter = (
---> 52               _interpreter_wrapper.InterpreterWrapper_CreateWrapperCPPFromFile(
     53               model_path))
     54       if not self._interpreter:

c:\users\appdata\local\programs\python\python35\lib\site-    packages\tensorflow\python\util\lazy_loader.py in __getattr__(self, item)
     51 
     52   def __getattr__(self, item):
---> 53     module = self._load()
     54     return getattr(module, item)
     55 

c:\users\appdata\local\programs\python\python35\lib\site-    packages\tensorflow\python\util\lazy_loader.py in _load(self)
     40   def _load(self):
     41     # Import the target module and insert it into the parent's     namespace
---> 42     module = importlib.import_module(self.__name__)
     43     self._parent_module_globals[self._local_name] = module
     44 

c:\users\appdata\local\programs\python\python35\lib\importlib\__init__.py in     import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

c:\users\appdata\local\programs\python\python35\lib\importlib\_bootstrap.py     in _gcd_import(name, package, level)

c:\users\appdata\local\programs\python\python35\lib\importlib\_bootstrap.py     in _find_and_load(name, import_)

c:\users\appdata\local\programs\python\python35\lib\importlib\_bootstrap.py     in _find_and_load_unlocked(name, import_)

c:\users\appdata\local\programs\python\python35\lib\importlib\_bootstrap.py     in _load_unlocked(spec)

c:\users\appdata\local\programs\python\python35\lib\importlib\_bootstrap_externa    l.py in exec_module(self, module)

c:\users\appdata\local\programs\python\python35\lib\importlib\_bootstrap.py     in _call_with_frames_removed(f, *args, **kwds)

c:\users\appdata\local\programs\python\python35\lib\site-    packages\tensorflow\contrib\lite\python\interpreter_wrapper\tensorflow_wrap_inte    rpreter_wrapper.py in <module>
     26                 fp.close()
     27             return _mod
---> 28     _tensorflow_wrap_interpreter_wrapper = swig_import_helper()
     29     del swig_import_helper
     30 else:

c:\users\appdata\local\programs\python\python35\lib\site-packages\tensorflow\contrib\lite\python\interpreter_wrapper\tensorflow_wrap_interpreter_wrapper.py in swig_import_helper()
 18             fp, pathname, description =     imp.find_module('_tensorflow_wrap_interpreter_wrapper', [dirname(__file__)])
 19         except ImportError:
---> 20             import _tensorflow_wrap_interpreter_wrapper
     21             return _tensorflow_wrap_interpreter_wrapper
     22         if fp is not None:

ImportError: No module named '_tensorflow_wrap_interpreter_wrapper'

我已经用谷歌搜索了异常,但没有发现任何异常。

import numpy as np
import tensorflow as tf

# Load TFLite model and allocate tensors.
interpreter = tf.contrib.lite.Interpreter(model_path="converted_model.tflite")

我相信,如果我可以通过这一步骤,那么将来不会有任何问题,并且可以轻松地进行目标检测。 谢谢。

1 个答案:

答案 0 :(得分:0)

似乎Interpreter存在问题,在Tensorflow安装中未发现。您可以尝试一下,

pip install tf-nightly

然后将tf.contrib.lite.Interpreter更改为tf.lite.Interpreter

它将解决您的问题。