# 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
你在做xu测试的预测
和你的火车相比
我想应该是你的测试
你忘了正常化图像。当前,
x_train
中的值在[0,255]
范围内。这会导致大梯度更新和暂停训练过程。在这种情况下,一个简单的标准化方案是:这会导致值落在
[0,1]
范围内。你一定会看到训练的进展。你知道吗更复杂的标准化方案涉及特征(即像素)标准化或中心化。在这种方法中,我们对所有图像进行标准化,使得所有图像中的每个像素的平均值为0,标准偏差为1(即,它们大多在
[-1,1]
范围内):注意最后一部分:永远不要用自己的平均值和标准来规范化测试数据。使用训练平均值和标准来代替。你知道吗
相关问题 更多 >
编程相关推荐