【问题标题】:Input dimension mismatch between dense layers and conv layers of imagenet while attempting transfer learning尝试迁移学习时 imagenet 的密集层和卷积层之间的输入维度不匹配
【发布时间】:2019-09-06 17:15:46
【问题描述】:

我正在尝试在 InceptionV3 的卷积层之上训练密集层。 但我无法初始化全连接模型。我收到一个 ValueError。

model_inc = applications.InceptionV3(weights='imagenet', 
                                     include_top=False)

model = Sequential()
model.add(Flatten(input_shape=model_inc.output_shape[1:]))
model.add(Dense(256, activation= 'relu', kernel_initializer='he_normal'))
model.add(Dropout(0.5))
model.add(Dense(9, activation='softmax'))

我希望模型能够成功编译,但我得到“ValueError:“Flatten”的输入形状未完全定义(得到(None,None,2048)。确保传递完整的“input_shape”或“ batch_input_shape" 模型中第一层的参数。"

【问题讨论】:

  • 请注意,加载一个模型然后再加载另一个可能会导致自动命名的图层发生冲突!命名层(sucks 和)有效,或者如果您重复运行,keras.backend.clear_session() 是一个方便的修复。

标签: tensorflow keras transfer-learning imagenet


【解决方案1】:

您希望您的输入转到您的model_inc,因此您必须在那里定义input_shape。像下面这样的东西应该可以工作

model_inc = applications.InceptionV3(input_shape=(224,224,3), weights='imagenet', 
                                     include_top=False)
model = Sequential()

# you need to add your base model
model.add(model_inc)

model.add(Flatten())
model.add(Dense(256, activation= 'relu', kernel_initializer='he_normal'))
model.add(Dropout(0.5))
model.add(Dense(9, activation='softmax'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2017-12-19
    相关资源
    最近更新 更多