gpt4 book ai didi

python - 应用程序中的 Keras 形状错误 Inception Resnet v2

转载 作者:太空宇宙 更新时间:2023-11-04 04:49:16 24 4
gpt4 key购买 nike

我正在使用 Keras 2.1.3,我正在尝试使用 Keras 应用程序微调 Inception Resnetv2。

所以我从 keras.applications 加载预训练模型

input_tensor = Input(shape=(299,299,3))
model = applications.inception_resnet_v2.InceptionResNetV2(weights='imagenet',
include_top=False,
input_tensor=input_tensor,
input_shape=(299, 299,3))

我为我的问题制造了瓶颈:

top_model = Sequential()
top_model.add(Flatten(input_shape=model.output_shape[1:]))
top_model.add(Dense(256, activation='relu'))
top_model.add(Dropout(0.5))
top_model.add(Dense(40, activation='softmax'))

最后创建一个新模型来连接两部分:

new_model = Sequential()
for l in model.layers:
new_model.add(l)

到这一步,我报错了

ValueError: Input 0 is incompatible with layer conv2d_7: expected axis -1 of input shape to have value 192 but got shape (None, 35, 35, 64)

所以我打印了每一层的形状并且我有

Layer n-1 : Input : (None, 35, 35, 64), Output : (None, 35, 35, 64)

Layer n : Input : (None, 35, 35, 192), Output : (None, 35, 35, 48)

如您所见,形状不匹配,来自 Keras 的形状看起来很奇怪。

最佳答案

我不确定 top_model.add(Flatten(input_shape=model.output_shape[1:])) 是否传递了所需的尺寸。
另一种方法是尝试。

ResNetV2_model_output = model.output
new_concatenated_model = Flatten()(ResNetV2_model_output)
new_concatenated_model = (Dense(256, activation='relu'))(new_concatenated_model)
new_concatenated_model = ((Dropout(0.5)))(new_concatenated_model)
new_concatenated_model = (Dense(40, activation='softmax'))(new_concatenated_model)

关于python - 应用程序中的 Keras 形状错误 Inception Resnet v2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48785552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com