TensorFlow Model Predict Block Input Shape Error for RNN
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am attempting to use a trained RNN model within Simulink using a TensorFlow Model Predict block for time series forecasting.
My model was trained using 2 timesteps and 4 features, therefore when I pass a numpy array of shape [1,2,4] to the following code I get a prediction for a single 'batch' within a standalone MATLAB script without error:
sequencesPy = py.numpy.array(sequences);
predictionsPy = model.predict(sequencesPy);
When referencing the same model within Simulink, I convert the model input signals to a numpy array of shape [1,2,4] using a preprocess.py script specified within the Model Predict block parameters, however when I attempt to run my model I get the following error:
== START OF PYTHON ERROR MESSAGE ==
Python Error: ValueError: Input 0 of layer "model_8" is incompatible with the layer: expected shape=(None, 2, 4), found shape=(2, 4)
== END OF PYTHON ERROR MESSAGE ==
However, my model appears to work when an array of [2,2,4] is passed from the preprocessing function.
Is there therefore a solution to stop my 0th dimension from being 'squeezed' out when being passed from my preprocess script to my TensorFlow model when it is equal to 1?
Thank you for your help!
4 个评论
Nithin
2025-2-11
Hi Jonathan,
It seems like the issue might not lie within the preprocess function itself. Instead, there could be a problem with the configuration of your Simulink model or the RNN model you're using. Given the information provided, it's challenging to pinpoint the exact cause.
P.S.: MATLAB itself isn't removing the batch dimension; the issue might be occurring elsewhere in the process.
回答(1 个)
Gayathri
2025-5-14
编辑:Gayathri
2025-5-14
The error you are encountering is due to the fact that the "preprocess" function is returning the output as an array. But it is expected to output a python list containing the output array. The python list should be a list of length '1', because there is only one input to the tensorflow model.
Please return the array in the below format.
return [array]
Please refer to the below link for more information on the same:
I hope this helps resolve the issue!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning with GPU Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!