Dimension error in TFlite

Hello,plz help me to solve my problem
I ran the model into tflite. then got the error:

ValueError: Cannot set tensor: Dimension mismatch. Got 56 but expected 1 for dimension 0 of input 0

The input I will use is an array with the name user_place_array

This is my code :

model = tf.lite.Interpreter(model_path="/content/recommender_model.tflite")

input_details = model.get_input_details()
output_details = model.get_output_details()
input_shape = input_details[0]['shape']

print(f"user_place_array shape = ",user_place_array.shape)
print(f"model input = ",input_shape)

the return is :

user_place_array shape = (56, 2)
model input =  [1 2]

and then, i check user_place_array

user_place_array

the output of user_place_array is :

array([[253,   0],
       [253,   1],
       [253,   2],
       [253,   3],
# until 56

and then I run the model using tflite :

model.set_tensor(input_details[0]['index'], user_place_array)

This is the problem. i got the tflite error here

ValueError: Cannot set tensor: Dimension mismatch. Got 56 but expected 1 for dimension 0 of input 0.

when I don’t use tflite, the model runs perfectly. I use keras model.predict(user_place_array).flatten()
the model provides recommendations as expected. I don’t know why it doesn’t work on Tflite.

can someone help me ? Thank You :slight_smile:

Hi @elfi, While making inference using TFLite model, the model expects the input data batch dimension to be 1 but you are passing the input data having batch dimension 56. Could you please try by passing the input data having a single batch dimension. Thank You.