【问题标题】:Tensorflow quantization on WindowsWindows 上的 TensorFlow 量化
【发布时间】: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 上量化模型的替代方案吗?

【问题讨论】:

  • TensorFlow Lite 仍然是一个实验性 API,Windows 支持似乎不稳定(如果有的话),请参阅 #16374#14607。您使用的是最新版本的 TensorFlow 吗?如果没有,升级可能会有所帮助。

标签: python windows tensorflow quantization


【解决方案1】:

cmake 的 Windows 构建当前不支持 toco。这是我记得在某处读到的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-21
    • 2022-01-25
    • 2017-05-16
    • 2017-03-03
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多