【发布时间】:2021-12-15 12:18:53
【问题描述】:
我正在尝试使用迁移学习对 2 个类别进行分类。预处理我的数据后,我想应用“InceptionResNetV2”。我想删除这个 Keras 应用程序的最后一层并想添加一个层。 我为此编写了以下脚本:
irv2 = tf.keras.applications.inception_resnet_v2.InceptionResNetV2()
irv2.summary()
x = irv2.layers[-1].output
x = Dropout(0.25)(x)
predictions = Dense(2, activation='softmax')(x)
model = Model(inputs=mobile.input, outputs=predictions)
然后出现错误:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-40-911de74d9eaf> in <module>()
5 predictions = Dense(2, activation='softmax')(x)
6
----> 7 model = Model(inputs=mobile.input, outputs=predictions)
NameError: name 'Model' is not defined
如果有其他方法可以删除最后一层并添加新层(
predictions = Dense(2, activation='softmax')),请告诉我。
这是我完整的code。
【问题讨论】:
标签: keras conv-neural-network keras-layer transfer-learning