Salted fish K210 experience notes-model training

This tutorial can be completed in Win: making a data set, training yolo, and converting it into a Kmodel file for k210

Model training

1. Install Anaconda3

Anaconda3 address and installation instructions

Remember to check [Add Anaconda3 to the PATH environment variable] during installationInsert picture description here

2. Download tool

To download this project, extract [train_ann.zip] and [train_img.zip] to the current folder in the project root directory.
Download
[ncc_0.1_win.zip] to the project root directory and extract to the current folder

3. Prepare the environment

First install Anaconda in your system. You can open the command line input to conda -Vverify whether it is installed and the current version of conda.
Insert picture description here

1. New environment: conda create -n yolo python=3.6
Insert picture description here
Enter y and wait for the download to complete
Insert picture description here

2. Activate the environment: conda activate yolo
Insert picture description here
3. Install the necessary software packages:pip install -r requirements.txt

The reason for the error: the file is not in the root directory, so it cannot be opened. Insert picture description here
Try again in the past.Insert picture description here

Wait for QAQ (it takes a little longer ... be patient)Insert picture description here

4. Modify the parameters

In [configs.json], modify the network type, the lable tag (such as raccoon), and other parameters. Note the folder name examlpe for storing pictures (train_img) and comments (train_ann)

Insert picture description here

5. Import pictures

First put the picture in the train_img folder

Open labelImg.exe
Insert picture description here

Open Dir—> Select the folder to store the image (train_img)
Insert picture description here
Change Save Dir—> Select the folder to store the annotation (train_ann)
Insert picture description here
Create RectBox—> Select the object to be marked and enter lable, the same as the configs above (such as raccoon )
Insert picture description here
Insert picture description here
Insert picture description here
After
saving , click Next (Next Image) to automatically generate an xml file of the marked target location and save it in the comment folder

6. Start training

input the command

python train.py -c configs.json

If the cv2 is lost, it is that the requirements.txt file is not finished, and it can be solved by retrying again: pip install -r requirements.txt

Insert picture description here
PS: There are too many training pictures, which leads to a huge training time. . When I do it myself, the pictures are less. (I waited for my flowers) The
Insert picture description here
download is complete

After the training is completed, a time-named folder will appear. The tflite file inside is the trained model.
Insert picture description here
Rename it (eg test.tflite) and copy it to the project root
Insert picture description here

Insert picture description here

7. Convert to Kmodel
 ncc_0.1_win\ncc test.tflite test.kmodel -i tflite -o k210model --dataset train_img

Insert picture description here
After conversion, test.kmodel will appear in the root directory, you can burn it into k210 to run

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -*-

test program

import sensor,image,lcd,time
import KPU as kpu

lcd.init(freq=15000000)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.set_brightness(2)

sensor.run(1)
clock = time.clock()
classes = ['class_1']
task = kpu.load(0x300000)
anchor = (1, 1.2, 2, 3, 4, 3, 6, 4, 5, 6.5)
a = kpu.init_yolo2(task, 0.17, 0.3, 5, anchor)
while(True):
    clock.tick()
    img = sensor.snapshot()
    code = kpu.run_yolo2(task, img)
    print(clock.fps())
    if code:
        for i in code:
            a=img.draw_rectangle(i.rect())
            a = lcd.display(img)
            print(i.classid(),i.value())
            for i in code:
                lcd.draw_string(i.x(), i.y(), classes[i.classid()], lcd.RED, lcd.WHITE)
                lcd.draw_string(i.x(), i.y()+12, '%f1.3'%i.value(), lcd.RED, lcd.WHITE)
    else:
        a = lcd.display(img)
a = kpu.deinit(task)

Reference address: https://github.com/TonyZ1Min/yolo-for-k210

Published 166 original articles · 22 praises · 10,000+ views

Guess you like

Origin blog.csdn.net/weixin_45020839/article/details/105285941