每一次测试自己的模型准确率的时候都要重新训练一次,这样耗费大量的时间,所以这一次我们讲讲如何保存自己之前训练的模型,在测试阶段调用模型。
本次实验会使用我们上一次建立的模型,如果没有看过上一节,链接如下
一.保存训练的模型
程序步骤如下:
from sklearn.preprocessing import LabelBinarizer
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from pyimagesearch.preprocessing import ImageToArrayPreprocessor
from pyimagesearch.preprocessing import SimplePreprocessor
from pyimagesearch.datasets import SimpleDatasetLoader
from pyimagesearch.nn.conv import ShallowNet
from keras.optimizers import SGD
from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
ap=argparse.ArgumentParser()
ap.add_argument('-d','--dataset',required=True,help='path to the input dataset')
ap.add_argument('-m',