用于多输出模型的预训练 CNN

Pre-trained CNN for multi-output models

如何将Keras Applications用于多输出模型?

我正在尝试将 VGG16 用于多输出模型,但出现值错误 ValueError: Input 0 of layer block1_conv1 is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape (None, 64, 64, 1)。我有点迷路,似乎无法在 VGG16 或任何其他 Keras 预训练应用程序的多输出上找到任何东西。

我以此为指导:Transfer Learning in Keras with Computer Vision

# load model without classifier layers
base_model = VGG16(weights='imagenet', include_top=False, input_shape=(IMG_HEIGHT, IMG_WIDTH,3))
# add new classifier layers
sex_x = base_model.output
sex_x = GlobalAveragePooling2D()(sex_x)
sex_x = Dropout(0.5)(gender_x)
output_sex = Dense(2, activation='sigmoid')(sex_x)

weight_x = base_model.output
weight_x = GlobalAveragePooling2D()(weight_x)
weight_x = Dropout(0.5)(weight_x)
output_weight = Dense(1, activation='linear')(weight_x)
# define new model
model = Model(inputs=base_model.inputs, outputs=[output_sex, output_weight])

model.compile(optimizer = 'adam', loss =['binary_crossentropy','mae',],metrics=['accuracy'])
history = model.fit(x_train,[y_train[:,0],y_train[:,1]],validation_data=(x_test,[y_test[:,0],y_test[:,1]]),epochs = 10, batch_size=128,shuffle = True)

关于我做错了什么有什么想法吗? `

根据这个错误,您的模型输入要求 3 channel RGB,但您的数据似乎是 1 channel(灰度)。确保你的数据有 RGB 图像。