I'm trying to run inference on a saved model from the MoveNet Pose estimation Model. The notebook used to train and test the model is from Tensorflow Notebook. I save the model using the model.save('model.keras')
.
This is the code I'm trying to load and run inference:
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
# Load the model
filepath = "C:\\Users\\golut\\OneDrive\\Documents\\PoseEstimation\\model.keras"
new_model = tf.keras.models.load_model(filepath)
# Read and preprocess the image
image_path = "C:\\Users\\golut\\OneDrive\\Documents\\PoseEstimation\\test_pos.jpg"
image = tf.io.read_file(image_path)
image = tf.image.decode_image(image, channels=3)
image = tf.image.convert_image_dtype(image, tf.float32)
image = tf.image.resize(image, (256, 256)) # Resize if necessary
image = np.expand_dims(image, axis=0) # Add batch dimension
# Perform inference
predictions = new_model.predict(image)
# Process predictions as needed
# For example, print the predictions
print(predictions)
# Optionally, visualize the image and predictions
plt.imshow(image[0]) # Assuming only one image in the batch
plt.show()
It gives me an error saying the expected dimensions by the model do not match.
Traceback (most recent call last):
File "c:\Users\golut\OneDrive\Documents\PoseEstimation\app.py", line 18, in <module>
predictions = new_model.predict(image)
File "C:\ProgramData\anaconda3\envs\pose_est\lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\golut\AppData\Local\Temp\__autograph_generated_filepea7q91y.py", line 15, in tf__predict_function
retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
ValueError: in user code:
File "C:\ProgramData\anaconda3\envs\pose_est\lib\site-packages\keras\src\engine\training.py", line 2440, in predict_function *
return step_function(self, iterator)
File "C:\ProgramData\anaconda3\envs\pose_est\lib\site-packages\keras\src\engine\training.py", line 2425, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "C:\ProgramData\anaconda3\envs\pose_est\lib\site-packages\keras\src\engine\training.py", line 2413, in run_step **
outputs = model.predict_step(data)
File "C:\ProgramData\anaconda3\envs\pose_est\lib\site-packages\keras\src\engine\training.py", line 2381, in predict_step
return self(x, training=False)
File "C:\ProgramData\anaconda3\envs\pose_est\lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\ProgramData\anaconda3\envs\pose_est\lib\site-packages\keras\src\engine\input_spec.py", line 298, in assert_input_compatibility
raise ValueError(
ValueError: Input 0 of layer "model" is incompatible with the layer: expected shape=(None, 51), found shape=(None, 256, 256, 3)
Any solution to this? What am I doing wrong?