[OpenR8 solution] IntegerList_Caffe_FC (Digital Rule Training with Caffe Full Connection Layer)
  1. Chapter1: IntegerList_Caffe_FC

 

This IntegerList_Caffe_FC is a deep learning Caffe framework that uses a multi-layer network to train the model and then test it through the trained model. This time, we want the model to learn the relationship between numbers, if the input six numbers are in order x1, x2, x3, y1, y2, y3, if x1+x2+x3 > y1+y2+y3, then output 1 On the contrary, it outputs 0. That is, the model must be able to learn a series of six numbers divided into the first three numbers, the last three numbers, a total of two groups, and the output is dependent on the comparison of the two sets of numbers. See Fig. 1.

 

First, we need to prepare the training and testing data, and then through the OpenR8 three flow files, the training and testing can be completed in sequence. Details are described in the following sections.

 

Fig. 1. Model training and testing.png

Fig. 1. Model training and testing.

 

 

  1. Chapter2: Step1: Pre-processing - preparation data

 

  1. purpose:

Prepare data for the model to learn and test the accuracy of the model.

  1. Introduction:
  2. Prepare to test and train two data files. The file is placed in the/solution/IntegerList_Caffe_FC/data folder with the file name extra_test0.txt (training) and extra_test1.txt (test). See Fig. 2.

Input: inputA, oututB

inputA = integer 1, integer 2, integer 3, integer 4, integer 5, integer 6

outputB = label.

The label is defined as

擷取.png

 

 

See Fig. 3.

  1. Note: If you want to modify the input of a few numbers, open the solution/IntegerList_Caffe_FC/data/deploy.prototxt file. Please find input_shape {dim: 1 dim: 6} in the file and change the “dim: 6” 6 to enter a few numbers.

 

Fig. 2. Prepare the data file name and location.png

Fig. 2. Prepare the data file name and location.

 

Fig. 3. Prepare the data.png

Fig. 3. Prepare the data.

 

 

 

 

  1. Chapter3: Step2: Pre-processing - 1_create_lmdb

 

  1. Purpose:

Convert the prepared file into the lmdb file needed for the follow-up training and test model.

  1. Instructions for use:

Please “Double-click R8.exe” => click “File” =>”Open” => “IntegerList_Caffe_FC under OpenR8 > solution” => “Load 1_create_lmdb.r6” => Click “Run”=> “Produce lmdb files”。See Fig. 4, Fig. 5, Fig. 6, Fig. 7, Fig. 8, Fig. 9.

For any questions about opening the software to the loading solution, please refer to the [OpenR8 Manual].

 

Fig. 4. R8.png

Fig. 4. R8.exe.

 

Fig. 5. File Open.png

Fig. 5. File => Open.

 

Fig. 6. Select 1_create_lmdb.flow.png

Fig. 6. Select 1_create_lmdb.flow.

 

Fig. 7. Load 1_annoset_to_lmdb.png

Fig. 7. Load 1_annoset_to_lmdb.

 

Fig. 8. Run.png

Fig. 8. Run.

 

Fig. 9. Produce lmdb files.png

Fig. 9. Produce lmdb files.

 

  1. Process file parameter description

This is the path to set the input file and the path to the output lmdb. The following is a description of each process sequence for this flow file. From top to bottom, there are:

(1) Caffe_Init: Caffe frame initialization.

(2) File_DeleteDir(Fig. 10): When the old lmdb archive folder exists in the folder, the old file needs to be removed before starting to generate a new lmdb. (for training)

As shown in Fig. 10,click【File_DeleteDir】=>【dirName’s Edit】=>【Value】,value【data/trainval_lmdb/】is the lmdb folder.

 

Fig. 10. File_DeleteDir.png

Fig. 10. File_DeleteDir.

 

(3) Caffe_IntegerList_CreateTrainData(Fig. 11): Produce lmdb file.(for training)

 

Fig. 11. Caffe_IntegerList_CreateTrainData.png

Fig. 11. Caffe_IntegerList_CreateTrainData.

 

(4) The last two【File_DeleteDir】and【Caffe_IntegerList_CreateTrainData】: In order to generate the lmdb for the test model, the setting method is as described above to generate the trained lmdb.

 

 

  1. Chapter4: Step3: training model - train

 

  1. Purpose:

After the pre-preparation data is completed, the training model begins.

  1. Instructions for use:

Open and load the [2_train] file using OpenR8. Press [Run] to start training the model. This step takes a little while to wait for the program to build the model. See Fig. 12, Fig. 13.

When this run is completed, a trained model will be generated, and its model file will be generated and placed, as shown in Fig. 14.

Path: OpenR8/solution/IntegerList_Caffe_FC/data/

File name 1: snapshot_iter_number of iterations.Caffemodel

File name 2: snapshot_iter_number of iterations. Solverstate

*If it appears after running: ERROR! No GPU! Please set the GPU variable to be empty. If the device does not support GPU, change the GPU in the [Caffe_Train] function from [all] to [].

 

Fig. 12. Open 2_train.png

Fig. 12. Open 2_train.

 

Fig. 13. Run 2_train and its running process.png

Fig. 13. Run 2_train and its running process.

 

Fig. 14. After training the model is generated.png

Fig. 14. After training the model is generated.

 

  1. 2_train process introduction:

(1) Caffe_Init: Caffe frame initialization.

(2) Caffe_Train:

【CaffeObject】Select the previous initialization settings.

【GPU】Whether the device used to train the model needs to use GPU acceleration, if it is, change the value to True; otherwise, change it to False. (If yes, please confirm if the device has a GPU)

【SolverPath】The main parameters. This is the input file solver.prototxt required for Caffe training. The file contains the number of training iterations, training parameters, and a list of samples. See Fig. 15, Fig. 16.

【continueTrainModelPath】The model that was trained before continuing continues to train. Fill in the value of the model path to be continuously trained. The model extension must be “.solverstate”.

 

Fig. 15. 2_train flow - caffe_Train.png

Fig. 15. 2_train flow - caffe_Train.

 

Fig. 16. solver.prototxt content.png

Fig. 16. solver.prototxt content.

 

 

  1. Chapter5: Step4: Test a trained model - inference

 

  1. Purpose:

Test the trained model.

  1. Instructions for use:

Open [3_inference] with OpenR8 and load the file. See Fig. 17.

Click [Caffe_IntegerList_Inference] => [inputList Edit] => [value needs to fill in the value to be tested] => click [Run] => to get the result. See Fig. 18, Fig. 19.

 

Fig. 17. 3_inference.png

Fig. 17. 3_inference.

 

Fig. 18. 3_inference enter test data.png

Fig. 18. 3_inference enter test data.

 

Fig. 19. 3_inference result.png

Fig. 19. 3_inference result.

 

  1. Introduction to the process content

(1) Caffe_Init: Caffe frame initialization.

(2) Caffe_XOR_ReadNet

【caffeObject】

【GPU】Whether the device used to train the model needs to use GPU acceleration, if it is, change the value to True; otherwise, change it to False. (If yes, please confirm if the device has a GPU)

【deployPath】Read the network structure model. (datadeploy.prototxt)

【caffeModelPath】Read the trained model (the file name is .caffemodel)

(3) Caffe_IntegerList_Inference

【caffeObject】

【outputResult】Output the result. That is, the result of the input content is judged by the model.

【inputResult】Enter what you want to test.

【classNumber】What kind of results are divided into categories.

(4) Print: Display in the dos window Output =

(5) Println: The output is displayed in the dos window.

 

 


Recommended Article

1.
OpenR8 Community Edition - AI Software for Everyone (Free Download)