AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Network.compute() is giving same output for any input

The forum is to discuss topics from different artificial intelligence areas, like neural networks, genetic algorithms, machine learning, etc.

Network.compute() is giving same output for any input

Postby thehoneymad » Sat Mar 17, 2012 2:35 pm

First of all, thanks andrew for the OCR tutorial.

I did a silly thing like this below just to check the ANN.

But it is giving me same output for any input. Could you please help me? I have read the other topics about mapping the values between [-1, 1] and my values are mapped so. Please help me.

Code: Select all
namespace SimpleOCR
{
    class Program
    {
        public double[] getinput(Bitmap image)
        {

           
            int increment = 0;
            int noOfElements = image.Width * image.Height;
            Console.WriteLine("Number of element is" + noOfElements);
            int height = image.Height;
            int width = image.Width;

            double[] finalArray = new double[noOfElements];

            Color[][] ColorMatrix = new Color[height][];

            for (int i = 0; i < image.Height; i++)
            {
                ColorMatrix[i] = new Color[width];
                for (int j = 0; j < image.Width; j++)
                {
                    ColorMatrix[i][j] = image.GetPixel(j, i);
                    Color c = ColorMatrix[i][j];

                    if (c.R < 191 && c.B < 191 && c.G < 191)
                    {
                        finalArray[increment] = 0.5f;
                        increment++;
                    }
                    else
                    {

                        finalArray[increment] = -0.5f;
                        increment++;
                    }
                }

            }

            return finalArray;

        }

        public double[][] getoutput()
        {
            double[][] outputPattern=new double[2][];
           

            for (int i = 0; i < 2; i++)
            {
                double[] ouput = new double[36*36];

                for (int j = 0; j < 36*36; j++)
                {
                    ouput[j] = -0.5;
                }

                outputPattern[i] = ouput;
                   
               
               
            }

            return outputPattern;

        }



        static void Main(string[] args)
        {
            Program program=new Program();
            Console.Write("here we go");

            Bitmap image1 = new Bitmap(@"D:\C# practice\SimpleOCR\SimpleOCR\Pattern1.jpg");
            Bitmap image2 = new Bitmap(@"D:\C# practice\SimpleOCR\SimpleOCR\Pattern2.jpg");
           
         
            double[] inputPattern1 = program.getinput(image1);
            double[] inputPattern2 = program.getinput(image2);
            double[][] outputPattern = program.getoutput();
            outputPattern[0][0] = 0.5;
            outputPattern[1][5] = 0.5;


            double[][] input = new double[][] { inputPattern1, inputPattern2 };

            int patterns=2;
            int patternSize=36*36;

           
            ActivationNetwork network = new ActivationNetwork(new BipolarSigmoidFunction(2.0f), patternSize,patterns,patterns);

           

            BackPropagationLearning teacher = new BackPropagationLearning(network);
           
            teacher.Momentum = 0.1f;
            teacher.LearningRate = 0.5f;

            Console.WriteLine("Here is the input patterns");

            for (int i = 1; i <= 36*36; i++)
            {
               if(inputPattern1[i]==0.5)
               {
                    Console.WriteLine("the first index is " + i);
                   break;
               }
            }

                       
            while (true)
            {
                double error = teacher.RunEpoch(input, outputPattern);
                if (error < 0.9)
                    break;
                else
                    Console.WriteLine("Error Level: "+error.ToString());
            }

            double[] inputNew = inputPattern1;
            double[] inputNew2 = inputPattern2;

           
            double[] RealOutput = network.Compute(inputPattern1);
            double[] RealOutput2 = network.Compute(inputPattern2);
       
             

                   
        }
    }
}
thehoneymad
 
Posts: 1
Joined: Sat Mar 17, 2012 2:27 pm



Return to Artificial Intelligence

cron