ConverterError: TOCO failed. See console for info.
来源:9-6 tflite保存与解释与量化

kingdomad
2019-08-16
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import sklearn
import pandas as pd
import os
import sys
import time
import tensorflow as tf
from tensorflow import keras
print(tf.__version__)
print(sys.version_info)
for module in mpl, np, pd, sklearn, tf, keras:
print(module.__name__, module.__version__)
output:
2.0.0-beta1
sys.version_info(major=3, minor=6, micro=9, releaselevel='final', serial=0)
matplotlib 3.1.1
numpy 1.16.2
pandas 0.25.0
sklearn 0.21.3
tensorflow 2.0.0-beta1
tensorflow.python.keras.api._v2.keras 2.2.4-tf
然后用TFLiteConverter就报错了。代码如下:
# 创建一个简单的 Keras 模型。
x = [-1, 0, 1, 2, 3, 4]
y = [-3, -1, 1, 3, 5, 7]
model = tf.keras.models.Sequential(
[tf.keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')
model.fit(x, y, epochs=50)
# 转换模型。
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
output:
...
Epoch 48/50
6/6 [==============================] - 0s 333us/sample - loss: 0.3053
Epoch 49/50
6/6 [==============================] - 0s 333us/sample - loss: 0.2990
Epoch 50/50
6/6 [==============================] - 0s 333us/sample - loss: 0.2929
---------------------------------------------------------------------------
ConverterError Traceback (most recent call last)
<ipython-input-2-77bdcd0e5030> in <module>
10 # 转换模型。
11 converter = tf.lite.TFLiteConverter.from_keras_model(model)
---> 12 tflite_model = converter.convert()
~\AppData\Local\conda\conda\envs\tf2b\lib\site-packages\tensorflow\lite\python\lite.py in convert(self)
390 input_tensors=input_tensors,
391 output_tensors=output_tensors,
--> 392 **converter_kwargs)
393
394 if self._is_calibration_quantize():
~\AppData\Local\conda\conda\envs\tf2b\lib\site-packages\tensorflow\lite\python\convert.py in toco_convert_impl(input_data, input_tensors, output_tensors, *args, **kwargs)
402 data = toco_convert_protos(model_flags.SerializeToString(),
403 toco_flags.SerializeToString(),
--> 404 input_data.SerializeToString())
405 return data
406
~\AppData\Local\conda\conda\envs\tf2b\lib\site-packages\tensorflow\lite\python\convert.py in toco_convert_protos(model_flags_str, toco_flags_str, input_data_str)
170 stderr = _try_convert_to_unicode(stderr)
171 raise ConverterError(
--> 172 "TOCO failed. See console for info.\n%s\n%s\n" % (stdout, stderr))
173 finally:
174 # Must manually cleanup files.
ConverterError: TOCO failed. See console for info.
b"'toco_from_protos' \xb2\xbb\xca\xc7\xc4\xda\xb2\xbf\xbb\xf2\xcd\xe2\xb2\xbf\xc3\xfc\xc1\xee\xa3\xac\xd2\xb2\xb2\xbb\xca\xc7\xbf\xc9\xd4\xcb\xd0\xd0\xb5\xc4\xb3\xcc\xd0\xf2\r\n\xbb\xf2\xc5\xfa\xb4\xa6\xc0\xed\xce\xc4\xbc\xfe\xa1\xa3\r\n"
老师求指点。
写回答
1回答
-
kingdomad
提问者
2019-08-16
我自问自答吧。因为系统没有找到toco_from_protos。把toco_from_protos脚本文件所在的路径添加到系统环境变量中即可。
10
相似问题