Open Ybisalt opened 2 weeks ago
Hi @Ybisalt ,
I have tested the given code with Keras 3.3.3v and it executes fine. Please note that I have changed the code K.sum
to keras.ops.sum
and same for K.square
also. Please refer to attached gist.
I have tested the given code with Keras 3.3.3v and it executes fine. Please note that I have changed the code
K.sum
tokeras.ops.sum
and same forK.square
also.
No! Same problem here. You didn't notice "Batch size = None! (None, 4)" line in the last output log. The number of batches without size depends on the order in which the method is called.
Try just one run of the fit() method (comment out the other fit lines):
log = model.fit(inp_data, out_data, epochs=3, batch_size=30) # Batch size = None!
My gist
x.shape
is the "static shape" of x
. It is often not a number. It can be None
. If you want the actual number value, you must use keras.ops.shape(x)
, e.g.
keras.ops.sum(keras.ops.square(x - y), axis=0) / keras.ops.shape(x)[0]
The .fit() method passes unsized batches to a custom loss function if the dataset size is not a multiple of the batch size. This happens twice, then everything goes fine. But if you need to use the batch size to normalize or reshape data, then an error occurs.