【发布时间】:2018-09-26 12:07:19
【问题描述】:
我已经冻结了我的模型并获得了 .pb 文件。然后我在 Linux 上使用 tocoConverter 量化我的模型,因为它在 Windows 上不受支持。我有 quantized_model.tflite。我可以在 Linux 上加载它并获得预测,但我在 Windows 上遇到问题,因为我的项目需要。 我尝试使用 tf.contrib.lite.Interpreter 使用此代码加载它:
import numpy as np
import tensorflow as tf
# Load TFLite model and allocate tensors.
interpreter=tf.contrib.lite.Interpreter(model_path="quantized_model.tflite")
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Test model on random input data.
input_shape = input_details[0]['shape']
# change the following line to feed into your own data.
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'],input_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)
*ImportError: No module named 'tensorflow.contrib.lite.python.Interpreter*
但它因“没有名为 'tensorflow.contrib.lite.python.interpreter 的模块”错误而失败。尝试使用 tf.contrib.lite 中的某些内容时,我总是在 Windows 上遇到此错误。也许有一种方法可以在 Windows 上加载它?或者您能建议在 Windows 上量化模型的替代方案吗?
【问题讨论】:
标签: python windows tensorflow quantization