简体   繁体   English

Tensorflow TocoConverter 给出 toco_from_protos 错误

[英]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,所以我想我一定搞砸了一个步骤,在这个步骤中,像tocotoco_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.如果您的tocotoco_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你有两个选择

  1. Download and build tensorflow from source从源代码下载并构建 tensorflow
  2. Use google collab if you don't want to install tensorflow from source Here i made video on how to fix this Error如果您不想从源代码安装 tensorflow,请使用 google collab这里我制作了有关如何修复此错误的视频

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.

相关问题 在运行toco时尝试将TensorFlow模型转换为TensorFlow lite --help给我一个错误 - Trying to convert TensorFlow model to TensorFlow lite, when running toco --help gives me an error 在Ubuntu 16.04上使用bazel从源构建张量流。 错误是--->规则'// tensorflow / contrib / lite / toco:toco'的链接失败(出口1) - Building tensor flow from source using bazel on Ubuntu 16.04. Error is ---> Linking of rule '//tensorflow/contrib/lite/toco:toco' failed (Exit 1) Tensorflow TOCO python API - Tensorflow TOCO python API 使用TocoConverter.from_keras_model_file将Keras模型转换为Tensorflow-Lite时出现问题 - Problem converting Keras model to Tensorflow-Lite using TocoConverter.from_keras_model_file Object 检测 TensorFlow 2:ImportError: cannot import name 'anchor_generator_pb2' from 'object_detection.protos' - Object Detection with TensorFlow 2 : ImportError: cannot import name 'anchor_generator_pb2' from 'object_detection.protos' 如何修复“ TOCO失败。 检查失败:将冻结的图形转换为tensorflow_lite模型时,dim> = 1(0对1)”错误 - How to fix “TOCO failed. Check failed: dim >= 1 (0 vs. 1)” error while converting a frozen graph into a tensorflow_lite model Spyder-导入张量流会出现错误 - Spyder - Importing tensorflow gives an error Tensorflow 安装给我一个来自 pip 模块的错误 - Tensorflow Installing gives me an error from pip module Tensorflow [Toco]将模型转换为优化格式导致ValueError - Tensorflow [Toco] convert Model to optimized format cause ValueError 使用toco进行tflite转换时出现“尺寸必须匹配”错误 - “Dimensions must match” error in tflite conversion with toco
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM