基于keras的不同神经网络模型MNIST手写体识别
1.CNN版
1.导入数据
相关库(导入plt是为了看数据集的图)
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Flatten, Conv2D, MaxPool2D,Activation,Dropout
from matplotlib import pyplot as plt
以下是keras里的原装数据集mnist的源码
def load_data(path='mnist.npz'):
# Returns
Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`.
"""
path = get_file(path,
origin='https://s3.amazonaws.com/img-datasets/mnist.npz',
file_hash='8a61469f7ea1b51cbae51d4f78837e45')
with np.load(path, allow_pickle=True) as f:
x_train, y_train = f['x_train'], f['y_train']
x_test, y_test = f['x_test'], f['y_test']
return (x_train, y_train)