简体   繁体   English

Windows上的Tensorflow量化

[英]Tensorflow quantization on Windows

I've freezed my model and got .pb file. 我已经冻结了模型并获得了.pb文件。 Then I've quantize my model using tocoConverter on Linux, as it's not supported on Windows. 然后,我在Linux上使用tocoConverter量化了我的模型,因为Windows不支持它。 I've got quantized_model.tflite. 我有quantized_model.tflite。 I can load it and get predictions on Linux, but I have issues to make it on Windows, as my project requires. 我可以加载它并在Linux上获得预测,但是根据我的项目需要,在Windows上安装它存在一些问题。 I've tried to load it using tf.contrib.lite.Interpreter using this code: 我尝试使用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*

But it failed with "No module named 'tensorflow.contrib.lite.python.interpreter" error. 但是它失败,并出现“没有名为'tensorflow.contrib.lite.python.interpreter的模块”错误。 I always get this errors on Windows, when trying to use something from tf.contrib.lite. 尝试使用tf.contrib.lite中的某些内容时,在Windows上总是会出现此错误。 Maybe there is a way to load this on Windows? 也许有一种方法可以在Windows上加载它? Or can you advice alternative options to quantize a model on Windows? 还是可以建议其他选择来量化Windows上的模型?

toco is currently not supported on Windows build for cmake. Windows build for cmake当前不支持toco。 This is what I remember reading somewhere. 这是我记得在某处阅读的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM