我们是数据科学的新手,我们正在尝试合并两种不同的 CNN 模型(一个有 2 个类,另一个有 3 个类)。型号代码为:
性别模型
#initialize the model along with the input shape
model = Sequential()
inputShape = (height, width, depth)
chanDim = -1
if K.image_data_format() == 'channels_first':
inputShape = (depth, height, width)
chanDim = 1
# CONV -> RELU -> MAXPOOL
model.add(Convolution2D(64, (3,3), padding='same', input_shape=inputShape))
model.add(Activation('relu'))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(3,3)))
model.add(Dropout(0.25))
# (CONV -> RELU)*2 -> AVGPOOL
model.add(Convolution2D(128, (3,3), padding='same'))
model.add(Activation('relu'))
model.add(BatchNormalization(axis=chanDim))
model.add(Convolution2D(128, (3,3), padding='same'))
model.add(Activation('relu'))
model.add(BatchNormalization(axis=chanDim))
model.add(AveragePooling2D(pool_size=(3,3) ))
model.add(Dropout(0.25))
# CONV -> RELU -> MAXPOOL
model.add(Convolution2D(256, (3,3), padding='same'))
model.add(Activation('relu'))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(3,3)))
model.add(Dropout(0.25))
# CONV -> RELU -> AVGPOOL
model.add(Convolution2D(512, (3,3), padding='same'))
model.add(Activation('relu'))
model.add(BatchNormalization(axis=chanDim))
model.add(AveragePooling2D(pool_size=(3,3)))
model.add(Dropout(0.25))
# DENSE -> RELU
model.add(Flatten())
model.add(Dense(1024))
model.add(Activation('relu'))
model.add(BatchNormalization())
model.add(Dropout(0.25))
# DENSE -> RELU
model.add(Dense(512))
model.add(Activation('relu'))
model.add(BatchNormalization())
model.add(Dropout(0.25))
我们尝试使用 concatenate keras 函数合并模型,但未能理解如何合并具有不同数量类的两个模型。我们的目标是:给定一张照片,我们希望同时预测性别和种族感谢您的关注。
一只名叫tom的猫
相关分类