问题遇到的现象和发生背景
关于 您车牌识别的资源里面 mnist_orgin.py 里面引用的 mnist.zip 文件。请问mnist_orgin.py 是用来评估模型准确性的吗? 资源里缺少的 mnist.zip 文件是什么呢?是否是类似训练用的车牌字体二值化图片,还是网络上的mnist文件?能否得到您这个文件的下载资源呢?
用代码块功能插入代码,请勿粘贴截图
import numpy as np
from keras.utils import to_categorical
path="mnist.zip" ############ **_就是这个文件__**
mnist_data = np.load(path)
train_X, train_y = mnist_data["x_train"], mnist_data["y_train"]
train_X = train_X.reshape(-1, 28, 28, 1)
train_X = train_X.astype('float32')
train_X /= 255
train_y = to_categorical(train_y, 10) # 对数字的标签分类做One-Hot编码
from keras.models import Sequential # 模型、层、损失函数、优化器
from keras.layers import Conv2D, MaxPool2D, Flatten, Dropout, Dense
from keras.losses import categorical_crossentropy
from keras.optimizers import Adadelta
model = Sequential()
model.add(Conv2D(32, (5, 5), activation='relu', input_shape=[28, 28, 1]))
model.add(Conv2D(64, (5, 5), activation='relu'))
model.add(MaxPool2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
model.compile(loss=categorical_crossentropy,
optimizer=Adadelta(),
metrics=['accuracy'])
# 模型训练
batch_size = 100
epochs = 8
model.fit(train_X, train_y,
batch_size=batch_size,
epochs=epochs)
# 模型评估
test_X, test_y = mnist_data["x_test"], mnist_data["y_test"]
test_X = test_X.reshape(-1, 28, 28, 1)
test_X = test_X.astype('float32')
test_X /= 255
test_y = to_categorical(test_y, 10)
loss, accuracy = model.evaluate(test_X, test_y, verbose=1)
print('loss:%.4f accuracy:%.4f' % (loss, accuracy))