I recently collected several Keras models for which I'm importing their architecture using keras.Models.model_from_json
function (Note that there is no training made yet). My image data generator can be customized to produce batches of samples with different sizes and shapes (varying in the same flow generator). For instance, I may generate data with the shape (*batchsize*,32,32,3)
and a total of 6 classes. Currently, the imported models have different input and output shapes, let's say (5*100*100*3)
and 2 classes assigned to their layers.
My goal is to change the input and output shape of such layers in order to compare different image sizes in the model performance.
First, in the input layer, I have tried:
model.layers[0].input.set_shape((None,32,32,3))
I received the following error:
Dimension 1 in both shapes must be equal, but are 100 and 32. Shapes are [?,100,100,3] and [?,32,32,3].
Similarly for the output layer, using
model.layers[len(model.layers)-1].output.set_shape((None,6))
the same error was throw
Dimension 1 in both shapes must be equal, but are 2 and 6. Shapes are [?,2] and [?,6].
TLDR: Is there a generic function/util to dynamically change the input and output shape of any model architecture in Keras?
PS: If the model has several outputs or the last two layers are, keras.layers.Dense followed by keras.layers.Activation
, changing the shape of last layer is a viable solution?