Keras: The added layer must be an instance of class layer

Created on 14 Feb 2020  路  1Comment  路  Source: keras-team/keras

conv_base = Net(weights='imagenet', include_top=False,pooling='max')
conv_base.trainable = False

model = models.Sequential()
model.add(conv_base)
model.add(layers.GlobalMaxPooling2D(name="gap"))
model.add(layers.Dropout(dropout_rate, name="dropout_out"))
model.add(layers.Dense(4, activation='softmax', name="fc_out"))
model.summary()

The Error is TypeError: The added layer must be an instance of class Layer. Found:

support

Most helpful comment

This worked for me on Keras 2.2.5 and Tensorflow 1.15.0.

from keras.applications.resnet import ResNet50
from keras import layers
from keras import models

conv_base = ResNet50(weights='imagenet', include_top=False,pooling=None)
conv_base.trainable = False

model = models.Sequential()
model.add(conv_base)
model.add(layers.GlobalMaxPooling2D(name="gap"))
model.add(layers.Dropout(0.5, name="dropout_out"))
model.add(layers.Dense(4, activation='softmax', name="fc_out"))
model.summary()

>All comments

This worked for me on Keras 2.2.5 and Tensorflow 1.15.0.

from keras.applications.resnet import ResNet50
from keras import layers
from keras import models

conv_base = ResNet50(weights='imagenet', include_top=False,pooling=None)
conv_base.trainable = False

model = models.Sequential()
model.add(conv_base)
model.add(layers.GlobalMaxPooling2D(name="gap"))
model.add(layers.Dropout(0.5, name="dropout_out"))
model.add(layers.Dense(4, activation='softmax', name="fc_out"))
model.summary()
Was this page helpful?
0 / 5 - 0 ratings