• Stars
    star
    992
  • Rank 46,173 (Top 1.0 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Image Captcha Solving Using TensorFlow and CNN Model. Accuracy 90%+

Captcha Solving Using TensorFlow

Introduction

  1. Solve captcha using TensorFlow.
  2. Learn CNN and TensorFlow by a practical project.

Follow the steps, run the code, and it works!

the accuracy of 4 digits version can be as high as 99.8%!

There are several more steps to put this prototype on production.

Ping me for paid technical supports.

[email protected]

Table of Contents

  • Solve Captcha Using CNN Model

    • Training: 4-digits Captcha
    • Training: 4-letters Captcha
    • Inference: load trained model and predict given images
  • Generate DataSet for Training

    • Usage
    • Example 1: 4 chars per captcha, use digits only
    • Example 2: sampling random images

Solve Captcha Using CNN Model

old code that using tensorflow 1.x is moved to tensorflow_v1.

Training: 4-digits Captcha

this is a perfect project for beginers.

we will train a model of ~90% accuracy in 1 minute using one single GPU card (GTX 1080 or above).

if we increase the dataset by 10x, the accuracy increases to 98.8%. we can further increase the accuracy to 99.8% using 1M traning images.

here is the source code and running logs: captcha-solver-tf2-4digits-AlexNet-98.8.ipynb

Images, Ground Truth and Predicted Values:

there is 1 predicton error out of the 20 examples below. 9871 -> 9821

Accuracy and Loss History:

Model Structure:

  • 3 convolutional layers, followed by 2x2 max pooling layer each.
  • 1 flatten layer
  • 2 dense layer

Training: 4-letters Captcha

this is a more practical project.

the code is the same as the 4-digits version, but the training dataset is much bigger.

it costs 2-3 hours to generate training dataset and costs 30 min to train a 95% accuracy model.

here is the source code and running logs: captcha-solver-tf2-4letters-AlexNet.ipynb

Inference: load trained model and predict given images

example: captcha-solver-model-restore.ipynb

Generate DataSet for Training

Usage

$ python datasets/gen_captcha.py  -h
usage: gen_captcha.py [-h] [-n N] [-c C] [-t T] [-d] [-l] [-u] [--npi NPI] [--data_dir DATA_DIR]

optional arguments:
  -h, --help           show this help message and exit
  -n N                 epoch number of character permutations.
  -c C                 max count of images to generate. default unlimited
  -t T                 ratio of test dataset.
  -d, --digit          use digits in dataset.
  -l, --lower          use lowercase in dataset.
  -u, --upper          use uppercase in dataset.
  --npi NPI            number of characters per image.
  --data_dir DATA_DIR  where data will be saved.

examples:

Example 1: 4 chars per captcha, use digits only

1 epoch has 10*9*8*7=5040 images, generate 6 epoches for training.

generating the dataset:

$ python datasets/gen_captcha.py -d --npi=4 -n 6
10 choices: 0123456789
generating 6 epoches of captchas in ./images/char-4-epoch-6/train
generating 1 epoches of captchas in ./images/char-4-epoch-6/test
write meta info in ./images/char-4-epoch-6/meta.json

preview the dataset:

$ python datasets/base.py images/char-4-epoch-6/
========== Meta Info ==========
num_per_image: 4
label_choices: 0123456789
height: 100
width: 120
n_epoch: 6
label_size: 10
==============================
train images: (30240, 100, 120), labels: (30240, 40)
test images: (5040, 100, 120), labels: (5040, 40)

Example 2: sampling random images

scenario: use digits/upper cases, 4 chars per captcha image.

1 epoch will have 36*35*34*33=1.4M images. the dataset is too big to debug.

using -c 10000 param, sampling 10k random images.

generating the dataset:

$ python3 datasets/gen_captcha.py -du --npi 4 -n 1 -c 10000
36 choices: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
generating 1 epoches of captchas in ./images/char-4-epoch-1/train.
only 10000 records used in epoche 1. epoche_count: 1413720

Running Jupyter in docker

tensorflow image: https://hub.docker.com/r/jackon/tensorflow-2.1-gpu

docker pull jackon/tensorflow-2.1-gpu
# check if gpu works in docker container
docker run --rm --gpus all -t jackon/tensorflow-2.1-gpu /usr/bin/nvidia-smi
# start jupyter server in docker container
docker run --rm --gpus all -p 8899:8899 -v $(realpath .):/tf/notebooks -t jackon/tensorflow-2.1-gpu

More Repositories

1

money-maker-apps

我认为有赚钱能力的开源小程序、个人网站
JavaScript
891
star
2

maya

骂丫--对骂机器人。君子动口不动手,科技改变骂丫
Python
205
star
3

paper-reading

比做算法的懂工程落地,比做工程的懂算法模型。
Jupyter Notebook
194
star
4

renren

人人网信息抓取与数据挖掘。social network analysis
Python
94
star
5

bookhub

eBook manager and sharing tools
Python
91
star
6

wechat-notification

通过微信公众号, 将通知信息推送至个人微信. 无需认证公众号, 可群发.
Python
58
star
7

personalization-vocabulary

根据个人的英语水平、兴趣和经常阅读的文章, 自动创建一个自定义的生词库,供背单词使用。
Python
33
star
8

distributed-vertical-crawlers

分布式垂直爬虫框架 & 爬虫们
Python
15
star
9

pages

一个月黑风不高的夜晚,接到一单外包。通宵写了这 270 行代码,赚了 1 万。
HTML
14
star
10

porn-hot-classification

Tensorflow 版本的图片鉴黄。not suitable/safe for work (NSFW) images detection using Tensorflow
Jupyter Notebook
13
star
11

football

足彩爬虫与数据分析
Python
12
star
12

dianping-crawler

大众点评网爬虫
HTML
10
star
13

hands-on-deep-learning-using-tensorflow-2.0

重读 CNN 网络的经典论文,并用 tensorflow 2.0 手撸一遍经典模型,感受一下实测数据
Jupyter Notebook
9
star
14

wechat-broker-bot

微信消息转发器
Python
7
star
15

mcm_latex_template

美赛数学建模论文 latex 模板 2010年 H 奖
6
star
16

django2-python3-docker-tmpl

Python3 & Django2 web 项目通用模板。docker & 微服务部署
Python
6
star
17

parenting

育儿的图书、文章、攻略和一页纸计划
5
star
18

ansible-playbooks

管理个人开发环境、服务器资源的 playbook 们
Shell
5
star
19

topology

树形结构展示网络拓扑图
JavaScript
5
star
20

projects-in-one

我的独立项目,都在这里。
JavaScript
5
star
21

media-of-lean-read

lean-read media与数据库备份
Shell
5
star
22

PerfTrack

linux 性能监控与图像显示。启动、关闭 sar 监控系统运行状态,并将性能运行信息写入文件; 显示滤波后的性能曲线;清理数据文件。
Python
5
star
23

interview-questions

HTML
2
star
24

vimrc

vim 配置备份
C++
2
star
25

shadowsocks-proxychains4-openvpn

文章最早发在知乎上,被和谐了。在这里做个备份
2
star
26

reading-more-books

我的读书笔记
2
star
27

score-now

实时比分与赔率信息
JavaScript
1
star
28

lottery-article-writer

rubbish
Python
1
star
29

dataset-repo

collection of datasets for deep learning
Python
1
star
30

compile_latex

latex 自动编译脚本
Shell
1
star
31

public-wechat-proxy

微信公众号消息 proxy
Python
1
star
32

iTableOcr

基于深度学习的 Table 信息提取框架
Python
1
star
33

paper-pipe

科技论文的下载、数据清洗与信息提取,试着碰撞一下好玩的思路💥
Python
1
star