0

I would like to restore the Resnet50V2 model from checkpoint but do not want the last layer to be restored in new model .I am not understanding how to do that? The pseudo code is as follows:

I trained the first model as

  Model= ResNet50v2 ()

 Cnn_model= Sequential([
                        Average pooling layer,
                        Dense (2048),
                        Dense (2048).
                        Dense (10) ])

Now I want to use the checkpoint of above model with the same architecture but do not want to add Dense(10) layer .

irum
  • 41
  • 5
  • This is a duplicate question, see here https://stackoverflow.com/questions/55392591/how-to-remove-the-last-layer-from-trained-model-in-tensorflow – ZWang Jul 17 '20 at 07:03
  • Thank you for your reply. I have seen that question before. I am editing my question so that it become more clear . – irum Jul 17 '20 at 10:31

1 Answers1

0

You can instantiate a new model, using the layers method from the Sequential class and getting all the layers until the 2nd last layer after you've loaded from the checkpoint:

model = Sequential([i for i in Cnn_model.layers[:-1])
  • Thank you for your answer.Is there any way to directly restore weights to the new model excluding last layer rather than first restoring to pre-trained model. – irum Jul 18 '20 at 12:03