This Image_Classify_ ResNet50_Caffe is using the Caffe framework, ResNet50 network architecture is used to train the model and to classify the images through trained models.
The main process is shown in Fig. 1.
First, we need to prepare the images we want to learn from the model, and divide the images into different folders according to categories.
Then, through the flow file in Image_Classify_ ResNet50_Caffe, the three txt manifest files are automatically generated.In this way, let the model know which files are to be tested for training, and which categories are divided into these files.After completing these pre-processing, execute the training flow file.After the training is completed, test the model that has been trained.
Fig. 1.Image_Classify_ ResNet50_Caffe Image recognition process.
Step 1: Pre-processing – Prepare the training image
For this solution, we want the model to identify the age of the portrait in the image, so we need to prepare the images for training.
Use folders to distinguish between portraits of different ages and pure background images, and the folder position is located in the Image in the data, as shown in Fig. 2.
Fig. 2.Training image folder.
Fig. 3.Image in folder 20.
Fig. 4.Image in folder 30.
Fig. 5.Image in folder background.
Step 2: Preprocessing - create_label
Define the image position of 【Training】and 【Test】.
Step 1: Open the OpenR8 folder and execute R8.exe.
Under the OpenR8 folder, there are two bat files for executing R8.exe, namely R8_Python3.6_CPU.bat and R8_Python3.6_GPU.bat.
If the computer has no GPU, execute R8_Python3.6_CPU.bat.
If your computer has a GPU and your solution needs to use GPU acceleration, you can choose R8_Python3.6_GPU.bat, as shown in Fig. 6.
Fig. 6.execute bat run R8.exe.
Step 2: Select and open the solution.
Open the first flow:1_create_label.
Fig. 7.Open solution 1_create_label.
Step 3: Execute the solution and generate label.txt, train.txt, val.txt.
Fig. 8.Execution solution.
Fig. 9.Generate three txt.
label.txt: The label that produces the classification.
The classification label is the same as the folder.
train.txt: Generates a list of training.
The list is the image path to be trained and the corresponding classification.
Taking this scheme as an example, the classification starts from 0, so if it is 20, it corresponds to 0, and if it is classified to 30, it corresponds to 1.
val.txt: Generates a list of tests.
In 1_create_label, you can modify the parameters from Caffe_Classify_CreateTrainTxt to select what ratio of images to train and test, as shown in Fig. 13
Fig. 13.Change the training and test image ratio.
If you set TrainSplitRate to 1, all images in the folder will be converted to trained images.
Step 3: Training model – train.txt
The introduction is divided into two parts, the first describes how to start training, and then if you are interested in knowing that each process block can be viewed in the 2nd to describe the details of this process.
- Instructions for use: Training model.
First, use the “OpenR8” open “2_train.flow” file to load “2_train”, such as Fig. 14,Fig. 15. Next, click "Run" to start the training model, and this step takes a little time to wait for the program to build the model. such as Fig. 16.
When this execution is completed, a trained model will be generated, and its model file generation will be placed, as shown in Fig. 17.
File name 1：xxx.Caffemodel
File name 2：xxx. Solverstate
If the appliance does not support the NVIDIA GPU. An error message appears.Please follow the Fig. 18,Fig. 19 operation.
Fig. 14.2_train file path.
Fig. 15.load 2_train.
Fig. 16.Perform 2_train and its execution process.
Fig. 17.The production model is finished after training.
Fig. 18.No GPU error message - Training.
Fig. 19.No GPU the way set it up - Training.
- 3_train introduction to processes and parameters:
►Caffe_ Init：Caffe framework Initialization.
【CaffeObject】The setting that follows the previous initialization.
【GPU】Whether the device used to train the model needs to use GPU acceleration, if so, change the value to all; Conversely, fill in the blanks. (If the selection is, make sure the appliance has a GPU)
【SolverPath】The main parameter. This is the input file “Solver.prototxt” required for Caffe training, which contains the number of training iterations, training parameters, and a list of samples. The following Fig. 20,Fig. 21。
【continueTrainModelPath】Continue training with pretrained models. Fill in the value of the model path that you want to train, and the model extension must be .caffemodel.
Fig. 20.2_train - Caffe_Train.
Fig. 21.solver.prototxt content.
test_iter： test a few images at a time.
test_interval：train a few rounds to run a test.
base_lr：learning rate、the smaller the value, the more sophisticated the training.
max_iter： Set up to a few rounds and stop training.
snapshot： Set a few rounds to create a model.
Step 4: Inference using a trained model - inference
- Purpose: To test the accuracy of each stage of the model, to find a suitable model, to avoid over-fitting the training sample, and the test sample is not effective.
- Instructions for use:
(1) Test sample: 【Open OpenR8】 => 【Open and load 3_inference_images.flow】=> 【Select the model to be tested】 => 【Execution flow]
Fig. 22.load 3_inference_images.flow.
Fig. 23.Select the model to be tested.
Fig. 24.Select the picture folder to be tested.
Press 『RUN』 to execute 3_inference_images.flow.
Fig. 25.Run flow.
Fig. 26.Implementation content.