-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a warning for mismatched inputs structure in Functional
#20170
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #20170 +/- ##
=======================================
Coverage 79.34% 79.34%
=======================================
Files 501 501
Lines 47319 47325 +6
Branches 8692 8694 +2
=======================================
+ Hits 37544 37550 +6
Misses 8017 8017
Partials 1758 1758
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvement -- LGTM
After upgrading Keras to latest version I am getting the warning, but can't figure out, what is wrong with the input and this is the output:
Hard to see, what is wrong I have tried with: result = model.predict({'X_input': x, 'B_input': b},verbose=0) Code is working fine |
@ThorvaldAagaard Same here. Did you figure it out? |
I did not find a fix, except downgrading Tensorflow to 2.17 There should be a way to disable these warnings. The change is this
so probably |
I found this, that can suppress all the warnings from Python
It is working |
Simple script to reproduce the error:
import numpy as np
from tensorflow.keras import layers, models
# Generate model
input_tensor_1 = layers.Input(shape=(10,), name='input_1')
input_tensor_2 = layers.Input(shape=(5,), name='input_2')
combined = layers.concatenate([input_tensor_1, input_tensor_2])
output = layers.Dense(1, activation='sigmoid')(combined)
model = models.Model(inputs=[input_tensor_1, input_tensor_2], outputs=output)
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
# Train
num_samples = 1000
X1 = np.random.rand(num_samples, 10)
X2 = np.random.rand(num_samples, 5)
y = np.random.randint(2, size=num_samples)
model.fit([X1, X2], y, epochs=5, batch_size=32, verbose=0)
# Prediction
X1_new = np.random.rand(5, 10)
X2_new = np.random.rand(5, 5)
model.predict([X1_new, X2_new], verbose=0) which gives the mentioned error:
By debugging, it seems a simple list/tuple mismatch in my case, given by: tree.assert_same_structure(
inputs, self._inputs_struct, check_types=False
) Fixed by using tuple as input for model: model = models.Model(inputs=(input_tensor_1, input_tensor_2), outputs=output) |
Hey @ThorvaldAagaard , @LuigiCerone |
Looking forward to the fix, I did not find a workaround for the predict method |
There are several issues related to mismatched inputs structure:
and more...
As a result, it would be beneficial to add a warning for users.
Ultimately, we might want to raise an error when a mismatch occurs. Otherwise, it could lead to subtle issues if the inputs have the same shape and dtype, as the computation could be incorrect even though the code runs.