2

I have a Keras model (TensorFlow 2.0) saved in hdf5 format (.h5). I want to load this existing model and change its input shape, so it only accepts a fixed batch size.

The input batch size can be fixed with the layer tensorflow.keras.Input(shape=..., batch_size=...). However, I do not want to create a new model from scratch (I want to use the already existing model). Is there a way to do this using the Python TF2 api without creating the model from scratch and without adding new layers?

IgnacioGaBo
  • 168
  • 11
  • This would mean you would have to call the `model.compile()` which will fail as this is a frozen model. Hence, in order to change you would have to train the model again for a different input model layer OR have your layer external to this model and convert it yourself to the required shape? – papaya Jan 20 '21 at 09:02
  • Thank you for your response. How can I transform an external layer with the shape I want and "append" it to an already existing (and trained) model? – IgnacioGaBo Jan 20 '21 at 11:04
  • You ideally cannot. Your best bet is to simply do this transformation on your own, after all this is exactly what a NN would end up doing even if you had the capabilities to do it and then provide the resultant to the existing model. Perhaps that should help you – papaya Jan 20 '21 at 13:07
  • 1
    @IgnacioGaBo, I have found similar [issue](https://stackoverflow.com/questions/49546922/keras-replacing-input-layer) resolved which could help you to solve this query. –  Nov 03 '21 at 08:03

0 Answers0