必备!人工智能和数据科学的七大 Python 库(13)

fromkeras.layersimportConv2D, MaxPooling2D

fromkerasimportbackendasK

batch_size =128

num_classes =10

epochs =12

# input image dimensions

img_rows, img_cols =28,28

# the data, split between train and test sets

(x_train, y_train), (x_test, y_test) = mnist.load_data()

ifK.image_data_format() =='channels_first':

x_train = x_train.reshape(x_train.shape[],1, img_rows, img_cols)

x_test = x_test.reshape(x_test.shape[],1, img_rows, img_cols)

input_shape = (1, img_rows, img_cols)

else:

x_train = x_train.reshape(x_train.shape[], img_rows, img_cols,1)

推荐阅读