[英]ResNet50 network in Keras functional API (python)
I want to transform the code below in Keras functional API.我想在 Keras 功能 API 中转换下面的代码。 This code worked fine when I trained it(with a softmax layer in the end).当我训练它时,这段代码运行良好(最后有一个 softmax 层)。
Resnet = ResNet50(include_top=False,
weights='imagenet', input_shape=(224, 224, 3))
image_model = tf.keras.Sequential(Resnet)
image_model.add(layers.GlobalAveragePooling2D())
#image_model.summary()
This is what I came up with using the tutorial from Keras functional API:这是我使用 Keras 功能 API 的教程得出的结论:
first_input = ResNet50(include_top=False, weights='imagenet', input_shape=(224, 224, 3))
first_dense = layers.GlobalAveragePooling2D()(first_input)
However, this error appears when I try to create the variable first_dense
:但是,当我尝试创建变量first_dense
时出现此错误:
Inputs to a layer should be tensors. Got: <tensorflow.python.keras.engine.functional.Functional
object at 0x000002566CE37520>
Your ResNet model should receive an input from an Input
layer and then be connected to the following layers like in the example below您的ResNet model 应该从Input
层接收输入,然后连接到以下层,如下例所示
resnet = ResNet50(include_top=False, weights='imagenet', input_shape=(224, 224, 3))
inp = Input((224,224,3))
x = resnet(inp)
x = GlobalAveragePooling2D()(x)
out = Dense(3, activation='softmax')(x)
model = Model(inp,out)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.