[英]Tensorflow TocoConverter gives toco_from_protos error
I basically used freeze_graph to freeze the model and then tried to use TocoConverter to convert the model to tflite, however it gives me the error:我基本上使用 freeze_graph 来冻结模型,然后尝试使用 TocoConverter 将模型转换为 tflite,但是它给了我错误:
RuntimeError: TOCO failed see console for info.
b'/bin/sh: 1: toco_from_protos: not found\n'
None
Below is my code:下面是我的代码:
graph_def_file = './frozen_model2.pb'
input_arrays = ['IteratorGetNext']
output_arrays = ['model/fc_result/prediction/BiasAdd']
converter = tf.contrib.lite.TocoConverter.from_frozen_graph(
graph_def_file, input_arrays, output_arrays)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
Any help would be much appreciated!!!任何帮助将非常感激!!!
The error b'/bin/sh: 1: toco_from_protos: not found\\n'
indicates that the shell command toco_from_protos
is not found.错误
b'/bin/sh: 1: toco_from_protos: not found\\n'
表示b'/bin/sh: 1: toco_from_protos: not found\\n'
shell 命令toco_from_protos
。 I'm guessing toco --help
doesn't work for you either.我猜
toco --help
也不适合你。
I built Tensorflow 1.9.0 from source so I assume I must have screwed up a step where shell commands like toco
and toco_from_protos
get set up.我从源代码构建了 Tensorflow 1.9.0,所以我想我一定搞砸了一个步骤,在这个步骤中,像
toco
和toco_from_protos
这样的 shell 命令被设置。
Anyway, my traceback was this:无论如何,我的回溯是这样的:
File "/home/casey/anaconda3/envs/mnist/lib/python3.6/site-packages/tensorflow/contrib/lite/python/lite.py", line 330, in convert
dump_graphviz_video=self.dump_graphviz_video)
File "/home/casey/anaconda3/envs/mnist/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert.py", line 263, in toco_convert
input_data.SerializeToString())
File "/home/casey/anaconda3/envs/mnist/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert.py", line 107, in toco_convert_protos
(stdout, stderr))
RuntimeError: TOCO failed see console for info.
b'/bin/sh: 1: toco_from_protos: not found\n'
None
If you follow the traceback to line 107 in [python path]/site-packages/tensorflow/contrib/lite/python/convert.py
, you'll see there is some logic in the definition for toco_convert_protos()
to run toco_from_protos
as a shell command:如果你按照回溯到
[python path]/site-packages/tensorflow/contrib/lite/python/convert.py
第 107 行,你会看到toco_convert_protos()
的定义中有一些逻辑来运行toco_from_protos
作为外壳命令:
# TODO(aselle): When toco does not use fatal errors for failure, we can
# switch this on.
if not _toco_from_proto_bin:
return _toco_python.TocoConvert(
model_flags_str, toco_flags_str, input_data_str)
with _tempfile.NamedTemporaryFile() as fp_toco, \
_tempfile.NamedTemporaryFile() as fp_model, \
_tempfile.NamedTemporaryFile() as fp_input, \
_tempfile.NamedTemporaryFile() as fp_output:
fp_model.write(model_flags_str)
fp_toco.write(toco_flags_str)
fp_input.write(input_data_str)
fp_model.flush()
fp_toco.flush()
fp_input.flush()
cmd = [
_toco_from_proto_bin, fp_model.name, fp_toco.name, fp_input.name,
fp_output.name
]
cmdline = " ".join(cmd)
proc = _subprocess.Popen(
cmdline,
shell=True,
stdout=_subprocess.PIPE,
stderr=_subprocess.STDOUT,
close_fds=True)
stdout, stderr = proc.communicate()
exitcode = proc.returncode
if exitcode == 0:
stuff = fp_output.read()
return stuff
else:
raise RuntimeError("TOCO failed see console for info.\n%s\n%s\n" %
(stdout, stderr))
If your toco
and toco_from_protos
shell commands aren't working then obviously this step will fail.如果您的
toco
和toco_from_protos
shell 命令不起作用,那么这一步显然会失败。
I made this change as a workaround in [python path]/site-packages/tensorflow/contrib/lite/python/convert.py
, to force the first case to return:我将此更改作为
[python path]/site-packages/tensorflow/contrib/lite/python/convert.py
一种解决方法,以强制第一种情况返回:
if _toco_from_proto_bin:
# if not _toco_from_proto_bin: # comment out this line to force return
return _toco_python.TocoConvert(
model_flags_str, toco_flags_str, input_data_str)
Janky, but it got the job done for me. Janky,但它为我完成了工作。 The proper solution would probably be to reinstall a version of Tensorflow that has working
toco
or redo the bazel build if you are building from source.如果您从源代码构建,正确的解决方案可能是重新安装具有工作
toco
的 Tensorflow 版本或重做 bazel 构建。
Make sure that the toco scripts are in your search path.确保 toco 脚本在您的搜索路径中。 Check PATH variable.
检查 PATH 变量。
It seems that they are installed in /home/user/.local/bin
so add this to PATH
variable.它们似乎安装在
/home/user/.local/bin
因此将其添加到PATH
变量中。
You have two options你有两个选择
I just experienced this problem when quantizing a model into integer-precision.我刚刚在将模型量化为整数精度时遇到了这个问题。
RuntimeError: TOCO failed see console for info.
b'/bin/sh: 1: toco_from_protos: not found\n'
The key is to find where does toco_from_protos
actually reside.关键是要找到
toco_from_protos
实际驻留的位置。
I use locate
command to search across ALL files in my Linux system.我使用
locate
命令在我的 Linux 系统中搜索所有文件。 (newly installed Linux may need to call updatedb
on the first time, to create an initial database). (新安装的 Linux 可能需要在第一次调用
updatedb
来创建初始数据库)。
bash > locate toco_from
result > /usr/local/intelpython3/bin/toco_from_protos
Bingo, let see if there are more things in this folder Bingo,看看这个文件夹里有没有更多的东西
ls /usr/local/intelpython3/bin/toco*
/usr/local/intelpython3/bin/toco
/usr/local/intelpython3/bin/toco_from_protos
My custom python installation requires manual configuration in order to be properly exposed to PATH我的自定义 python 安装需要手动配置才能正确暴露给 PATH
So I added the following lines in my ~/.profile
所以我在
~/.profile
添加了以下几行
PYTHONBIN=/usr/local/intelpython3/bin
export PATH=$PATH:$PYTHONBIN
and I made it in effect immediately by:我通过以下方式立即生效:
source ~/.profile
Then everything goes well again.然后一切都会再次顺利。
I would recommend to try it on latest tensorflow (not tensorflow-gpu).我建议在最新的 tensorflow(不是 tensorflow-gpu)上尝试。 Worked for me
为我工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.