GithubHelp home page GithubHelp logo

sickfox / cnn_keras_captcha Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scnuhealthy/cnn_keras_captcha

0.0 2.0 0.0 91.43 MB

This a deep learning program for recognizing the captcha using keras with python.

Python 61.54% Jupyter Notebook 38.46%

cnn_keras_captcha's Introduction

#What is the capthca Captcha is image generated by chars randomly and proper voice to avoid the attack from the robot.
9_9530
The picture above is a common captcha,including four digital numbers.
#How to recognize the captcha There three main methods:

  • find the loopholes of the captcha
  • spilt the captcha into single char, and then recognize the chars
  • regard the captha as the whole, and recognzie it directly

Tesseract OCR and OpenCV use the second method. But the captcha is more and more complex now. There is a common phenomenon that the chars in the captcha interlace with one another, so the second method gets a low accuracy. This program focuses on the third method.

#Generate the captcha to train Acquire massive capthca by hunman is unrealistic. Fortunately, we can easily generate the captcha by the python package captcha.See the get_captcha.py in details.

#Build the cnn model I build the network with keras, using the theano backend. I think use keras raher than theano to code is much more convenient.
The network includes three convolution layers and two full-connected layers. Owing to CNN needs a large amount of samples to train, with the limitation of time and resources, I only use digital number as the char set of the captcha. So output of the model has 410 numbers, while is will have 462 numbers if the char set includes ppercase and lowercase letters.

# 3 conv layer
model.add(Convolution2D(nb_filters1, kernel_size[0], kernel_size[1],
                        border_mode='valid',
                        input_shape=input_shape))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Dropout(0.25))

model.add(Convolution2D(nb_filters2, kernel_size[0], kernel_size[1]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Dropout(0.25))

model.add(Convolution2D(nb_filters3, kernel_size[0], kernel_size[1]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Dropout(0.25))

# Fully connected layer
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Dense(MAX_CAPTCHA*CHAR_SET_LEN))
model.add(Activation('softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='adadelta',
              metrics=['accuracy'])

#The training result
I use 18000 training samples and 6000 test samples. After 64 epochs of training, the model obtains the correct rate of 63.9% on the test data.There is part of the result following: ย 

test_result
4063
7229
We can see the program successfully recognize "4063" , but fail "7229". The chat '7' and '2' are similar, maybe we need more data to train.

#Try yourself ##Environment My Environment is Windows10 with Anaconda. Anaconda should install the package theano,keras and capthca. ##Run my program You can run my program by downloading my code(get_captcha.py, load_data.py and get_captcha.py), running get_captcha.py(create path 'F:\captcha\data' first) and running recognize_captcha.py. Program get_captcha.py will generate the captchas and Program recognize_captcha.py will build the model. I also provide training model file(my_model.json and my_model_weights.h5), you can load it directly and recognize the captcha around the corner.

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.