【发布时间】:2019-06-23 09:48:19
【问题描述】:
我已经训练了一个模型并将其转换为 .tflite 模型。我已经使用以下方法完成了训练后量化:
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_quant_model = converter.convert()
但是当我尝试在 RaspberryPi 上使用模型进行推理时,出现以下错误
Traceback (most recent call last):
File "tf_lite_test.py", line 8, in <module>
interpreter = tf.lite.Interpreter(model_path="converted_from_h5_model_with_quants.tflite")
File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/lite/python/interpreter.py", line 46, in __init__
model_path))
ValueError: Didn't find op for builtin opcode 'CONV_2D' version '2'
Registration failed.
当我将模型转换为 tflite 而不应用任何训练后量化时,我不会出错。这是我用来在不应用训练后量化的情况下隐藏模型的代码。
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_quant_model = converter.convert()
这是我的模型:
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(32, (3,3), activation='relu', input_shape=(IMG_SHAPE, IMG_SHAPE, 3)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
tf.keras.layers.Conv2D(128, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(3, activation='softmax')
])
如何应用训练后量化并加载模型而不会出现此错误?
【问题讨论】:
-
你的设备上 tensorflow 的版本是什么?我相信
CONV_2D版本2支持跨步,尽管这里没有使用它是生成的tflite 操作的格式。尝试让 tflite 生成CONV_2D版本1或将其更新为支持该操作的较新版本。 -
我大约一周前安装了tflite,从那以后有没有新版本?另外,我将如何检查我的 tfite 安装版本? tflite 似乎没有 .version 版本?
-
“你的设备上 tensorflow 的版本是什么?”
-
我知道我的 tf 版本。它是 1.13.1。我只是不知道如何查看 tflite 的版本。
标签: tensorflow tensorflow-lite