Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Image Recognition with Neural Networks

, 30 Oct 2007 CPOL
This article contains a brief description of BackPropagation Artificial Neural Network and its implementation for Image Recognition
backpropagation2_demo.zip
BackPropagation.exe
ICONS
adobe.bmp
mozilla.bmp
ms word.bmp
netbeans.bmp
notepad.bmp
quest.bmp
studio.bmp
Thumbs.db
winamp.bmp
PATTERNS
0.bmp
1.bmp
2.bmp
3.bmp
4.bmp
5.bmp
6.bmp
7.bmp
8.bmp
9.bmp
A.bmp
B.bmp
C.bmp
D.bmp
E.bmp
F.bmp
G.bmp
H.bmp
I.bmp
J.bmp
K.bmp
L.bmp
M.bmp
N.bmp
O.bmp
P.bmp
Q.bmp
R.bmp
S.bmp
T.bmp
Thumbs.db
U.bmp
V.bmp
W.bmp
X.bmp
Y.bmp
Z.bmp
BackPropagation2_src.zip
Properties
Settings.settings
BackPropagation.suo
bin
Debug
06_19_BackPropagation.exe
06_19_BackPropagation.vshost.exe
ICONS
adobe.bmp
mozilla.bmp
ms word.bmp
netbeans.bmp
notepad.bmp
quest.bmp
studio.bmp
Thumbs.db
winamp.bmp
PATTERNS
0.bmp
1.bmp
2.bmp
3.bmp
4.bmp
5.bmp
6.bmp
7.bmp
8.bmp
9.bmp
A.bmp
B.bmp
C.bmp
D.bmp
E.bmp
F.bmp
G.bmp
H.bmp
I.bmp
J.bmp
K.bmp
L.bmp
M.bmp
N.bmp
O.bmp
P.bmp
Q.bmp
R.bmp
S.bmp
T.bmp
Thumbs.db
U.bmp
V.bmp
W.bmp
X.bmp
Y.bmp
Z.bmp
Lib
backpropagation_demo.zip
06_19_BackPropagation.exe
0
0.bmp
Thumbs.db
1
1.bmp
Thumbs.db
2
2.bmp
Thumbs.db
3
3.bmp
Thumbs.db
4
4.bmp
Thumbs.db
5
5.bmp
Thumbs.db
6
6.bmp
Thumbs.db
7
7.bmp
Thumbs.db
8
8.bmp
Thumbs.db
9
9.bmp
Thumbs.db
A
A.bmp
Thumbs.db
B
B.bmp
Thumbs.db
C
C.bmp
Thumbs.db
D
D.bmp
Thumbs.db
E
E.bmp
Thumbs.db
F
F.bmp
Thumbs.db
G
G.bmp
Thumbs.db
H
H.bmp
Thumbs.db
I
I.bmp
Thumbs.db
J
J.bmp
Thumbs.db
K
K.bmp
Thumbs.db
L
L.bmp
Thumbs.db
M
M.bmp
Thumbs.db
N
N.bmp
Thumbs.db
O
O.bmp
Thumbs.db
P
P.bmp
Thumbs.db
Q
Q.bmp
Thumbs.db
R
R.bmp
Thumbs.db
S
S.bmp
Thumbs.db
T
T.bmp
Thumbs.db
Thumbs.db
U
Thumbs.db
U.bmp
V
Thumbs.db
V.bmp
W
Thumbs.db
W.bmp
X
Thumbs.db
X.bmp
Y
Thumbs.db
Y.bmp
Z
Thumbs.db
Z.bmp
Adobe
adobe reader.bmp
Thumbs.db
Mozilla
Thumbs.db
untitled.bmp
NetB
Thumbs.db
untitled6.bmp
NoteP
Thumbs.db
untitled4.bmp
Office
ms word.bmp
Thumbs.db
Printer
Thumbs.db
untitled.bmp
Quest
Thumbs.db
untitled5.bmp
Studio
Thumbs.db
untitled3.bmp
Winamp
Thumbs.db
untitled2.bmp
Winrar
Thumbs.db
untitled.bmp
BackPropagation_src.zip
BackPropagation.suo
06_19_BackPropagation.exe
06_19_BackPropagation.vshost.exe
Adobe
adobe reader.bmp
Thumbs.db
Mozilla
Thumbs.db
untitled.bmp
NetB
Thumbs.db
untitled6.bmp
NoteP
Thumbs.db
untitled4.bmp
Office
ms word.bmp
Thumbs.db
Printer
Thumbs.db
untitled.bmp
Quest
Thumbs.db
untitled5.bmp
Studio
Thumbs.db
untitled3.bmp
Winamp
Thumbs.db
untitled2.bmp
Winrar
Thumbs.db
untitled.bmp
0
0.bmp
Thumbs.db
1
1.bmp
Thumbs.db
2
2.bmp
Thumbs.db
3
3.bmp
Thumbs.db
4
4.bmp
Thumbs.db
5
5.bmp
Thumbs.db
6
6.bmp
Thumbs.db
7
7.bmp
Thumbs.db
8
8.bmp
Thumbs.db
9
9.bmp
Thumbs.db
A
A.bmp
Thumbs.db
B
B.bmp
Thumbs.db
C
C.bmp
Thumbs.db
D
D.bmp
Thumbs.db
E
E.bmp
Thumbs.db
F
F.bmp
Thumbs.db
G
G.bmp
Thumbs.db
H
H.bmp
Thumbs.db
I
I.bmp
Thumbs.db
J
J.bmp
Thumbs.db
K
K.bmp
Thumbs.db
L
L.bmp
Thumbs.db
M
M.bmp
Thumbs.db
N
N.bmp
Thumbs.db
O
O.bmp
Thumbs.db
P
P.bmp
Thumbs.db
Q
Q.bmp
Thumbs.db
R
R.bmp
Thumbs.db
S
S.bmp
Thumbs.db
T
T.bmp
Thumbs.db
Thumbs.db
U
Thumbs.db
U.bmp
V
Thumbs.db
V.bmp
W
Thumbs.db
W.bmp
X
Thumbs.db
X.bmp
Y
Thumbs.db
Y.bmp
Z
Thumbs.db
Z.bmp
Settings.settings
bpsimplified_demo.zip
sample.net
Adobe.bmp
Mozilla.bmp
NBeans.bmp
Npad.bmp
Quest.bmp
VStudio.bmp
Winamp.bmp
Word.bmp
0.bmp
1.bmp
2.bmp
3.bmp
4.bmp
5.bmp
6.bmp
7.bmp
8.bmp
9.bmp
A.bmp
B.bmp
C.bmp
D.bmp
E.bmp
F.bmp
G.bmp
H.bmp
I.bmp
J.bmp
K.bmp
L.bmp
M.bmp
N.bmp
O.bmp
P.bmp
Q.bmp
R.bmp
S.bmp
T.bmp
U.bmp
V.bmp
W.bmp
X.bmp
Y.bmp
Z.bmp
BPSimplified.exe
bpsimplified_src.zip
BPSimplified
bin
Debug
BPSimplified.exe
ICONS
Adobe.bmp
Mozilla.bmp
NBeans.bmp
Npad.bmp
Quest.bmp
VStudio.bmp
Winamp.bmp
Word.bmp
PATTERNS
0.bmp
1.bmp
2.bmp
3.bmp
4.bmp
5.bmp
6.bmp
7.bmp
8.bmp
9.bmp
A.bmp
B.bmp
C.bmp
D.bmp
E.bmp
F.bmp
G.bmp
H.bmp
I.bmp
J.bmp
K.bmp
L.bmp
M.bmp
N.bmp
O.bmp
P.bmp
Q.bmp
R.bmp
S.bmp
T.bmp
U.bmp
V.bmp
W.bmp
X.bmp
Y.bmp
Z.bmp
sample.net
Lib
Properties
Settings.settings
#region Copyright (c), Some Rights Reserved
/*##########################################################################
 * 
 * NeuralNetwork.cs
 * -------------------------------------------------------------------------
 * By
 * Murat FIRAT, September 2007
 * 
 * -------------------------------------------------------------------------
 * Description:
 * Contains Neural Network Class(BP1layer,BP2layer or BP3layer) And
 * Callback To Handle Training Process
 * 
 * -------------------------------------------------------------------------
 ###########################################################################*/
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace BPSimplified.Lib
{    
    class NeuralNetwork<T>
        where T : IComparable<T>
    {
        private IBackPropagation<T> NeuralNet;
        private double maximumError = 1.0;
        private int maximumIteration = 10000;
        Dictionary<T, double[]> TrainingSet;

        public delegate void IterationChangedCallBack(object o, NeuralEventArgs args);
        public event IterationChangedCallBack IterationChanged = null;

        public NeuralNetwork(IBackPropagation<T> IBackPro, Dictionary<T, double[]> trainingSet)
        {
            NeuralNet = IBackPro;
            TrainingSet = trainingSet;
            NeuralNet.InitializeNetwork(TrainingSet);
        }

        public bool Train()
        {
            double currentError = 0;
            int currentIteration = 0;
            NeuralEventArgs Args = new NeuralEventArgs() ;

            do
            {
                currentError = 0;
                foreach (KeyValuePair<T, double[]> p in TrainingSet)
                {
                    NeuralNet.ForwardPropagate(p.Value, p.Key);
                    NeuralNet.BackPropagate();
                    currentError += NeuralNet.GetError();
                }
                
                currentIteration++;

                if (IterationChanged != null && currentIteration % 5 == 0)
                {
                    Args.CurrentError = currentError;
                    Args.CurrentIteration = currentIteration;
                    IterationChanged(this, Args);
                }

            } while (currentError > maximumError && currentIteration < maximumIteration && !Args.Stop);
                        
            if (IterationChanged != null)
            {
                Args.CurrentError = currentError;
                Args.CurrentIteration = currentIteration;
                IterationChanged(this, Args);
            }

            if (currentIteration >= maximumIteration || Args.Stop)   
                return false;//Training Not Successful
            
            return true;
        }

        public void Recognize(double[] Input, ref T MatchedHigh, ref double OutputValueHight,
            ref T MatchedLow, ref double OutputValueLow)
        {
            NeuralNet.Recognize(Input, ref MatchedHigh,ref OutputValueHight,ref MatchedLow,ref OutputValueLow);
        }

        public void SaveNetwork(string path)
        {
            FileStream FS = new FileStream(path, FileMode.Create);
            BinaryFormatter BF = new BinaryFormatter();
            BF.Serialize(FS, NeuralNet);
            FS.Close();
        }

        public void LoadNetwork(string path)
        {
            FileStream FS = new FileStream(path, FileMode.Open);
            BinaryFormatter BF = new BinaryFormatter();
            NeuralNet = (IBackPropagation<T>)BF.Deserialize(FS);
            FS.Close();
        }

        public double MaximumError
        {
            get { return maximumError; }
            set { maximumError = value; }
        }

        public int MaximumIteration
        {
            get { return maximumIteration; }
            set { maximumIteration = value; }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Murat Firat
Software Developer (Senior)
Turkey Turkey
Has BS degree on CS, working as SW engineer at istanbul.

| Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 30 Oct 2007
Article Copyright 2007 by Murat Firat
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid