检查目标时出错:预期输出的形状为(10,),但数组的形状为(1,)

时间:2020-04-05 02:37:43

标签: deep-learning cnn

我正在尝试在Google colab上实现Inception模型,当我运行model.fit时,出现了此错误。有人可以帮助我吗?

ValueError                                Traceback (most recent call last)
<ipython-input-25-b030aa96e908> in <module>()
      4                     batch_size=256,
      5                     epochs=epochs,
----> 6                     callbacks=[lr_sc])

2 frames
/usr/local/lib/python3.6/dist-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    139                             ': expected ' + names[i] + ' to have shape ' +
    140                             str(shape) + ' but got array with shape ' +
--> 141                             str(data_shape))
    142     return data
    143 

ValueError: Error when checking target: expected output to have shape (10,) but got array with shape (1,)

我的代码在这里:

epochs = 25
initial_lrate = 0.001

def decay(epoch, steps=100):
    initial_lrate = 0.001
    drop = 0.96
    epochs_drop = 8
    lrate = initial_lrate * math.pow(drop, math.floor((1+epoch)/epochs_drop))
    return lrate

sgd = SGD(lr=initial_lrate, momentum=0.9, nesterov=False)

lr_sc = LearningRateScheduler(decay, verbose=1)

model.compile(loss=['categorical_crossentropy', 'categorical_crossentropy', 'categorical_crossentropy'], loss_weights=[1, 0.3, 0.3], optimizer=sgd, metrics=['accuracy'])

和model.fit在这里:

history = model.fit(X_train, 
                    [y_train, y_train, y_train], 
                    validation_data=(X_test, [y_test, y_test, y_test]), 
                    batch_size=256, 
                    epochs=epochs, 
                    callbacks=[lr_sc])

0 个答案:

没有答案