My keras model:
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'))
After training, i convert model to 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)
Then i want to test 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: Cannot set tensor: Got value of type NOTYPE but expected type FLOAT64 for input 0, name: input_1 ```
X[0]- Alex K.inpto make sure it has floats inside. Also what is yoursinput_shape? - Alex K.set_tensor()makes a copy of data, maybe you have some issues during this. Try to use tensor strategy. - Alex K.