简体   繁体   English

ImportError:没有名为“ tensorflow.contrib.lite.python.tflite_convert”的模块

[英]ImportError: No module named 'tensorflow.contrib.lite.python.tflite_convert'

I tried tflite_convert to convert my saved_model.pb(object detection API) file to .tflite but when i execute this command on cmd on the directory of C:\\Users\\LENOVO-PC\\tensorflow> where tensorflow git is cloned, 我尝试tflite_convert将我的saved_model.pb(对象检测API)文件转换为.tflite,但是当我在C:\\Users\\LENOVO-PC\\tensorflow>目录上的cmd上执行此命令时,克隆了tensorflow git,

tflite_convert \ --output_file=/saved_model/maonani.tflite \ --saved_model_dir=/saved_model/saved_model

I get an error saying 我说错了

ImportError: No module named 'tensorflow.contrib.lite.python.tflite_convert'

the complete sourcelog is 完整的源日志是

C:\Users\LENOVO-PC\tensorflow>tflite_convert \ --output_file=/saved_model/maonani.tflite \ --saved_model_dir=/saved_model/saved_model
Traceback (most recent call last):
  File "c:\users\lenovo-pc\appdata\local\programs\python\python35\lib\runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\lenovo-pc\appdata\local\programs\python\python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\LENOVO-PC\AppData\Local\Programs\Python\Python35\Scripts\tflite_convert.exe\__main__.py", line 5, in <module>
ImportError: No module named 'tensorflow.contrib.lite.python.tflite_convert'

is there anyway to convert my .pb file to .tflite on WINDOWS? 反正在Windows上将我的.pb文件转换为.tflite吗?

Hi my solution was using linux in the following way Windows Subsystem for Linux - see 嗨,我的解决方案是以以下方式使用Linux的Windows子系统Linux- 请参阅

then install from store ubunto 然后从商店ubunto安装

then need to pip3 install --upgrade "tensorflow=1.7*" then if you try to run toco it would not be recognized. 然后需要pip3 install --upgrade“ tensorflow = 1.7 *”,那么如果您尝试运行toco,它将无法识别。

the solution is go to folder 解决方法是转到文件夹

~/.local/bin/

there you would find toco, this is a python file. 在那里您会找到toco,这是一个python文件。

run

python3 ~/.local/bin/toco

you would get the "exe" of toco. 您将获得toco的“ exe”。

to convert you can run the command explained in https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2-tflite/#2 转换可以运行命令解释 https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2-tflite/#2

just change the -graph_def_file=tf_files/retrained_graph.pb to --input_file=tf_files/retrained_graph.pb 只需将-graph_def_file = tf_files / retrained_graph.pb更改为--input_file = tf_files / retrained_graph.pb

Hope this helps someone 希望这可以帮助某人

Note: if you are missing pip3, you would need to install it 注意:如果您缺少pip3,则需要安装它

I follow the instruction on this site: 我按照此网站上的说明进行操作:

https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2-tflite/#2 https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2-tflite/#2

However, it seems that tflearn_convert doesn't support Windows anymore. 但是,似乎tflearn_convert不再支持Windows。 So i decided to use Ubuntu on Windows. 所以我决定在Windows上使用Ubuntu。 After having created a virtual environment to install tensorflow, i checked "toco" by typing toco in the terminal. 创建一个虚拟环境以安装tensorflow后,我通过在终端中键入toco来检查“ toco”。 And there go the instruction to use toco. 然后有使用toco的说明。

usage: /home/hieu/venv/bin/toco

Flags: 标志:

    --input_file=""                         string  Input file (model of any supported format). For Protobuf formats, both text and binary are supported regardless of file extension.
    --output_file=""                        string  Output file. For Protobuf formats, the binary format will be used.
    --input_format=""                       string  Input file format. One of: TENSORFLOW_GRAPHDEF, TFLITE.
    --output_format=""                      string  Output file format. One of TENSORFLOW_GRAPHDEF, TFLITE, GRAPHVIZ_DOT.
    --default_ranges_min=0.000000           float   If defined, will be used as the default value for the min bound of min/max ranges used for quantization.
    --default_ranges_max=0.000000           float   If defined, will be used as the default value for the max bound of min/max ranges used for quantization.
    --inference_type=""                     string  Target data type of arrays in the output file (for input_arrays, this may be overridden by inference_input_type). One of FLOAT, QUANTIZED_UINT8.
    --inference_input_type=""               string  Target data type of input arrays. If not specified, inference_type is used. One of FLOAT, QUANTIZED_UINT8.
    --input_type=""                         string  Deprecated ambiguous flag that set both --input_data_types and --inference_input_type.
    --input_types=""                        string  Deprecated ambiguous flag that set both --input_data_types and --inference_input_type. Was meant to be a comma-separated list, but this was deprecated before multiple-input-types was ever properly supported.
    --drop_fake_quant=false                 bool    Ignore and discard FakeQuant nodes. For instance, to generate plain float code without fake-quantization from a quantized graph.
    --reorder_across_fake_quant=false       bool    Normally, FakeQuant nodes must be strict boundaries for graph transformations, in order to ensure that quantized inference has the exact same arithmetic behavior as quantized training --- which is the whole point of quantized training and of FakeQuant nodes in the first place. However, that entails subtle requirements on where exactly FakeQuant nodes must be placed in the graph. Some quantized graphs have FakeQuant nodes at unexpected locations, that prevent graph transformations that are necessary in order to generate inference code for these graphs. Such graphs should be fixed, but as a temporary work-around, setting this reorder_across_fake_quant flag allows TOCO to perform necessary graph transformaitons on them, at the cost of no longer faithfully matching inference and training arithmetic.
    --allow_custom_ops=false                bool    If true, allow TOCO to create TF Lite Custom operators for all the unsupported TensorFlow ops.
    --drop_control_dependency=false         bool    If true, ignore control dependency requirements in input TensorFlow GraphDef. Otherwise an error will be raised upon control dependency inputs.
    --debug_disable_recurrent_cell_fusion=false     bool    If true, disable fusion of known identifiable cell subgraphs into cells. This includes, for example, specific forms of LSTM cell.

And many more... 还有很多...

After that, i used this command to convert file: 之后,我使用此命令来转换文件:

 toco --input_file="tf_files/retrained_graph.pb" --output_file="tf_files/optimized_graph.lite" --input_format="TENSORFLOW_GRAPHDEF" --output_format="TFLITE" --input_shape="1,224,224,3" --input_array="input" --output_array="final_result" --inference_type="FLOAT" --input_data_type="FLOAT"

Then optimized_graph.lite should be found in tf_files 然后optimized_graph.litetf_files发现

According to this thread : Tensorflow discussions 根据此主题: Tensorflow讨论

The issue really is that the module as of now is not supported on windows. 实际上,问题在于Windows至今不支持该模块。 You can follow the thread and see if there is an update regarding the same. 您可以关注该线程,查看是否有关于该线程的更新。

PS: some people claim that a git-clone and bazel build helped resloved the issue, instead of pip install, you can try that as well but have serious doubts if that will work. PS:有人声称git-clone和bazel构建有助于解决该问题,而不是点子安装,您也可以尝试这样做,但对是否可行感到严重怀疑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM