[OpenR8 solution] Image_Age_SSD_Keras (Using the SSD 512 algorithm for image analysis and Keras library for age prediction)
  1. Chapter1: Image_Age_SSD_Keras introduction

 

This Image_Age_SSD_Keras is based on the deep learning Keras framework. First use the SSD (Single Shot MultiBox Detector) algorithm to train the model, and then use the trained model for age prediction.The training image size is 512 × 512.

 

The main process is shown in Fig1.

 

First, we need to prepare the image we want to learn from the model, select the target box in the image, and label the category of the box. The purpose is to let the model know what the object in the image belongs to.

 

Then through the flow file, generate two pkl files, so that the model knows which files are to be tested and tested, and then executes the flow file to train two pkl files. After the training is completed, select different flow files according to the source of the image to be tested.

 

Fig1. SSD forecast age process.png

Fig1. SSD forecast age process.

 

 

  1. Chapter2: Pre-Processing - Region of Interest Mark

 

Fig1.1 SSD forecast age process.png

 

  1. Purpose:

Prepare to label the area of interest.

 

  1. Introduction:

Label the objects in the image that you want the model to learn. For example, if you want the model to learn the age of the face, prepare the image of the face, and bounding box the face in the image and label the age. In this way, the model will know the age of the face in the area marked by this image. It can be seen that if you want the model to learn something, you will be ready for images and mark up categories.

 

So the file we need to prepare contains the following two

(1). Image (image that you want the model to learn)

(2). Label the xml file of the image's target location (the file will be automatically generated after tagging)

 

  1. Example:

In this Image_Age_SSD_Keras scenario example:

To predict the age of the face in the image, we use the labelImg.exe (below in Fig2) to mark the target face in the image, as shown in Fig3 below. The red frame is the category of the face and the age of the face. After marking, the .xml file will be automatically generated when it is saved.

 

Place the image in the specified folder location. See Fig4 below.

【training】

Please place the image: openR8/solution/Image_Age_SSD_Keras/data/image

Please place the xml file: openR8/solution/Image_Age_SSD_Keras/data/annotation

 

  1. Additional instructions:

The tagged software labelImg.exe has been attached with the OpenR8 file. The file path is openR8 > solution > Image_Age_SSD_Keras > labelImg.exe, as shown in Fig2 below.

The usage method can be found in the open source robot club https://tw.openrobot.club/article/index?sn=10976.

 

Fig3. Marking the target object in the image.png

Fig3. Marking the target object in the image.

 

Fig4. Marked image and xml file placement position of the training sample folder.png

Fig4. Marked image and xml file placement position of the training sample folder.

 

 

  1. Chapter3: Pre-processing – generate pkl files

 

Fig4. 1Marked image and xml file placement position of the training sample folder.png

 

This step is to convert the marked training image into the pkl file needed for the subsequent training model.

 

  1. Open the 1_prepare flow file

If the computer has a GPU installed, please double-click R8_Python3.6_GPU.bat. If the GPU is not installed, please double-click R8_Python3.6_CPU.bat => click [File] => [Open] => [OpenR8 > Image_Age_SSD_Keras under solution] => [1_prepare.flow]. See Fig5, Fig6, Fig7, Fig8 below.

 

For any questions about turning on the software to the loading solution, refer to the [OpenR8 Operation Manual].

 

Fig5. R8_Python3.6_GPU.bat and R8_Python3.6_CPU.png

Fig5. R8_Python3.6_GPU.bat and R8_Python3.6_CPU.bat.

 

Fig6. File open.png

Fig6. File open.

 

Fig7. Select 1_prepare.flow form the Image_Age_SSD_Keras folder.png

Fig7. Select 1_prepare.flow form the Image_Age_SSD_Keras folder.

 

Fig8. Load 1_prepare.flow.png

Fig8. Load 1_prepare.flow.

 

  1. Execute the 1_prepare process file

Please click Run. After the execution is completed, prior_boxes_ssd512.pkl and AGE.pkl (or update the previous prior_boxes_ssd512.pkl and AGE.pkl) will be generated, as shown in Fig9, Fig10.

 

Fig9. Execution completed.png

Fig9. Execution completed.

 

Fig10. Generate AGE.pkl and prior_boxes_ssd512.png

Fig10. Generate AGE.pkl and prior_boxes_ssd512.pkl.

 

 

  1. Chapter4: Training model – train

 

Fig10. 1Generate AGE.pkl and prior_boxes_ssd512.png

 

The introduction is divided into two parts. The first point is to introduce how to start training. Then, if you are interested in knowing each process block, you can watch the second point to introduce the details of this process.

 

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

First, use OpenR8 to open the [2_train.flow] file and load 2_train.flow, as shown in Fig11, Fig12.

Press [Run] to start training the model. This step takes a while to wait for the program to build the model. See Fig13 below.

When this execution is completed, a trained model is generated, as shown in Fig14.

Path: OpenR8/solution/Image_Age_SSD_Keras/data/output

file name: xxx.hdf5

 

Remarks: The 700 of the CMD window in Fig13 refers to the total number of training images.

 

Fig11. 2_train.flow file path.png

Fig11. 2_train.flow file path.

 

Fig12. Open 2_train.flow.png

Fig12. Open 2_train.flow.

 

Fig13. Executing 2_train.flow and its execution process.png

Fig13. Executing 2_train.flow and its execution process.

 

Fig14. After training the model is generated.png

Fig14. After training the model is generated.

 

  1. 2_train process introduction:

►Python:

【result】The default is not filled in, this parameter is to receive the message returned by python.

【path】Execute the path to ssd_run_training.py.

【arg】The default is not filled in. This parameter is the parameter to be passed to ssd_run_training.py.

【pythonPath】The default is not filled in. This parameter is the location of the python.exe to be called.

 

Fig15. 2_train.flow - Python.png

Fig15. 2_train.flow - Python.

 

 

  1. Chapter5: Test a trained model - inference_image

 

Fig15. 12_train.flow - Python.png

 

After the model has been trained, the trained model can be tested by this step. First open the [3_inference_folder.flow] with OpenR8 and load the file. As shown in Fig16, Fig17.

 

  1. Test process

►Select the image folder location to be tested, as shown in Fig18 below, fill in the image folder path.

 

►Select the trained model to detect the image. Fill in the hdf5 folder position as shown in Fig19 below.

 

►Watch the results message. Press Run to detect the age of the face predicted by the trained model and select the face of the face. See Fig20 below. Press Enter to continue reading the next image in the folder until the image in the folder has been detected. See Fig21 below.

 

Fig16. 3_inference_folder.flow.png

Fig16. 3_inference_folder.flow.

 

Fig17. Load 3_inference_folder.flow.png

Fig17. Load 3_inference_folder.flow.

 

Fig18. 3_inference_folder - Select test image folder.png

Fig18. 3_inference_folder - Select test image folder.

 

Fig19. 3_inference_folder sets the position of the model.png

Fig19. 3_inference_folder sets the position of the model.

 

Fig20. 3_inference_folder execution result.png

Fig20. 3_inference_folder execution result.

 

Fig21. 3_inference_folder - Another image test result.png

Fig21. 3_inference_folder - Another image test result.

 

  1. 3_inference_folder process content introduction

►Python:

【result】The default is not filled in, this parameter is to receive the message returned by python.

【path】The path to ssd_run_inference_folder.py (starting with 3_inference_folder.flow).

【arg】Pass the parameter to ssd_run_inference_folder.py, where the path of the image folder to be tested and the path of the trained model are passed, and the image folder and the model path are separated by spaces.

【pythonPath】The default is not filled in. This parameter is the location of the python.exe to be called.

 

 

  1. Chapter6: Capture webcam image test trained model - inference_camera

 

Fig21. 13_inference_folder - Another image test result.png

 

After the model has been trained, the trained model can also be tested by capturing the image of the webcam in this step.

 

First open the [4_inference_camera.flow] using OpenR8 and load the file. See Fig22, Fig23 below.

 

  1. Test process

 

  1. Select the trained model to detect the image. The training model to be used is placed in the hdf5 file of data/output/. See Fig24 below.

 

►Press Run to detect the target coordinate position of the webcam and its category through the trained model. See Fig25 below.

 

Fig22. 4_inference_camera.flow.png

Fig22. 4_inference_camera.flow.

 

Fig23. Load 4_inference_camera.flow.png

Fig23. Load 4_inference_camera.flow.

 

Fig24. .png

Fig24. 4_inference_camera confirm model file.

 

Fig25. .png

Fig25. 4_inference_camera execution result.

 

  1. inference_camera.flow process content introduction

 

►Python:

【result】The default is not filled in. This parameter is to receive the python return result.

【path】The path to ssd_run_inference_camera.py (starting with 4_inference_camera.flow).

【arg】The argument passed to ssd_run_inference_camera.py, where the argument passed is the trained model path.

【pythonPath】The default is not filled in. This parameter is the location of the call python.exe.

 

 

  1. Chapter7: Parameter setting

 

There are many variable parameters from the preparation of the data to the image age prediction. The parameters that can be set in each case are listed below.

 

To use GPU acceleration, be sure to select R8_Python3.6_GPU.bat when opening bat; instead, open R8_Python3.6_CPU.bat if you want to use the CPU.

 

1_prepare.flow running

 

(1) Set the number of categories to be trained: The trained images are divided into several categories, and the number is set. If the unknown label as shown in Fig26 appears after running, it means that there is an unknown category name. Please go to get_data_from_XML.py to add or modify the category name and confirm the number of categories, as shown in Fig27 and Fig28.

 

PS. If the number of get_data_from_XML.py categories has changed, remember that ssd_run_training.py also modifies the number of categories, as shown in Fig29.

 

Fig26. Unknown label appears when running 1_prepare.flow.png

Fig26. Unknown label appears when running 1_prepare.flow.

 

Fig27. Adding a category to get_data_from_XML.png

Fig27. Adding a category to get_data_from_XML.py.

 

Fig28. Location of the number of categories in get_data_from_XML.png

Fig28. Location of the number of categories in get_data_from_XML.py.

 

2_train.flow before running

 

(1) Set the number of categories of training: The number of training images is divided into several categories, as shown in Fig29.

 

(2) Set the folder position of the training image: the position of the training image folder, as shown in Fig30.

 

(3) Adjust the batch_size value: If an error like Fig31 occurs, try to reduce the value of this parameter, as shown in Fig32.

 

(4) Set the number of trainings: Set the number of trainings, as shown in Fig33.

 

Fig29. Change the number of categories in ssd_run_training.png

Fig29. Change the number of categories in ssd_run_training.py.

 

Fig30. Changing the training folder position in ssd_run_training.png

Fig30. Changing the training folder position in ssd_run_training.py.

 

Fig31. Insufficient memory during training.png

Fig31. Insufficient memory during training.

 

Fig32. Setting the position of batch size.png

Fig32. Setting the position of batch size.

 

Fig33. training times.png

Fig33. training times.

 


Recommended Article

1.
OpenR8 - AI Software for Everyone (Download)