基于多位数预测的Keras阵列误差
我正试图实现这个架构,从SVHN数据集中的图像中预测数字,我需要从图像中预测多个数字 我已经准备好了以下数据形状:基于多位数预测的Keras阵列误差,keras,Keras,我正试图实现这个架构,从SVHN数据集中的图像中预测数字,我需要从图像中预测多个数字 我已经准备好了以下数据形状: 列车:(188602,32,32,1) 列车假人:(188602,5,11) X_val:(47151,32,32,1) y_val_假人:(47151,5,11) 然而,在我的代码中,当我尝试适应时,我遇到了这个错误(在此之前一切都正常) 这不是全部错误。我也无法识别代码中链接图像的尺寸。很容易看出,y\u train\u dummy就是问题所在。有关损失维度的假设,请查看k
- 列车:(188602,32,32,1)
- 列车假人:(188602,5,11)
- X_val:(47151,32,32,1)
- y_val_假人:(47151,5,11)
这不是全部错误。我也无法识别代码中链接图像的尺寸。很容易看出,
y\u train\u dummy
就是问题所在。有关损失维度的假设,请查看keras文档。@sascha我添加了全部错误。问题似乎出在y_train_dummy上,我可能有5个输出(每个输出有10个类),但只有1个带标签的数组(有10个类)。
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-136-c031c9f027b5> in <module>()
----> 1 model.fit(X_train, y_train_dummy, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1, validation_data=(X_val, y_val_dummy))
/Users/home/anaconda3/lib/python3.5/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, nb_epoch, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight)
1032 class_weight=class_weight,
1033 check_batch_dim=False,
-> 1034 batch_size=batch_size)
1035 # prepare validation data
1036 if validation_data:
/Users/home/anaconda3/lib/python3.5/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_batch_dim, batch_size)
963 output_shapes,
964 check_batch_dim=False,
--> 965 exception_prefix='model target')
966 sample_weights = standardize_sample_weights(sample_weight,
967 self.output_names)
/Users/home/anaconda3/lib/python3.5/site-packages/keras/engine/training.py in standardize_input_data(data, names, shapes, check_batch_dim, exception_prefix)
74 raise Exception('The model expects ' + str(len(names)) +
75 ' input arrays, but only received one array. '
---> 76 'Found: array with shape ' + str(data.shape))
77 arrays = [data]
78
Exception: The model expects 5 input arrays, but only received one array. Found: array with shape (188602, 5, 11)
batch_size = 128
nb_classes = 10
nb_epoch = 2
_, img_rows, img_cols, img_channels = X_train.shape
model_input = Input(shape=(img_rows, img_cols, img_channels))
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 = Model(input=model_input, output=lst)
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd)
model.fit(X_train, y_train_dummy, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1, validation_data=(X_val, y_val_dummy))