GOCR to Neural Nets Pt 2
As per usual these posts don’t go as smoothly as I would like. The idea was to use FANN for PHP to make a simple neural network that would work easily. Hahahaha. You might think I make this stuff up as I go along. Oh wait. I do.
Anyway FANN requires PEAR to be installed and I figured that it’d be much simpler than installing PEAR modules to find something that was completely PHP to do the job. I did that. However.
1. It’s slow.
Ok so it’s slow. We can live with that right? I mean we’ve got some time.
2. It’s slow.
Ok it really is slow, and I’m getting impatient.
3. It’s painfully slow.
PHP sucks for some things. I do like C’s direct memory access. On the plus side this little neural net class is so simple and easy to understand.
Anyway I went ahead and I fitted all my modules together around this PHP neural net and I walked away whilst my computer attempted to learn the alphabet at a ridiculously slow pace. 900 captchas later I give it up.
The neural net does sort of work now for quite a few characters. Although I did notice a character failed to segment properly which set the learning back a bit. A lot of the characters it fails on are things like producing P’s for R’s or vice versa. So you can understand where the problem lies.
I won’t post code because there’s a fair bit spread over a few modules. nnbreak.php is the main module and must be run from the command line. Like this:
php nnbreak.php captcha.jpg answer.txt train=1/0
1 means train the network using the answer stored in answer.txt. 0 means guess what the captcha is in captcha.jpg, which will ignore answer.txt but answer.txt must still be included (although it can be blank or not exist etc).
So analysis… Here’s how it works roughly:
Allocate memory for the neural network, and load in previous neuron weight values
Extract the letters as said in that post about extracting letters.
Convert the letters into a 10×10 matrix of averaged values, maximum being 1.0
Loop through each letter and send the matrix of values to the input neurons
Check the output neurons
Possibly teach the network the right answer using back propogation.
We can tweak a lot of things such as the number of neurons in each layer and the size of the matrix. I did mess with the default backpropogation teaching speed because it didn’t seem to be learning fast enough to me
. I’m guessing that has some drawbacks to it but I’m not sure exactly what they are. In this line the 0.5 is the learning speed which has been moved up from the default 0.1:
$nn = new nn(3, $layer_structure,1,0.5,0.9);
Now if anyone happens to train the network to recognise all of the letters properly send me the file so I can claim it as my own and pretend I did it all perfectly
. J/k. Seriously though I do think it should eventually learn all the letters properly it’s just taking a long time.
In conclusion. I don’t trust neural networks they do too much stuff that I don’t know about. I’m betting that robot from the Terminator was probably built from neural nets.
The code to guess a captcha using neural nets - Already populated with some weights so it sort of works



March 30th, 2008 at 7:18 pm
I think you are over complicating things a tad… Im no expert at breaking capchas, in fact i never even thought of trying until i read your phpbb2 capcha post..
Ive since got to work using only php and the gd library to clean and crop the images and using a php class to solve them..
admittadly im only working on the phpbb2 captcha but ive got it up to 91% success rate and its pretty quick…
anyway.. keep the posts coming your approaches are very interesting.. like i said im new to this stuff so all info is good info
March 30th, 2008 at 7:20 pm
oh yeah.. and you are a better writer than you think you are!!
March 31st, 2008 at 4:29 am
I most definitely am over complicating things. You could have just used GOCR or phpOCR and got the same results. It’s just interesting to learn loads of different techniques.
You might find that neural nets come in more useful somewhere else… You never know.
I was actually thinking about neuro-evolution, and evolutionary programming the other day. And it crossed my mind that the two are very similar. In many ways the neuron weights are like a statement of code. I think you can do more with a neural network than you could imagine, it’s just that initial training it and getting the correct number of layers so it can store enough information about the pattern but not so much it takes a million years to train. Hmmm…
March 31st, 2008 at 6:20 am
Hmm.. He is a better writer. I agree with that.
March 31st, 2008 at 1:11 pm
Inspired by your first post, I tried this ANN coded in PHP entirely: http://www.tremani.nl/open-source/neural-network/
I don’t know how the speed compares to other ANNs, but it’s pretty simple to use once, you know what ANNs are
April 1st, 2008 at 9:48 pm
Gah, PHP is such a pain in the butt to learn lol, so I think I’ll stick with my html for now. But you’re definately not a bad writer.
April 16th, 2008 at 3:22 pm
[…] The first entry is the filename, and it can literally be any pbm/png file. The second entry is the correct letter. That simple. All we have to do is rip the letters out and put them in the same directory. Unfortunately I haven’t got the script cleaned in a nice easy to use format to just download, but I’ll post what I used to build my custom database very quickly. I use the retrieve.php include which is somewhere on this site. I should be more organised. I think it’s here. […]
June 4th, 2008 at 2:58 am
Just wondering when training … does it have to be done on different captchas or just one? I have it working on my training captcha, but not even close on another with out training. Seems once I start trainging on multiple captchas, when in 0 mode it takes forever. Any ideas would be appreciated thanks.