简体   繁体   English

Keras resnet50 get_layer() '没有这样的层'错误

[英]Keras resnet50 get_layer() 'no such layer' error

So I'm loading the keras Resnet50 model using the below code:所以我正在使用以下代码加载 keras Resnet50 模型:

backbone = resnet50.ResNet50(include_top=False, weights=None, input_tensor=None, pooling=None, classes=1000)

I need to get a batch normalization layer which is named ' bn5c_branch2c ' in the resnet50 code on github(line 75) .我需要在github(line 75)上的 resnet50 代码中获得一个名为“ bn5c_branch2c ”的批量标准化层。

Running backbone.get_layer('bn5c_branch2c') gives me a ValueError: No such layer: bn5c_branch2c.运行backbone.get_layer('bn5c_branch2c')给我一个ValueError: No such layer: bn5c_branch2c。

Printing the names of the layers using:使用以下方法打印层的名称:

for layer in backbone.layers:
     print(layer.name)

I found that indeed none of the layers go by this name, instead they're named something like ' conv5_block1_3_bn '.我发现确实没有任何层以这个名称命名,而是将它们命名为“ conv5_block1_3_bn ”。 However, in the code of resnet50 the name is clearly fed as ' bn5c_branch2c '.但是,在 resnet50 的代码中,名称明确输入为“ bn5c_branch2c ”。 I'm unable to understand how this is happening and how can I extract a layer by the name it is assigned in the code.我无法理解这是如何发生的,以及如何通过代码中分配的名称提取图层。 Any help would be great.任何帮助都会很棒。 Thanks.谢谢。

tensorflow - 2.3.1 keras - 2.4.3 OS - Ubuntu 20.04.1 LTS张量流 - 2.3.1 keras - 2.4.3 操作系统 - Ubuntu 20.04.1 LTS

bn5c_branch2c layer works with Tensorflow 1.13.1. bn5c_branch2c层适用于 Tensorflow 1.13.1。

from tensorflow.keras.applications import resnet50
from tensorflow.keras import layers
from tensorflow.keras.layers import Concatenate, Conv2D, UpSampling2D, BatchNormalization, Add, Lambda
from tensorflow.keras.models import Model

backbone = resnet50.ResNet50(include_top=False,
                                          weights=None,
                                          input_tensor=None,
                                          pooling=None,
                                          classes=1000)

C5 =  backbone.get_layer('bn5c_branch2c').output

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

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