Friday, October 21, 2011

A 7-Segment Display Recognizing Neural Network

Among other things, I teach Robotics to ECE students at Galileo University, Guatemala. I got to teach this class after 3 years of learning so much as a teaching assistant since 2005. Back then, in order to learn about artificial neural networks, I made a project that was assigned to our students, because I wanted to be able to answer their questions.


OK, so I made this application in Borland C++ Builder 6 back in 2005. The specific type of neural networks implemented in this project are Feed Forward Neural Networks using the Back Propagation Method, the ones described in generation5.org. By the way, if you want to learn about ANNs, I highly recommend the tutorials by James Matthews and Samuel Hsiung, which can be found at generation5.org.

This is the topology for the Neural Networks implemented. The perceptrons use the sigmoid activation function.

So this application is a Neural Network trained to recognize all 10 digits in a 7 segment display. The user enters the pattern using 7 buttons. It's supposed to guess the meaning of a received pattern, as would be required by an intelligent system (say, a robot) observing a 7 segment display, which is a very cool computer vision application.

You may argue that hard-coding the 10 digits would do the trick. True, but the real value in a neural network is that by means of teaching the system how the numbers look, you are giving it the chance to make guesses for incomplete or weird patterns, which would be the case if the observed display has one or more damaged segments. This is a very reduced application of the same principle used in OCR.

I made 2 implementations to solve this problem:
  • Single-Output ANN: Outputs an integer (0-9) corresponding to the digit concluded by the ANN given the input.
  • 7-Output ANN: Outputs an array of 7 boolean variables that represent each segment. This also works as an "Auto Complete" feature. This implementation has the disadvantage of being able to come up with non-numeric patterns (A, -1, L, E and so on). 
 The single output version of the application

In both applications, the user sets the following parameters (please go to generation5.org if you're not familiar with the terms):
    • 3 or 4 layered Neural Network (1 or 2 hidden layers).
    • How many neurons to use per layer (first MUST be 7 and last MUST be 7 or 1).
    • Training Goal: Train until a specific error % is reached or Train a specific number of iterations.
    • Eta, the learning rate.
    • The Bias.
    • The Goal (Error or Iterations).
Go ahead and try it. Sorry, they're Windows apps. I HAVE to start writing online code :(
The source code of the library I made is included in case you want to fiddle with it.

Artificial Intelligence 
I like Artificial Intelligence very much. I teach some of it at my Robotics class, but I never received formal education on it.

I recently enrolled in the online version of Standford's CS221 AI class to learn more. So far, it's been OK: relatively easy to understand, not prohibitively time consuming, sometimes it's been challenging, but most importantly: it's been fun.

Again, for practical stuff and to learn lots about AI, go to generation5.org

3 comments:

  1. Would you mind share your source code?
    Te importaria compartir el codigo fuente?

    ReplyDelete
    Replies
    1. the link that says "Go ahead and try it." is a zip file with two .exe and a source file named neural.h
      the original code is for borland c++ builder v6. email me if interested.

      Delete