keras获得某一层或者某层权重的输出实例

时间:2021-05-22

一个例子:

print("Loading vgg19 weights...") vgg_model = VGG19(include_top=False, weights='imagenet') from_vgg = dict() # 因为模型定义中的layer的名字与原始vgg名字不同,所以需要调整 from_vgg['conv1_1'] = 'block1_conv1' from_vgg['conv1_2'] = 'block1_conv2' from_vgg['conv2_1'] = 'block2_conv1' from_vgg['conv2_2'] = 'block2_conv2' from_vgg['conv3_1'] = 'block3_conv1' from_vgg['conv3_2'] = 'block3_conv2' from_vgg['conv3_3'] = 'block3_conv3' from_vgg['conv3_4'] = 'block3_conv4' from_vgg['conv4_1'] = 'block4_conv1' from_vgg['conv4_2'] = 'block4_conv2' for layer in model.layers: if layer.name in from_vgg: vgg_layer_name = from_vgg[layer.name] layer.set_weights(vgg_model.get_layer(vgg_layer_name).get_weights()) print("Loaded VGG19 layer: " + vgg_layer_name)densenet.load_weights('model/densenet_weight/densenet_bottom.h5')# densenet.save_weights('densenet_bottom.h5') # print(densenet.weights)# 获得模型所有权值t=densenet.get_layer('densenet_conv1/bn')print(t)print(densenet.get_weights()[2])

以上这篇keras获得某一层或者某层权重的输出实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章