python - 使用 Quantized MobilenetV1 Tf-lite 预测期间不同图像的相同输出
问题描述
我有不同的输入图像;但是,当使用相同的 tflite 模型/文件进行预测时,输出总是相同的。我的代码示例和输出如下。
我错过了什么?
Tflite 文件量化为:
converter = tf.lite.TFLiteConverter.from_frozen_graph('vww_96_grayscale_frozen.pb', ['input'], ['MobilenetV1/Predictions/Reshape_1'])
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset_gen
tflite_quant_model = converter.convert()
推理代码:
interpreter = tf.lite.Interpreter(model_path=TFLITE_MODEL)
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
interpreter.allocate_tensors()
for cnt in range(5):
image_path = "/data/0-val_img-"+str(cnt)+".png"
image_data = PIL.Image.open(image_path).resize((96, 96)).convert('L')
#plt.imshow(image_data) # shows different images, as expected
#plt.show()
array = np.array(image_data).astype(np.uint8)
array = ((array / 127.5) - 1.0).astype(np.float32)
array = np.expand_dims(array, axis=2)
array = np.expand_dims(array, axis=0)
# set input data
interpreter.set_tensor(input_details[0]['index'], array)
interpreter.invoke()
# get output
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)
输出
[[0.91796875 0.08203125]]
[[0.91796875 0.08203125]]
[[0.91796875 0.08203125]]
[[0.91796875 0.08203125]]
[[0.91796875 0.08203125]]
解决方案
我认为问题是我训练中的时期数少。我用 200000 个 epoch 重新训练了网络。所有图像都按预期生成不同的概率值。
推荐阅读
- bots - 如何删除 Telegram 中其他机器人的消息?
- java - 如何向模块路径添加依赖项?
- ros - ROS 访问网络摄像头
- javascript - 在本地主机上运行 JS - 服务器 js
- c# - C# 小于一定数量
- c++ - 在执行时在布局中添加自定义小部件
- javascript - svg-pan-zoom 平移/缩放到任何对象
- postgresql - 如何使用 Postgres “ROLLBACK TO SAVEPOINT”和“FOR UPDATE SKIP LOCKED”?
- c - C 编程 yes no 带有错误捕获器的循环
- git - 在 satis 存储库中使用本地存储库