简体   繁体   English

Tensorfllow:从更改的 model 加载检查点

[英]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.出于某种原因,我想测试检测器和他的相同版本的性能差异,但使用一些 3d 卷积进行了微调。
The model of the detector is google EfficientDet, the weights are finetuned on custom data.探测器的 model 是 google EfficientDet,权重根据自定义数据进行微调。
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).我想知道是否可以将我的自定义权重加载到 model 中,其中 graph-def 不一样(在某些层会有 3d 卷积)。 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我是 Tensorflow 的新手,有点难过,因为在 Pytorch 中这很容易

Thanks谢谢

You can load the second model, get weights of the layer and set weights of your model:您可以加载第二个 model,获取层的权重并设置 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM