简体   繁体   English

从Keras中不同名称的图层加载权重

[英]Load weights from layers with different names in Keras

My model consists of two different ResNets, and its layers share the same name but with a d_ prefix at the beginning in one of the branches. 我的模型由两个不同的ResNet组成,其各层共享相同的名称,但其中一个分支的开头带有d_前缀。

Image1----conv1---conv2---(...)
                                   \
                                     Other stuff I don't need the weights
                                   /
Image2----d_conv1---d_conv2---(...)

How do I load the same weights to both ResNet if my weights.h5 file has those weights saved only with the name without prefix? 如果我的weights.h5文件中的权重仅使用没有前缀的名称保存,那么如何将相同的权重加载到两个ResNet中?

在Keras中,加载权重时设置by_name = False。

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

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