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

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

input_shape = (img_rows, img_cols,1)

x_train = x_train.astype('float32')

x_test = x_test.astype('float32')

x_train /=255

x_test /=255

print('x_train shape:', x_train.shape)

print(x_train.shape[],'train samples')

print(x_test.shape[],'test samples')

# convert class vectors to binary class matrices

y_train = keras.utils.to_categorical(y_train, num_classes)

y_test = keras.utils.to_categorical(y_test, num_classes)

model = Sequential()

model.add(Conv2D(32, kernel_size=(3,3),

推荐阅读