import keras
from keras import layers
import matplotlib.pyplot as plt
import joblib
import keras.datasets.mnist as mnist
import pandas as pd
import numpy as np
(train_image, train_label), (test_image, test_label) = mnist.load_data()
#建立感知机
model = keras.Sequential()
model.add(layers.Flatten())#Flatten层可以将数据展平成1维的
model.add(layers.Dense(64, activation='relu'))#全连接层
model.add(layers.Dense(10, activation='softmax'))#全连接层,0-10手写数字,所以10个输出
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['acc'])
model.fit(train_image, train_label, epochs=50, batch_size=512, validation_data=(test_image, test_label))
#np.argmax(model_mnist.predict(test_image[:10], axis=1))
y = model.predict(test_image)
print(y)