Home > Tutorial > 5.Artificial neural network

Artificial neural network

 


Example 2:

Reconstruct 2-dimensional color space after training neural network using 3 points of color value as shown in the following image.

 

Point #  X Y Red channel (0~255) Green channel (0~255) Blue channel (0~255)
1 0.5 0.1 255 0 0
2 0.1 0.9 0 255 0
3 0.9 0.9 0 0 255

where X and Y mean geometrical location of each point.

For reference, 24 bit color consists of red, green, and blue channels from 0 to 255

 

 

1. First of all, setup neural network topology.

Click on  'Artificial neural network' under Menu > Tool

There are 2 input variables such as X, Y and 3 output variables such as Red, Green, Blue.

 

 

2. Prepare training pattern

Since every input or output values should have values less than 1, color channel value (0~255) will be normalized to be 1 simply dividing maximum number (255).

For simplicity, a user can use Excel. Make the following table and then copy the table to clipboard!!

 

 

3. To import the excel table, click on the 'Training pattern' button and then click on the 'Paste all columns' button. You can see the imported table in the window.

 

 

4. Start training by clicking on 'Start training' button. It will take about 20 seconds.

  To check regression result, click on the 'Recall' button. You will se the new window titled 'Neural Network - Recalling Pattern'

 

 

5. When training is completed, save it by clicking on the 'Save Network' button.

   File name is 'Sample 2DColorMap - Trained network.vgn'

 

6. Develop script code and execute the code

  Click on 'Module Library' under Menu>Tool.

  Then add new module and finally click on 'Test run' button to execute the code.

 

VBScript source code

Function Main()

 

   '---- Parameters -------------------

   ResolutionSize=5

   ViewPortSize=350

 

 

   '---- Define Canvas ------------------------

   Call CustomUI.Define_Canvas(ViewPortSize,ViewPortSize)

   Call CustomUI.Clear_Canvas

   CustomUI.Form_BringToFront

   CustomUI.Form_Caption="2D color mapping using artificial neural network"

 

 

   '--- Load trained neural network map ---------------

   Call NeuralNet.OpenNN_Once("Sample 2DColorMap - Trained network.vgn")

 

 

   '---- Draw 2D map ----------------------------------------------

  For y= 0 to ViewPortSize step ResolutionSize

     For x=0 to ViewPortSize step ResolutionSize

 

         'Assign inputs

         NeuralNet.InputData(1)=x/ViewPortSize

         NeuralNet.InputData(2)=y/ViewPortSize

 

         'Predict

         Call NeuralNet.PredictNN()

 

         'Read outputs

         Red=NeuralNet.OutputData(1)*255

         Green=NeuralNet.OutputData(2)*255

         Blue=NeuralNet.OutputData(3)*255

 

        'Set fill color and draw rectangle

        Call CustomUI.Set_FillColor_byRGB(Red,Green,Blue)

        Call CustomUI.FillRectangle(x,y,ResolutionSize,ResolutionSize)

     Next

 Next   

 

   '--- Finalize CustomUI -----------------

   CustomUI.Make_Clone

 

End Function