2 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
您忘記了對(duì)圖像進(jìn)行標(biāo)準(zhǔn)化。當(dāng)前,中的值在x_train范圍內(nèi)[0,255]。這會(huì)導(dǎo)致較大的梯度更新并拖延訓(xùn)練過(guò)程。在這種情況下,一種簡(jiǎn)單的標(biāo)準(zhǔn)化方案是:
x_train = x_train.astype('float32') / 255
x_test = x_test.astype('float32') / 255
這將導(dǎo)致值落在范圍內(nèi)[0,1]。然后,您肯定會(huì)看到培訓(xùn)的進(jìn)展。
更復(fù)雜的歸一化方案涉及按特征(即按像素)歸一化或居中。在這種方法中,我們對(duì)所有圖像進(jìn)行歸一化,以使所有圖像中的每個(gè)像素的平均值為零,標(biāo)準(zhǔn)差為1(即,它們大多落在范圍內(nèi)[-1,1]):
# make sure values are float
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_mean = x_train.mean(axis=0)
x_train -= x_mean
x_std = x_train.std(axis=0)
x_train /= x_std + 1e-8 # add a small constant to prevent division by zero
# normalize test data using the mean and std of training data
x_test -= x_mean
x_test /= x_std + 1e-8
注意最后一部分:永遠(yuǎn)不要以自己的均值和std標(biāo)準(zhǔn)化測(cè)試數(shù)據(jù)。使用訓(xùn)練平均值和std代替。

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊
您正在對(duì)x_test進(jìn)行預(yù)測(cè)
predictions = model.predict_classes(x_test, batch_size=50)
而不是將它們與y_train進(jìn)行比較
comparison = [(predictions[i], y_train_[i][0]) for i in range(0, len(predictions))]
我認(rèn)為應(yīng)該是y_test
添加回答
舉報(bào)