python - Keras微调InceptionV3张量维度误差
问题描述
我正在尝试在 Keras 中微调模型:
inception_model = InceptionV3(weights=None, include_top=False, input_shape=(150,
150, 1))
x = inception_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(256, activation='relu', name='fc1')(x)
x = Dropout(0.5)(x)
predictions = Dense(10, activation='softmax', name='predictions')(x)
classifier = Model(inception_model.input, predictions)
####training training training ... save weights
classifier.load_weights("saved_weights.h5")
classifier.layers.pop()
classifier.layers.pop()
classifier.layers.pop()
classifier.layers.pop()
###enough poping to reach standard InceptionV3
x = classifier.output
x = GlobalAveragePooling2D()(x)
x = Dense(256, activation='relu', name='fc1')(x)
x = Dropout(0.5)(x)
predictions = Dense(10, activation='softmax', name='predictions')(x)
classifier = Model(classifier.input, predictions)
但我得到了错误:
ValueError: Input 0 is incompatible with layer global_average_pooling2d_3: expected ndim=4, found ndim=2
解决方案
推荐阅读
- kotlin - Kotlin 函数参数作为可挂起
- python - 如何将非常特殊的列表导出到 Excel 或 csv
- authorization - 使用 Canary 将默认当前用户覆盖为 Guardian 当前用户
- sql - Oracle SQL 使用欧几里德距离执行局部异常因子 (LOF)
- python - VS Code Python pip 无法识别
- javascript - Javascript如何重命名对象键维护值和位置
- python - 张量流中的 tf.matmul(X,weight) 与 tf.matmul(X,tf.traspose(weight))
- python-3.x - Flappy Bird pygame 基础未定义
- node.js - 类验证器不区分大小写的枚举验证?
- android - 尝试在 Firebase 中使用自定义身份验证登录时应用程序崩溃