Git Product home page Git Product logo

captcha_recognize's Introduction

Introduce

Translation: English 中文

image recognition captchas using TensorFlow, no need image segmentation, run on ubuntu 16.04, python 2.7

captchacaptchacaptchacaptchacaptchacaptcha

accuracy 99.7% judged by captcha_eval.py, training size 50000, after 20000 steps captcha generator: https://github.com/lepture/captcha

captchacaptchacaptchacaptchacaptchacaptcha

accuracy 52.1% judged by captcha_eval.py, training size 100000, after 200000 steps captcha generator: https://github.com/Gregwar/CaptchaBundle

Dependence

python 2.7

Anaconda2 4.3.1

https://www.continuum.io/downloads#linux

TensorFlow 1.1

https://github.com/tensorflow/tensorflow

captcha

https://pypi.python.org/pypi/captcha/0.1.1

Usage

1.prepare captchas

put your own captchas in <current_dir>/data/train_data/ for training, <current_dir>/data/valid_data/ for evaluating and <current_dir>/data/test_data/ for recognize testing, images file name must be label_*.jpg or label_*.png and recommend size 128x48. you can also use default generation:

python captcha_gen_default.py

2.convert dataset to tfrecords

the result file will be <current_dir>/data/train.tfrecord and <current_dir>/data/valid.tfrecord

python captcha_records.py

3.training

train and evaluate neural network on CPU or one single GPU

python captcha_train.py

you can also train over multiple GPUs

python captcha_multi_gpu_train.py

4.evaluate

python captcha_eval.py

5.recognize

read captchas from <current_dir>/data/test_data/ for recogition

python captcha_recognize.py

result like this

...
image WFPMX_num552.png recognize ----> 'WFPMX'
image QUDKM_num468.png recognize ----> 'QUDKM'

captcha_recognize's People

Contributors

patricklib 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

captcha_recognize's Issues

Can't apply for dynamic length of captcha

I have got an issue when run the captcha_records.py, the problem is that my captcha length is 6 or 7 characters, so I set CHARS_NUM = 7, when run the captcha_records.py, it shows an error
"IndexError: index 7 is out of bounds for axis 0 with size 7"
How can I apply for dynamic length of captcha?

Thank you very much!

acknowledgment

your code helped me a lot !
so appreciate your fantastic work...
can i send email to you and ask some question about the code in this repository?

training.py Running Time

I used Tensorflow-CPU. The captcha_train.py had run over 3 hours and the step was over 2700, but the loss was between 2.9 and 3. It decreased very slowly. Can you tell me how long did your training.py run? And, doed it stop until the loss reach zero ? THX

TypeError: object of type 'zip' has no len()

Copying the exact error while running captcha_records.py

(tensorenviron) C:\Work\captcha_recognize-master>python captcha_records.py
Looking for images in './data/train_data'

Writing ./data\train.tfrecords
Traceback (most recent call last):
File "captcha_records.py", line 123, in
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "C:\Users\User\AppData\Local\Continuum\anaconda2\envs\tensorenviron\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
_sys.exit(main(argv))
File "captcha_records.py", line 102, in main
conver_to_tfrecords(training_data, TRAIN_FILE)
File "captcha_records.py", line 55, in conver_to_tfrecords
num_examples = len(data_set)
TypeError: object of type 'zip' has no len()

module 'tensorflow' has no attribute 'app'

Hi.
in captcha_records.py stroke 123 it says:
AttributeError: module 'tensorflow' has no attribute 'app'
i changed tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) to tf.compat.v1.run(main=main, argv=[sys.argv[0]] + unparsed)
now it says module 'tensorflow.compat.v1' has no attribute 'run'

Training loss just keep increasing

Model doesnot work. Training loss never stablizes. Here is the proof.

Step 440 run_train: loss = 15.94 (8.119 sec)
Step 450 run_train: loss = 36.65 (8.486 sec)
Step 460 run_train: loss = 102.19 (8.480 sec)
Step 470 run_train: loss = 317.27 (9.262 sec)
Step 480 run_train: loss = 801.44 (8.208 sec)
Step 490 run_train: loss = 2089.72 (7.839 sec)
Step 500 run_train: loss = 5845.62 (7.887 sec)
2017-08-26 13:12:49.057376 Saving in ./captcha_train/captcha
Step 510 run_train: loss = 13428.68 (7.818 sec)
Step 520 run_train: loss = 25587.19 (9.801 sec)
Step 530 run_train: loss = 59853.98 (7.978 sec)
Step 540 run_train: loss = 108795.05 (8.611 sec)
Step 550 run_train: loss = 190373.88 (8.281 sec)
Step 560 run_train: loss = 308137.38 (7.726 sec)

Configuration:
IMAGE_HEIGHT = 65
IMAGE_WIDTH = 190
CHAR_SETS = 'abcdefghijklmnopqrstuvwxyz'
CLASSES_NUM = len(CHAR_SETS)
CHARS_NUM = 8

Facing problem while freezing graph for deployment

I tried freezing the checkpoints with "Reshape_1:0" as an output Tensor, but after converting into ProtoBuffer I am unable to generate an inference from it.

What should be right input and output nodes for the Frozen graph?

training time

When training your model, you use CPU, GPU or multi GPUs? If GPU, what's the version and how long did you take about training your model?

generate

I get this

$python ./captcha_gen_default.py 
>> generate 1000 captchas in ./data/test_data
Traceback (most recent call last):
  File "./captcha_gen_default.py", line 55, in <module>
    gen(FLAGS.test_dir, TEST_SIZE, CHARS_NUM)
  File "./captcha_gen_default.py", line 28, in gen
    for i in xrange(total_size):
NameError: name 'xrange' is not defined

what I can to do?

Substring not found / Index out of bounds

Writing ./data/train.tfrecords
Traceback (most recent call last):
File "captcha_records.py", line 123, in
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "~/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 126, in run
_sys.exit(main(argv))
File "captcha_records.py", line 102, in main
conver_to_tfrecords(training_data, TRAIN_FILE)
File "captcha_records.py", line 62, in conver_to_tfrecords
label_raw = label_to_one_hot(label).tostring()
File "captcha_records.py", line 42, in label_to_one_hot
index.append(CHAR_SETS.index(c))
ValueError: substring not found

Before adding _1 to all of my training captchas I've got this error:

Traceback (most recent call last):
File "captcha_records.py", line 123, in
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "~/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 126, in run
_sys.exit(main(argv))
File "captcha_records.py", line 102, in main
conver_to_tfrecords(training_data, TRAIN_FILE)
File "captcha_records.py", line 62, in conver_to_tfrecords
label_raw = label_to_one_hot(label).tostring()
File "captcha_records.py", line 44, in label_to_one_hot
one_hot_label[one_hot_index] = 1.0
IndexError: index 5 is out of bounds for axis 0 with size 5

python3.6

hi
can you update your python versionto 3.6 ?

载入图片的代码会使图片载入两次

extensions = ['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG']
# ...
for extension in extensions:
     file_glob = os.path.join(image_dir, '*.' + extension)
     file_list.extend(gfile.Glob(file_glob))

在Windows上,后缀大小写不区分,同一张图片会被载入两次:
image

Recognize all images.

Is it possible to make it recognize multiple image sizes different from the training ones? Im having tensor shapes different error while trying with images bigger than train ones.

文章

您好!感谢您的分享,请问关于这个项目您有博客文章或者任何其他形式的理论说明吗?

训练时间

请问我若过用一个cpu来训练需要多长时间,
IMAGE_HEIGHT = 60
IMAGE_WIDTH = 150
CHARS_NUM = 4
准确率能达到多少,因为我想尽快用到,所以比较急,谢谢

can't convert to tfjs model ValueError: Unsupported input_format - output_format pair: tf_saved_model - tfjs_layers_model

I am not able to convert to tfjs model(webmodel) using tensorflowjs_converter
throws the Error msg:
File "/home/shiva/.local/bin/tensorflowjs_converter", line 11, in
sys.exit(main())
File "/home/shiva/.local/lib/python2.7/site-packages/tensorflowjs/converters/converter.py", line 373, in main
(input_format, output_format))
ValueError: Unsupported input_format - output_format pair: tf_saved_model - tfjs_layers_model

terminate called after throwing an instance of 'std::bad_alloc'

Looking for images in './data/test_data'
2018-04-16 15:11:21.166594: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2
./captcha_train/captcha-62400
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted

Resume Training

Based on the code, it seems the main method in the captcha_train.py deletes recursively the training data. For neural networks that take longer to train, it is useful to be able to fine tune the network along the way. Unless I am interpreting the code wrong?

theory

what's the theory? how can you recognize the whole captcha without image segmentation ?

what result mean trainning is finished

the loss is reduce to 0 when step 170 , but it don't stop,
i pressed 'ctrl+c' breaked it, then try to eval and recognize,
but the result of recognize is so bad,

can i break the train when loss equal 0?
or it will finished , i need't do that?

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.