pythontensorflowdeep-learningcheckpoint

Tensorfllow: load checkpoint from changed model


For some reason I want to test the difference in the performance of a detector and his identical version but finetuned with some 3d convolutions.
The model of the detector is google EfficientDet, the weights are finetuned on custom data.
I was wondering if it was possible to load my custom weight in a model in which the graph-def is not the same (there would be 3d convolutions at some layers). And what could be the way to do that.
I'm new to Tensorflow and a bit sad because in Pytorch this would be so easy

Thanks


Solution

  • You can load the second model, get weights of the layer and set weights of your model:

    source_model = keras.models.load_model('path/to/location')
    weight = source_model.layers[0].get_weights()   # <= change index here
    EfficientDetModel.layers[0].set_weights(weight) # <= change index here