Search code examples
pythontensorflowkerasfeature-extractionresnet

Where is pretrained ResNet101 in Keras and how obtain raw feature?


I need pretrained ResNet101 in Keras but Python gives me error. In the documentation they write

keras.applications.resnet.ResNet101(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

(https://keras.io/applications/) but when I import ResNet101 Python gives the error

AttributeError: module 'keras.applications' has no attribute 'resnet' 

Moreover, I need the features calculated before the "pooling" layer, for example using VGG16 I'd do this:

myModel = Model(baseModel.input, baseModel.layers[-2].output)

How can I obtain them using ResNet? Thanks


Solution

  • The error is in your Keras version:

    https://stackoverflow.com/a/54730330/9110938

    Feature Extraction

    Last two layers of ResNet-101 are global average pooling and fully-connected layers. Because of that:

    myModel.layers[-1].output # output of the FC layer
    myModel.layers[-2].output # output of the global average pooling layer