python多输入识别_python-用于多位数识别的Keras

我正在尝试通过Keras(theano后端)中的一些练习来了解CNN.我无法拟合以下模型(错误:AttributeError:’Convolution2D’对象没有属性’get_shape’).此数据集是来自MNIST数据的图像(28 * 28),这些图像串联在一起,最多可包含五个图像.因此,输入形状应为1、28、140(灰度= 1,高度= 28,宽度= 28 * 5)

目的是预测数字的顺序.谢谢!!

batch_size = 128

nb_classes = 10

nb_epoch = 2

img_rows =28

img_cols=140

img_channels = 1

model_input=(img_channels, img_rows, img_cols)

x = Convolution2D(32, 3, 3, border_mode='same')(model_input)

x = Activation('relu')(x)

x = Convolution2D(32, 3, 3)(x)

x = Activation('relu')(x)

x = MaxPooling2D(pool_size=(2, 2))(x)

x = Dropout(0.25)(x)

conv_out = Flatten()(x)

x1 = Dense(nb_classes, activation='softmax')(conv_out)

x2 = Dense(nb_classes, activation='softmax')(conv_out)

x3 = Dense(nb_classes, activation='softmax')(conv_out)

x4 = Dense(nb_classes, activation='softmax')(conv_out)

x5 = Dense(nb_classes, activation='softmax')(conv_out)

lst = [x1, x2, x3, x4, x5]

model = Sequential(input=model_input, output=lst)

model.compile(loss='categorical_crossentropy',

optimizer='adam',

metrics=['accuracy'])

model.fit(dataset, data_labels, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1)

你可能感兴趣的:(python多输入识别)