简体   繁体   中英

Keras resnet50 get_layer() 'no such layer' error

So I'm loading the keras Resnet50 model using the below code:

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) .

Running backbone.get_layer('bn5c_branch2c') gives me a 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 '. However, in the code of resnet50 the name is clearly fed as ' 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

bn5c_branch2c layer works with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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