-
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
Custom Generator crash for variable input dimensions #19748
Comments
Some thoughts without any knowledge about the internals of Keras, so I may be way off the mark here: I understand that due the dynamic nature of a generator, Keras has no previous knowledge about whether or not the generator will produce consistent dimensions, and Keras can probably optimize better with fixed dimensions, so it might be important to make this decision early on in training. However, there are a few hints that I think could be used to avoid this issue: First, a model with varying input dimensions needs to have its input defined as some version of It could still be desirable to run a model with variable inputs with a fixed dimension generator, so maybe there could be another argument for the fit function or a virtual function in the generator, like In any case, I think it would be helpful to mention this side-effect in the error message, something like: |
Thanks for the report. @hertschuh do you think we could do some per-batch shape validation in the data adapter in order to raise a more helpful error message? e.g.
|
…lds a tensor of unexpected shape. Addresses keras-team#19748
…elds a tensor of unexpected shape. Addresses keras-team#19748
Fix is pushed. Thanks! |
Wow, that was fast. Thanks a lot! |
When I try to run a generator for a classifier that allows varying input dimensions, I get a crash when my first two batches happen to have the same input dimensions. It works fine if the two first batches have different input dimensions.
It seems that keras looks at the first two batches and if they have the same dimensions, it expects all following batches to have the same dimensions as well. If they don't, I get a crash.
This has stumped me for quite some time until I found what seemed to be the cause, and I think it could be handled in a more transparent way to help users identify the cause faster if it occurs.
I am using Keras 3.3.3
This is the error:
TypeError: 'generator' yielded an element of shape (10, 16, 32, 1) where an element of shape (None, 16, 16, 1) was expected.
The following code shows the problem:
The text was updated successfully, but these errors were encountered: