Giter VIP home page Giter VIP logo

captcha-tensorflow's Introduction

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

captcha-tensorflow's People

Contributors

0x0000dead avatar ac1982 avatar coolcash1 avatar dejqk avatar dependabot[bot] avatar grissiom avatar jackonyang avatar takeru avatar turicas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

captcha-tensorflow's Issues

Specific question No issue.

Hello There,

First of All Nice job!
I have a specific question, i am looking for a captcha solver
That can solve the Pictures i provide aa attachment,

I am looking for almost 7 months Now And still dont found
Where i looking for, i want to use the solver in Java,

I hope their is Someone that can help, sorry for opening the issue
I dont know How to contact on a other way.

Greetings Klapkaak078
49813054-07d6-460e-960d-b94661d2c3c6
2759e22d-128d-4741-b227-5892d3f15f83

Why not the training accuracy and test accuracy rise?

我是直接使用的此代码,其中只是更改了数据集的大小,设定的数据集为30000张训练集,6000张测试集,每幅验证码由数字和大小写字符构成。但是实际在训练时发现train accuracy 和test accuracy都上不去,而且loss达到4.12左右就不再下降,请问这是什么原因?
2018-04-11 11-18-36

2018-04-11 11-10-05

ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape

#python cnn_1_char.py --data_dir=images/char-1-epoch-1000/

data loaded
train images: 10000. test images: 2000
label_size: 10, image_size: 6000
2018-03-18 15:52:23.154212: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-03-18 15:52:23.246932: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-03-18 15:52:23.247218: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties: 
name: GeForce GTX 1050 major: 6 minor: 1 memoryClockRate(GHz): 1.493
pciBusID: 0000:01:00.0
totalMemory: 3.95GiB freeMemory: 2.73GiB
2018-03-18 15:52:23.247233: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)
2018-03-18 15:52:34.593156: W tensorflow/core/common_runtime/bfc_allocator.cc:273] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.43GiB.  Current allocation summary follows.
2018-03-18 15:52:34.593232: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (256):   Total Chunks: 31, Chunks in use: 31. 7.8KiB allocated for chunks. 7.8KiB in use in bin. 2.1KiB client-requested in use in bin.
2018-03-18 15:52:34.593264: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (512):   Total Chunks: 1, Chunks in use: 0. 768B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593289: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (1024):  Total Chunks: 1, Chunks in use: 1. 1.2KiB allocated for chunks. 1.2KiB in use in bin. 1.0KiB client-requested in use in bin.
2018-03-18 15:52:34.593312: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (2048):  Total Chunks: 5, Chunks in use: 5. 16.2KiB allocated for chunks. 16.2KiB in use in bin. 15.6KiB client-requested in use in bin.
2018-03-18 15:52:34.593333: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (4096):  Total Chunks: 5, Chunks in use: 5. 20.0KiB allocated for chunks. 20.0KiB in use in bin. 20.0KiB client-requested in use in bin.
2018-03-18 15:52:34.593353: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (8192):  Total Chunks: 1, Chunks in use: 1. 15.8KiB allocated for chunks. 15.8KiB in use in bin. 15.6KiB client-requested in use in bin.
2018-03-18 15:52:34.593373: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (16384):         Total Chunks: 1, Chunks in use: 0. 21.0KiB allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593394: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (32768):         Total Chunks: 4, Chunks in use: 4. 160.0KiB allocated for chunks. 160.0KiB in use in bin. 160.0KiB client-requested in use in bin.
2018-03-18 15:52:34.593415: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (65536):         Total Chunks: 2, Chunks in use: 1. 160.0KiB allocated for chunks. 78.2KiB in use in bin. 78.1KiB client-requested in use in bin.
2018-03-18 15:52:34.593436: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (131072):        Total Chunks: 4, Chunks in use: 4. 800.0KiB allocated for chunks. 800.0KiB in use in bin. 800.0KiB client-requested in use in bin.
2018-03-18 15:52:34.593453: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (262144):        Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593471: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (524288):        Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593488: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (1048576):       Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593505: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (2097152):       Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593522: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (4194304):       Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593539: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (8388608):       Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593557: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (16777216):      Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593578: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (33554432):      Total Chunks: 2, Chunks in use: 1. 93.75MiB allocated for chunks. 45.78MiB in use in bin. 45.78MiB client-requested in use in bin.
2018-03-18 15:52:34.593599: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (67108864):      Total Chunks: 4, Chunks in use: 4. 375.00MiB allocated for chunks. 375.00MiB in use in bin. 375.00MiB client-requested in use in bin.
2018-03-18 15:52:34.593616: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (134217728):     Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2018-03-18 15:52:34.593636: I tensorflow/core/common_runtime/bfc_allocator.cc:627] Bin (268435456):     Total Chunks: 1, Chunks in use: 1. 1.98GiB allocated for chunks. 1.98GiB in use in bin. 1.43GiB client-requested in use in bin.
2018-03-18 15:52:34.593654: I tensorflow/core/common_runtime/bfc_allocator.cc:643] Bin for 1.43GiB was 256.00MiB, Chunk State: 
2018-03-18 15:52:34.593673: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c00000 of size 1280
2018-03-18 15:52:34.593688: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c00500 of size 256
2018-03-18 15:52:34.593701: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c00600 of size 256
2018-03-18 15:52:34.593715: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c00700 of size 256
2018-03-18 15:52:34.593728: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c00800 of size 256
2018-03-18 15:52:34.593743: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c00900 of size 40960
2018-03-18 15:52:34.593757: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c0a900 of size 4096
2018-03-18 15:52:34.593770: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c0b900 of size 256
2018-03-18 15:52:34.593784: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c0ba00 of size 256
2018-03-18 15:52:34.593797: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c0bb00 of size 256
2018-03-18 15:52:34.593811: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c0bc00 of size 3328
2018-03-18 15:52:34.593824: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c0c900 of size 256
2018-03-18 15:52:34.593843: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c0ca00 of size 204800
2018-03-18 15:52:34.593857: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c3ea00 of size 256
2018-03-18 15:52:34.593870: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c3eb00 of size 256
2018-03-18 15:52:34.593884: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0513c3ec00 of size 98304000
2018-03-18 15:52:34.593898: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f05199fec00 of size 4096
2018-03-18 15:52:34.593911: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f05199ffc00 of size 256
2018-03-18 15:52:34.593924: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f05199ffd00 of size 256
2018-03-18 15:52:34.593937: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f05199ffe00 of size 256
2018-03-18 15:52:34.593951: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f05199fff00 of size 256
2018-03-18 15:52:34.593964: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a00000 of size 256
2018-03-18 15:52:34.593977: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a00100 of size 256
2018-03-18 15:52:34.593990: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a00200 of size 256
2018-03-18 15:52:34.594003: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a00300 of size 256
2018-03-18 15:52:34.594016: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a00400 of size 256
2018-03-18 15:52:34.594029: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a00500 of size 256
2018-03-18 15:52:34.594043: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a00900 of size 256
2018-03-18 15:52:34.594056: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a00a00 of size 40960
2018-03-18 15:52:34.594070: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a0aa00 of size 80128
2018-03-18 15:52:34.594084: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a32a00 of size 256
2018-03-18 15:52:34.594097: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0519a32b00 of size 48000000
2018-03-18 15:52:34.594111: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f7f2b00 of size 40960
2018-03-18 15:52:34.594123: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f7fcb00 of size 4096
2018-03-18 15:52:34.594137: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f7fdb00 of size 16128
2018-03-18 15:52:34.594150: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f801a00 of size 3328
2018-03-18 15:52:34.594164: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f807b00 of size 40960
2018-03-18 15:52:34.594178: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f811b00 of size 256
2018-03-18 15:52:34.594191: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f811c00 of size 256
2018-03-18 15:52:34.594204: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f811d00 of size 256
2018-03-18 15:52:34.594218: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f811e00 of size 3328
2018-03-18 15:52:34.594231: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f812b00 of size 3328
2018-03-18 15:52:34.594244: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f813800 of size 256
2018-03-18 15:52:34.594258: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f813900 of size 256
2018-03-18 15:52:34.594271: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f813a00 of size 204800
2018-03-18 15:52:34.594284: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f845a00 of size 204800
2018-03-18 15:52:34.594298: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f877a00 of size 256
2018-03-18 15:52:34.594311: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f877b00 of size 256
2018-03-18 15:52:34.594324: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f877c00 of size 256
2018-03-18 15:52:34.594338: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f051f877d00 of size 98304000
2018-03-18 15:52:34.594351: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f0525637d00 of size 98304000
2018-03-18 15:52:34.594364: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f052b3f7d00 of size 256
2018-03-18 15:52:34.594377: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f052b3f7e00 of size 4096
2018-03-18 15:52:34.594391: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f052b3f8e00 of size 4096
2018-03-18 15:52:34.594404: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f052b3f9e00 of size 3328
2018-03-18 15:52:34.594417: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f052b3fab00 of size 204800
2018-03-18 15:52:34.594430: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f052b42cb00 of size 98304000
2018-03-18 15:52:34.594444: I tensorflow/core/common_runtime/bfc_allocator.cc:661] Chunk at 0x7f05311ecb00 of size 2126722304
2018-03-18 15:52:34.594458: I tensorflow/core/common_runtime/bfc_allocator.cc:670] Free at 0x7f0519a00600 of size 768
2018-03-18 15:52:34.594472: I tensorflow/core/common_runtime/bfc_allocator.cc:670] Free at 0x7f0519a1e300 of size 83712
2018-03-18 15:52:34.594485: I tensorflow/core/common_runtime/bfc_allocator.cc:670] Free at 0x7f051c7f9700 of size 50304000
2018-03-18 15:52:34.594499: I tensorflow/core/common_runtime/bfc_allocator.cc:670] Free at 0x7f051f802700 of size 21504
2018-03-18 15:52:34.594512: I tensorflow/core/common_runtime/bfc_allocator.cc:676]      Summary of in-use Chunks by size: 
2018-03-18 15:52:34.594529: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 31 Chunks of size 256 totalling 7.8KiB
2018-03-18 15:52:34.594545: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 1280 totalling 1.2KiB
2018-03-18 15:52:34.594561: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 5 Chunks of size 3328 totalling 16.2KiB
2018-03-18 15:52:34.594577: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 5 Chunks of size 4096 totalling 20.0KiB
2018-03-18 15:52:34.594593: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 16128 totalling 15.8KiB
2018-03-18 15:52:34.594608: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 4 Chunks of size 40960 totalling 160.0KiB
2018-03-18 15:52:34.594624: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 80128 totalling 78.2KiB
2018-03-18 15:52:34.594639: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 4 Chunks of size 204800 totalling 800.0KiB
2018-03-18 15:52:34.594655: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 48000000 totalling 45.78MiB
2018-03-18 15:52:34.594671: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 4 Chunks of size 98304000 totalling 375.00MiB
2018-03-18 15:52:34.594686: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 2126722304 totalling 1.98GiB
2018-03-18 15:52:34.594701: I tensorflow/core/common_runtime/bfc_allocator.cc:683] Sum Total of in-use chunks: 2.39GiB
2018-03-18 15:52:34.594721: I tensorflow/core/common_runtime/bfc_allocator.cc:685] Stats: 
Limit:                  2619473920
InUse:                  2569063936
MaxInUse:               2569063936
NumAllocs:                     189
MaxAllocSize:           2126722304

2018-03-18 15:52:34.594755: W tensorflow/core/common_runtime/bfc_allocator.cc:277] ******_***********************************************************************xxxxxxxxxxxxxxxxxxxxxx
2018-03-18 15:52:34.594788: W tensorflow/core/framework/op_kernel.cc:1192] Resource exhausted: OOM when allocating tensor with shape[2000,32,100,60]
Traceback (most recent call last):
  File "cnn_1_char.py", line 167, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "cnn_1_char.py", line 148, in main
    test_summary, test_accuracy = sess.run([merged, accuracy], feed_dict={x: test_x, y_: test_y, keep_prob: 1.0})
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 889, in run
    run_metadata_ptr)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1120, in _run
    feed_dict_tensor, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1317, in _do_run
    options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1336, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[2000,32,100,60]
         [[Node: convolution-layer-1/Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](input/Reshape, convolution-layer-1/Variable/read)]]

Caused by op u'convolution-layer-1/Conv2D', defined at:
  File "cnn_1_char.py", line 167, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "cnn_1_char.py", line 75, in main
    h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
  File "cnn_1_char.py", line 41, in conv2d
    return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 631, in conv2d
    data_format=data_format, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[2000,32,100,60]
         [[Node: convolution-layer-1/Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](input/Reshape, convolution-layer-1/Variable/read)]]

How can I solve it?

How to test using a single image

Hey, i found this code and it's amazing, thanks for all! I have a issue... how to pass a single captcha per time? In the example you pass a batch.

plus issue: how can i gerenate a black and white captcha? In this case you pass the number 3 on the argument C (RGB), i need to generate more collored type of captchas.

1000

What happened when i use other value ...
No such file or directory: 'images/char-1-epoch-2000/meta.json

 $time python3 simple_softmax.py images/char-1-epoch-1000/
Traceback (most recent call last):
  File "simple_softmax.py", line 70, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 124, in run
    _sys.exit(main(argv))
  File "simple_softmax.py", line 17, in main
    meta, train_data, test_data = input_data.load_data(FLAGS.data_dir, flatten=True)
  File "/home/user/captcha-tensorflow/datasets/base.py", line 13, in load_data
    with open(meta_info, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'images/char-1-epoch-2000/meta.json'

in my opinion this is error

how should i adpat to a different image size?

there are some errors indicates me that image size doesn't fit

Invalid argument: Input to reshape is a tensor with 832000 values, but the requested shape requires a multiple of 40000

original size generated from captcha was 100100, could you please tell me how to adpat to a new size, for example, my image size is 20050

这项目基于什么环境运行起来

github上的Tensorflow相关项目,有哪个可以直接运用到实际应用中的?

目前急切想实现Tensorflow的 实际应用和运用?
求推荐,文档全,基本能顺利跑起来的

AttributeError: 'module' object has no attribute 'load_data_1char'

I try your code, but encounter an error while execute softmax_with_log.py. any help?
thanks

[sumarsono@mesin-arch captcha-tensorflow]$ python2 softmax_with_log.py 
Traceback (most recent call last):
  File "softmax_with_log.py", line 115, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/home/sumarsono/captcha-tensorflow/virt/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "softmax_with_log.py", line 37, in main
    train_data, test_data = input_data.load_data_1char(FLAGS.data_dir)
AttributeError: 'module' object has no attribute 'load_data_1char'

TypeError: 'float' object cannot be interpreted as an integer

Nice project. Thanks for sharing. Having problem though. Cloned repo. Did a pip install -r requirements.txt. Tried to run gen_captcha.py and I get a TypeError.

I uncommented the tensorflow=2.1.4 line in the requirements.txt file and set it to 2.8.4 since 2.1.4 was not found and the earliest version of tensroflow was 2.8.4.

My env:
MacOS Monteray v12.6
Python 3.10.7

(.env) ➜  captcha-tensorflow git:(master) 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.
Traceback (most recent call last):
  File "/Users/evancarey/prj/captcha-tensorflow/datasets/gen_captcha.py", line 137, in <module>
    gen_dataset()
  File "/Users/evancarey/prj/captcha-tensorflow/datasets/gen_captcha.py", line 80, in gen_dataset
    _gen_captcha(build_file_path('train'), num_per_image, n_epoch, width, height, choices=choices, max_images_count=max_images_count)
  File "/Users/evancarey/prj/captcha-tensorflow/datasets/gen_captcha.py", line 48, in _gen_captcha
    image.write(captcha, fn)
  File "/Users/evancarey/prj/captcha-tensorflow/.env/lib/python3.10/site-packages/captcha/image.py", line 58, in write
    im = self.generate_image(chars)
  File "/Users/evancarey/prj/captcha-tensorflow/.env/lib/python3.10/site-packages/captcha/image.py", line 228, in generate_image
    im = self.create_captcha_image(chars, color, background)
  File "/Users/evancarey/prj/captcha-tensorflow/.env/lib/python3.10/site-packages/captcha/image.py", line 212, in create_captcha_image
    mask = im.convert('L').point(table)
  File "/Users/evancarey/prj/captcha-tensorflow/.env/lib/python3.10/site-packages/PIL/Image.py", line 1651, in point
    return self._new(self.im.point(lut, mode))
TypeError: 'float' object cannot be interpreted as an integer
(.env) ➜  captcha-tensorflow git:(master)

conv_captcha.py里是只对验证码一个字符进行识别?

    # forward prop
    predict = tf.argmax(y_conv, axis=1)
    expect = tf.argmax(y_, axis=1)

    # evaluate accuracy
    with tf.name_scope('evaluate_accuracy'):
        correct_prediction = tf.equal(predict, expect)
        accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
        variable_summaries(accuracy)

如果要改成识别四个字符的验证码,应该怎么改呢

TypeError: run() takes no arguments (2 given)

$ python simple_softmax.py images/char-1-epoch-2000/

Traceback (most recent call last):
File "simple_softmax.py", line 70, in
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
TypeError: run() takes no arguments (2 given)

Forced exit task while generating the dataset

I tried to generate datasets with 6 letters as follow:

!python3 datasets/gen_captcha.py -dul --npi 6 -n 1 -c 10000 --data_dir ./gdrive/MyDrive/Teledrop-Datasets/

But it turns that the process in google colab exited automatically, because of the usage of the RAM. Is there any way to limit the RAM usage?

How do I test the model in tensorflow.js (node-js)?

def format_y(y):
    return ''.join(map(lambda x: chr(int(x)), y))

def predict(image_path):
    im = Image.open(image_path)
    # im = im.resize((H, W))
    im = np.array(im) / 255.0
    im = np.array(im)
    
    y_pred = model.predict(np.array([im]))
    y_pred = tf.math.argmax(y_pred, axis=-1)
    
    print('predict: %s' % format_y(y_pred[0]))
    plt.imshow(im)

Im struggling to input the image in tensorflowjs, it always throw error ValueError: Error when checking model : the Array of Tensors that you are passing to your model is not the size the the model expected model expected. Expected to see 1 Tensor(s), but instead got 0 Tensors(s).

After Training

What command do you run after you've trained it to test it on the actual image that i'm trying to solve.

ok, i run it, what next?

What I can to do to solve my image?

I have image and need get string to resolve captcha, where is code?

Is possible to tell what is format of data to train and test?
filename is only 'string'_some.png
some will be everything?

testing accuracy problem

image
I just follow as Tutorials for TensorFlow Beginners.But I get the result as testing accuracy = 76.48% which is too low compared with yours(testing accuracy = 91.05%).

I hope to hear from you.
Thank you very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.