Home > Enterprise >  How to change the input dimensions of pretrained keras model?
How to change the input dimensions of pretrained keras model?

Time:09-22

Is there a way to change the input layer dimensions from (None,224,224,3) to (None,3,224,224) in the model it self rather than changing the input image? I am trying to do this on a keras pretrained without having to loose the weights.

model = keras.models.load_model('/content/Sample_MobileNetV2_7Class_210721.hdf5')
model.summary()

Model: "model"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            [(None, 224, 224, 3) 0                                            
__________________________________________________________________________________________________
Conv1 (Conv2D)                  (None, 112, 112, 32) 864         input_1[0][0]                    
__________________________________________________________________________________________________
bn_Conv1 (BatchNormalization)   (None, 112, 112, 32) 128         Conv1[0][0]                      
__________________________________________________________________________________________________
Conv1_relu (ReLU)               (None, 112, 112, 32) 0           bn_Conv1[0][0]                   
__________________________________________________________________________________________________

CodePudding user response:

You can add a Reshape() layer to solve your problem. Like this:

base = keras.models.load_model('/content/Sample_MobileNetV2_7Class_210721.hdf5')

model = Sequential()
model.add(Input(shape=(3,224,224))
model.add(Reshape((224,224,3))
model.add(base)
  • Related