Python tensorflow 精简版错误 :Cannot set tensor: Got tensor of type 1 but expected type 3 for input 88

标签 python tensorflow tensorflow-lite

我已将我的模型转换为 tensorflow-lite,但在编译时出现以下错误:

Traceback

这是我的代码:

interpreter = tf.contrib.lite.Interpreter(model_path= "/mnt/ficusspain/cqli/tensorflow_models/Quantized_Models/mobilenet_v1_0.25_128_quant/mobilenet_v1_0.25_128_quant.tflite")
interpreter.allocate_tensors()

print("can we get here?")

# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

print("can we get here")

# Test model on random input data.
input_shape = input_details[0]['shape']
print(input_shape)
print(input_details[0]['index'])
print(output_details[0]['index'])

    
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)

最佳答案

您需要将数据类型从 np.float32 更改为 np.uint8:

input_data = np.array(np.random.random_sample(input_shape), dtype=np.uint8)

您可以随时查看

print(interpreter.get_input_details())

需要哪个数据类型

关于Python tensorflow 精简版错误 :Cannot set tensor: Got tensor of type 1 but expected type 3 for input 88,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530724/

相关文章:

python - 训练模型后评估建议

python - 在 Raspberry Pi 上使用 Azure-iothub-device-client 时出现问题

python - Django:[0, 1]基数的一对多关系

python - 变量正在更新以打印准确的分数

Tensorflow:model_with_buckets 模型中 freeze_graph.py 的 "output_node_names"是什么?

python - 在Windows上安装tensorflow-gpu

linux - 我们可以在 linux 上运行 tensorflow lite 吗?或者它仅适用于 android 和 ios

raspberry-pi - 如何为 Raspberry Pi 交叉编译 Tensorflow-Lite?

android - 无法在 android 中找到变换灰度类以在 android 中转换为灰度

python 错误: object of type 'builtin_function_or_method' has no len()