在继续进行的过程中,img_rows和img_cols用作图像尺寸。在mnist数据集中,它是28和28.我们还需要检查数据格式,即'channels_first'或'channels_last'。在CNN中,我们可以在数据之前对数据进行标准化,使得大的计算项可以减少到更小的项。比如,我们可以通过将其除以255来规范化x_train和x_test数据。
检查数据格式:
img_rows, img_cols=28, 28
if k.image_data_format() == 'channels_first':
x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
inpx = (1, img_rows, img_cols)
else:
x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
inpx = (img_rows, img_cols, 1)
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255
x_test /= 255








暂无数据