使用CNN破解验证码与微笑检测实践
1. 使用CNN破解验证码
1.1 训练验证码破解模型
在定义好预处理函数后,我们可以开始在图像验证码数据集上训练LeNet模型。以下是具体步骤:
1.1.1 导入必要的包
打开 train_model.py
文件,插入以下代码:
# import the necessary packages
from sklearn.preprocessing import LabelBinarizer
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from keras.preprocessing.image import img_to_array
from keras.optimizers import SGD
from pyimagesearch.nn.conv import LeNet
from pyimagesearch.utils.captchahelper import preprocess
from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
以上代码导入了我们所需的Python包,我们将使用SGD优化器和LeNet架构在数字数据集上训练模型