Python tensorflow lite错误:;无法设置张量:已获取类型为1的张量,但输入应为类型3
我已将模型转换为tensorflow lite,但编译时出现以下错误: 这是我的密码:Python tensorflow lite错误:;无法设置张量:已获取类型为1的张量,但输入应为类型3,python,tensorflow,tensorflow-lite,Python,Tensorflow,Tensorflow Lite,我已将模型转换为tensorflow lite,但编译时出现以下错误: 这是我的密码: 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.allocat
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())
需要哪种数据类型请不要使用控制台输出的屏幕截图,这会使必要时更难阅读和复制。相反,将该输出粘贴为问题中的代码块。对不起,我将修复它!