8. Online Model Training

## 8.1 Training Data Preparation

The 7. Touch Control Course - Touch Photography routine is utilized to collect the corresponding dataset. Refer to the 7.3 Touch Photography section of the 7. Touch Control Course for specific procedures on capturing and saving the dataset images.

8.2 Online Training Platform Registration

Online training model address: https://www.kendryte.com/zh/training/dataset

  1. Click the X button to cancel login.

  1. Click the top right corner to switch to English.

  1. After switching, click the Sign in or Sign up option in the top right corner.

  1. Accessing the KENDRYTE allows for either registration or login, and registration is demonstrated here as an example.

  1. Click the Register button to begin registration.

  1. Fill in the corresponding personal information and click Register.

8.3 Initiating Online Model Training

  1. After successful registration, the account logs in automatically and then clicks Create Dataset on the right.

  1. Taking Image Detection as an example to create a dataset, enter the dataset name and select the corresponding recognition and annotation types.

  1. Click the Configuration button in the top-right corner.

  1. Click the Upload Image button to upload the corresponding dataset to the cloud platform.

  1. Upload the prepared dataset to the model training cloud platform.

  1. Click the Annotate button after the image upload is complete.

  1. Click New Tag to add labels for the corresponding categories.

  1. Add green, red, and yellow labels for traffic light recognition.

  1. Select the corresponding color tag, using green as an example, and drag the mouse to annotate the target object.

  1. Apply corresponding annotations to all images.

  1. Click the return button upon completion of all annotations.

  1. Next, click the Train button to start model training.

  1. Fill in the corresponding training parameters.

* Platform: Select K230
* nncase Version: The latest version is selected.
* Iterations: This value is adjusted based on the dataset, typically set around 200. The system automatically ceases training when the loss remains stable, and change < 0.05 for 30~50 consecutive epochs.
* Batch Size: Select 8.
* Learning Rate: Enter 0.001.
* Label Box Limit: Enter 5, which indicates the maximum number of target boxes allowed per image.
  1. Click Confirm to automatically redirect to the training interface and wait for the training. Note that queuing may be required during busy periods.

  1. As training occurs in the cloud, the webpage or browser may be closed without affecting the process.

  1. During the process, hover the mouse over the training result chart to view real-time loss data.

  1. Upon training completion, the registered email address receives a notification indicating the end of model training.

8.4 Model Download and Deployment

  1. First, click Records on the left, then click Download on the right to save the trained model and deployment materials locally.

  1. Extract the downloaded compressed package locally.

  1. The detailed directory structure of the archive is as follows.

**_image_1_2_2.py # 1.2.2 firmware image inference script, full code
**_video_1_2_2.py # 1.2.2 firmware video inference script, full code
**_image_1_3.py # 1.3 firmware image inference script, highly encapsulated
**_video_1_3.py # 1.3 firmware video inference script, highly encapsulated
README.pdf # Official tutorial document
det_results # Verification test results
mp_deployment_source # micropython deployment resource directory
|- *.kmodel # kmodel file
|- deploy_config.json # Deployment configuration file
  1. Extract the downloaded archive to a local directory. Focus exclusively on the sample program, as well as the model and configuration files located within the mp_deployment_source directory.

  1. Copy the entire mp_deployment_source folder to the This PC\CanMV\sdcard directory on the K230 development board SD card.

  1. Using the video inference program as an example, drag the decompressed det_image_1_2_2.py into the CanMV IDE.

  1. The program requires minor modification regarding the corresponding path.

Slightly modify the import path in the det_image_1_2_2.py program.

Original program:

root_path = "/sdcard/mp_deployment_source/"
config_path = root_path + "deploy_config.json"
deploy_conf = {}
debug_mode = 1

Modified to:

root_path = "/sdcard/mp_deployment_source/"
config_path = "/sdcard/mp_deployment_source/deploy_config.json"
deploy_conf = {}
debug_mode = 1
  1. The display mode can also be selected.

Select the display mode by slightly modifying the display section of the det_image_1_2_2.py program.

LCD display mode:

display_mode = "lcd"
if display_mode == "lcd":
    DISPLAY_WIDTH = ALIGN_UP(800, 16)
    DISPLAY_HEIGHT = 480
else:
    DISPLAY_WIDTH = ALIGN_UP(1920, 16)
    DISPLAY_HEIGHT = 1080
OUT_RGB888P_WIDTH = ALIGN_UP(640, 16)
OUT_RGB888P_HEIGH = 360

HDMI display mode:

 display_mode = "hdmi"
 if display_mode == "lcd":
  DISPLAY_WIDTH = ALIGN_UP(800, 16)
     DISPLAY_HEIGHT = 480
    else:
  DISPLAY_WIDTH = ALIGN_UP(1920, 16)
     DISPLAY_HEIGHT = 1080
    OUT_RGB888P_WIDTH = ALIGN_UP(640, 16)
 OUT_RGB888P_HEIGH = 360
  1. The achieved effect is shown in the figure below.