我的keras模型:
model = Sequential()
model.add(keras.layers.InputLayer(input_shape=(1134,), dtype='float64'))
model.add(Dense(1024, activation='relu'))
model.add(Dense(512, activation='relu'))
model.add(keras.layers.Dropout(0.35))
model.add(Dense(3, activation='softmax'))训练完成后,我将模型转换为tflite。
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.target_spec.supported_ops = [tf.lite.OpsSet.SELECT_TF_OPS] <-- without this I will get an error
tflite_model = converter.convert()
with open('model.tflite', 'wb') as f:
f.write(tflite_model)然后我想测试一下模型:
interpreter = tf.lite.Interpreter(model_path="/content/model.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
input_shape = input_details[0]['shape']
inp = np.expand_dims(X[0], axis=0)
interpreter.set_tensor(input_details[0]['index'], inp) <-- in this line i get error```
Error:ValueError:无法设置张量:获取了类型为NOTYPE的值,但输入0应为类型FLOAT64,名称: input_1 `
发布于 2021-01-12 06:00:39
试试这个:
interpreter = tf.lite.Interpreter(model_path="/content/model.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
input_shape = input_details[0]['shape']
inp = np.expand_dims(X[0], axis=0)
inp = inp.astype(np.float64) # This was missing
interpreter.set_tensor(input_details[0]['index'], inp)https://stackoverflow.com/questions/65601060
复制相似问题