您好我是Keras的新人。我选择keras来实现这篇论文:http://mmlab.ie.cuhk.edu.hk/projects/TCDCN.html。我只是将输入大小更改为48x48然后输出我只需要68个地标坐标。这是我的网络:
def mtfl40New(size):
model = Sequential()
model.add(Conv2D(16, (5, 5), padding='valid', input_shape=(3, size, size)))
model.add(Activation('tanh'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(48, (3, 3), padding='valid'))
model.add(Activation('tanh'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3), padding='valid'))
model.add(Activation('tanh'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (2, 2), padding='valid'))
model.add(Activation('tanh'))
model.add(Flatten())
model.summary()
#model.count_params()
model.add(Dense(100, kernel_initializer="normal", input_shape=(576,)))
model.add(Activation('tanh'))
model.add(Dense(136, kernel_initializer="normal"))
model.add(Activation('tanh'))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])
return model
答案 0 :(得分:2)
这又是您的输入形状与其解释格式之间的不兼容性。您已在Keras配置中设置了首先对通道进行排序的图像,而输入形状在末尾具有通道。要修复它,只需替换此行:
model.add(Conv2D(16, (5, 5), padding='valid', input_shape=(3, size, size)))
使用:
model.add(Conv2D(16, (5, 5), padding='valid', input_shape=(size, size, 3)))