CaptchaCracker验证码识别

联合创作 · 2023-09-26 06:25

CaptchaCracker 是一个开源的 Python 库,它提供了创建和应用深度学习模型来识别 Captcha 图像的功能。你可以创建一个深度学习模型,如下图所示识别 Captcha 图像中的数字,并输出一串数字,或者你可以自己尝试这个模型。

Input

Output

023062

Examples

训练和保存模型

在执行模型训练之前,应准备好训练数据图像文件,在文件名中注明验证码图像的实际值,如下图所示。

import glob
import CaptchaCracker as cc

# Training image data path
train_img_path_list = glob.glob("../data/train_numbers_only/*.png")

# Training image data size
img_width = 200
img_height = 50

# Creating an instance that creates a model
CM = cc.CreateModel(train_img_path_list, img_width, img_height)

# Performing model training
model = CM.train_model(epochs=100)

# Saving the weights learned by the model to a file
model.save_weights("../model/weights.h5")

加载一个已保存的模型来进行预测

import CaptchaCracker as cc

# Target image data size
img_width = 200
img_height = 50
# Target image label length
max_length = 6
# Target image label component
characters = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}

# Model weight file path
weights_path = "../model/weights.h5"
# Creating a model application instance
AM = cc.ApplyModel(weights_path, img_width, img_height, max_length, characters)

# Target image path
target_img_path = "../data/target.png"

# Predicted value
pred = AM.predict(target_img_path)
print(pred)
浏览 15
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报