赞
踩
keras源码engine中toplogy.py定义了加载权重的函数:load_weights(self, filepath, by_name=False)
其中默认by_name为False,这时候加载权重按照网络拓扑结构加载,适合直接使用keras中自带的网络模型,如VGG16
VGG19/resnet50等,源码描述如下:
If `by_name` is False (default) weights are loaded
based on the network's topology, meaning the architecture
should be the same as when the weights were saved.
Note that layers that don't have weights are not taken
into account in the topological ordering, so adding or
removing layers is fine as long as they don't have weights.
若将by_name改为True则加载权重按照layer的name进行,layer的name相同时加载权重,适合用于改变了
模型的相关结构或增加了节点但利用了原网络的主体结构情况下使用,源码描述如下:
If `by_name` is True, weights are loaded into layers
only if they share the same name. This is useful
for fine-tuning or transfer-learning models where
some of the layers have changed.
在进行边缘检测时,利用VGG网络的主体结构,网络中增加反卷积层,这时加载权重应该使用
model.load_weights(filepath,by_name=True)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。