-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
Irregular Tensors as output from Generator class with batch size = 1 #19925
Comments
Hello there look at this example that i tested for you : import numpy as np
def get_item(index):
height_X = np.random.randint(3, 6)
width_X = np.random.randint(3, 6)
X = np.random.rand(1, height_X, width_X, 7)
Y = np.array([0])
return X, Y
X, Y = get_item(0)
print(X.shape, Y.shape)
X, Y = get_item(1)
print(X.shape, Y.shape)
X, Y = get_item(2)
print(X.shape, Y.shape) outputs are :
|
Hi, thanks for your response. It happens that I need to give my network tensors of different dimensions. I have set the batch to 1 so that it accepts tensors of different dimensions in each call to getItem. Still it doesn't work. |
@hansschaa this is a fundamental constraint in how deep learning models expect input data. The batch size can vary but the input tensor shape will have to be fixed. |
@hansschaa you can have a generator which yields tensors with different dimension values. There is however one constraint, which is that the first two batches returned must have different values for all the dimensions in question. That is how Keras detects the dynamic dimensions. You can look at this test for an example: https://github.com/keras-team/keras/blob/master/keras/src/trainers/data_adapters/generator_data_adapter_test.py#L105 More context in #19748 |
Hello, I have a problem creating a generator and expecting it to work with tensors of different dimensions. I am using Keras 3.4.0 and I am getting the error message: TypeError:
generator
yielded an element of shape (1, 3, 3, 7) where an element of shape (None, 4, 4, 7) was expected.You can try the following and you will obtain the difference error between the dimensions of the tensors for independent batches.
Thanks for help!
The text was updated successfully, but these errors were encountered: