Exemplo n.º 1
0
 /// <summary>Creates an instance of the <code>ConvolutionalNN</code> class.</summary>
 /// <param name="firstPart">The first part of the convolutional neural network.</param>
 /// <param name="fnn">The second part of the convolutional neural network.</param>
 /// <param name="createIO">Whether the input image and the output array of the network are to be created.</param>
 public ConvolutionalNN(PurelyConvolutionalNN firstPart, FeedForwardNN fnn, bool createIO = true)
 {
     this.firstPart  = firstPart;
     this.i2a        = new ImageToArray(firstPart.OutputDepth, firstPart.OutputWidth, firstPart.OutputHeight, false);
     this.fnn        = fnn;
     this.errorArray = Backbone.CreateArray <float>(firstPart.OutputDepth * firstPart.OutputWidth * firstPart.OutputHeight);
     this.errorImage = new Image(this.firstPart.OutputDepth, this.firstPart.OutputWidth, this.firstPart.OutputHeight);
     if (createIO)
     {
         this.SetInputGetOutput(new Image(firstPart.InputDepth, firstPart.InputWidth, firstPart.InputHeight));
     }
     this.siameseID = new object();
 }
Exemplo n.º 2
0
 /// <summary>Creates an instance of the <code>DeConvolutionalNN</code> class.</summary>
 /// <param name="firstPart">First part of the network.</param>
 /// <param name="cnn">Second part of the network.</param>
 /// <param name="createIO">Whether the input array and the output image of the netwok are to be created.</param>
 public DeConvolutionalNN(FeedForwardNN firstPart, PurelyConvolutionalNN cnn, bool createIO = true)
 {
     this.firstPart       = firstPart;
     this.a2i             = new ArrayToImage(cnn.InputDepth, cnn.InputWidth, cnn.InputHeight, false);
     this.cnn             = cnn;
     this.errorArray      = Backbone.CreateArray <float>(cnn.InputDepth * cnn.InputWidth * cnn.InputHeight);
     this.errorImage      = new Image(cnn.InputDepth, cnn.InputWidth, cnn.InputHeight);
     this.layersConnected = false;
     if (createIO)
     {
         this.SetInputGetOutput(Backbone.CreateArray <float>(firstPart.InputSize));
     }
     this.siameseID = new object();
 }
Exemplo n.º 3
0
        public PopulationController(FeedForwardNN nn, int PopulationCount)
        {
            if (PopulationCount < 2)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Population count must be more than 2");
                Console.ForegroundColor = ConsoleColor.White;
            }

            this.PopulationCount = PopulationCount;
            this.descriptor      = nn.Descriptor;

            Population = new PopulationUnit[PopulationCount];

            for (int i = 0; i < PopulationCount; i++)
            {
                Population[i] = new PopulationUnit(nn);
            }
        }
Exemplo n.º 4
0
 /// <summary>Either creates a siamese of the given <code>ConvolutionalNN</code> instance or clones it.</summary>
 /// <param name="original">The original instance to be created a siamese of or cloned.</param>
 /// <param name="siamese"><code>true</code> if a siamese is to be created, <code>false</code> otherwise.</param>
 protected ConvolutionalNN(ConvolutionalNN original, bool siamese)
 {
     this.errorArray      = Backbone.CreateArray <float>(firstPart.OutputDepth * firstPart.OutputWidth * firstPart.OutputHeight);
     this.errorImage      = new Image(this.firstPart.OutputDepth, this.firstPart.OutputWidth, this.firstPart.OutputHeight);
     this.layersConnected = false;
     if (siamese)
     {
         this.firstPart = (PurelyConvolutionalNN)original.CreateSiamese();
         this.i2a       = (ImageToArray)original.i2a.CreateSiamese();
         this.fnn       = (FeedForwardNN)original.fnn.CreateSiamese();
         this.siameseID = original.SiameseID;
     }
     else
     {
         this.firstPart = (PurelyConvolutionalNN)original.firstPart.Clone();
         this.i2a       = (ImageToArray)original.i2a.Clone();
         this.fnn       = (FeedForwardNN)original.fnn.Clone();
         this.siameseID = new object();
     }
 }
Exemplo n.º 5
0
 /// <summary>Either creates a siamese or clones the given <code>DeConvolutionalNN</code> instance.</summary>
 /// <param name="original">The original instance to be created a siamese of or cloned.</param>
 /// <param name="siamese"><code>true</code> if a siamese is to be created, <code>false</code> if a clone is.</param>
 protected DeConvolutionalNN(DeConvolutionalNN original, bool siamese)
 {
     this.errorArray      = Backbone.CreateArray <float>(original.cnn.InputDepth * original.cnn.InputWidth * original.cnn.InputHeight);
     this.errorImage      = new Image(original.cnn.InputDepth, original.cnn.InputWidth, original.cnn.InputHeight);
     this.layersConnected = false;
     if (siamese)
     {
         this.firstPart = (FeedForwardNN)original.firstPart.CreateSiamese();
         this.a2i       = (ArrayToImage)original.a2i.CreateSiamese();
         this.cnn       = (PurelyConvolutionalNN)original.cnn.CreateSiamese();
         this.siameseID = original.SiameseID;
     }
     else
     {
         this.firstPart = (FeedForwardNN)original.firstPart.Clone();
         this.a2i       = (ArrayToImage)original.a2i.Clone();
         this.cnn       = (PurelyConvolutionalNN)original.cnn.Clone();
         this.siameseID = new object();
     }
 }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            FeedForwardNN nn = new FeedForwardNN(new FeedForwardNNDescriptor());

            nn.ReadWeights("mnist.xml");

            float[][] testData    = new float[10000][];
            float[][] testAnswers = new float[10000][];

            int index = 0;

            using (StreamReader sr = new StreamReader(@"C:\Users\Dima\source\repos\NeuralNet1\NeuralNetRun\bin\Debug\mnist_test.csv", System.Text.Encoding.Default))
            {
                string line;

                while ((line = sr.ReadLine()) != null)
                {
                    string[] array = line.Split(',');
                    float[]  data  = new float[784];
                    int      label = Convert.ToInt32(array[0]);

                    for (int i = 0; i < 784; i++)
                    {
                        data[i] = Normalize.Minimax(Convert.ToInt32(array[i + 1]), 0, 255);
                    }

                    float[] answer = new float[10];
                    answer[label] = 1;

                    testData[index]    = data;
                    testAnswers[index] = answer;
                    index++;
                }
            }

            Trainer trainer = new Trainer(ref nn);

            trainer.TrainBackPropogation(1, 1, 0.0001f, 0.3f, testData, new float[][] { }, testAnswers, new float[][] { });

            float[][] o = new float[3][];

            o[0] = nn.Run(testData[0]);
            o[1] = nn.Run(testData[1]);
            o[2] = nn.Run(testData[2]);

            int answer0;
            int answer1;
            int answer2;

            float max = 0;

            for (int i = 0; i < o[0].Length; i++)
            {
                if (o[0][i] > max)
                {
                    answer0 = i;
                    max     = o[0][i];
                }
            }

            max = 0;

            for (int i = 0; i < o[0].Length; i++)
            {
                if (o[1][i] > max)
                {
                    answer1 = i;
                    max     = o[1][i];
                }
            }

            max = 0;

            for (int i = 0; i < o[0].Length; i++)
            {
                if (o[2][i] > max)
                {
                    answer2 = i;
                    max     = o[2][i];
                }
            }
        }
Exemplo n.º 7
0
        public PopulationUnit(FeedForwardNN NN)
        {
            this.NN = NN;

            Outputs = new float[NN.Descriptor.LayersData[NN.Descriptor.LayersData.Length - 1]];
        }
Exemplo n.º 8
0
 public Trainer(ref FeedForwardNN NN)
 {
     NeuralNet = NN;
 }