Note

This is the documentation for the latest development branch and may refer to features that are not available in released versions. If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

yolo_module_api_manual#

Overview#

This manual is intended to guide developers in deploying models trained and converted using YOLOv5, YOLOv8, and YOLO11 through the YOLO module. The models support three types of tasks: classification, detection, and segmentation. It helps users quickly interface with the YOLO source code and deploy the trained models on the K230. For YOLO usage examples, refer to the documentation: yolo_battle

API Introduction#

YOLOv5 Class#

Constructor#

Description

The encapsulated YOLOv5 module constructor. Initializes the YOLOv5 type to obtain a YOLOv5 instance.

Syntax

from libs.YOLO import YOLOv5

yolo=YOLOv5(task_type="classify",mode="image",kmodel_path="yolov5_det.kmodel",labels=["apple","banana","orange"],rgb888p_size=[1280,720],model_input_size=[320,320],conf_thresh=0.5,nms_thresh=0.25,max_boxes_num=50,debug_mode=0)

Parameters

Parameter Name

Description

Description

Type

task_type

Task type

Supports three types of tasks, options are ‘classify’/’detect’/’segment’;

str

mode

Inference mode

Supports two inference modes, options are ‘image’/’video’, ‘image’ means inferring on an image, ‘video’ means inferring on a real-time video stream captured by the camera;

str

kmodel_path

kmodel path

Path of the kmodel copied to the development board;

str

labels

Category label list

Names of labels for different categories;

list[str]

rgb888p_size

Inference frame resolution

Resolution of the current inference frame, e.g., [1920,1080], [1280,720], [640,640];

list[int]

model_input_size

Model input resolution

Input resolution when training the YOLOv5 model, e.g., [224,224], [320,320], [640,640];

list[int]

display_size

Display resolution

Set when the inference mode is ‘video’, supports hdmi([1920,1080]) and lcd([800,480]);

list[int]

conf_thresh

Confidence threshold

Confidence threshold for categories in classification tasks, and object confidence threshold in detection and segmentation tasks, e.g., 0.5;

float [0~1]

nms_thresh

nms threshold

Non-maximum suppression threshold, required for detection and segmentation tasks;

float [0~1]

mask_thresh

mask threshold

Binarization threshold for segmenting objects within detection boxes in segmentation tasks;

float [0~1]

max_boxes_num

Maximum number of detection boxes

Maximum number of detection boxes allowed to be returned in one frame;

int

debug_mode

Debug mode

Whether the timing function is enabled, options 0/1, 0 means no timing, 1 means timing;

int [0/1]

Return Value

Return Value

Description

YOLOv5

YOLOv5 instance

config_preprocess#

Description

YOLOv5 preprocessing configuration function.

Syntax

yolo.config_preprocess()

Parameters

Parameter Name

Description

Input / Output

Description

None

Return Value

Return Value

Description

None

run#

Description

Infer one frame of image, and return the inference result for use by the draw_result method. The classification task returns the category index and score, the detection task returns a list of detection box positions, scores, and category indices, and the segmentation task returns the mask result along with a list of detection box positions, scores, and category indices.

Syntax

res=yolo.run(img)

Parameters

Parameter Name

Description

Input / Output

Description

img

The image to be inferred in ulab.numpy.ndarray format, or a frame of image obtained from the video stream via get_frame

Input

Return Value

Return Value

Description

res

Model post-processing result, which varies depending on the task. The classification task returns the category index and score, the detection task returns a list of detection box positions, scores, and category indices, and the segmentation task returns the mask result along with a list of detection box positions, scores, and category indices.

draw_result#

Description

Draw the YOLOv5 inference result on the screen or image.

Syntax

yolo.draw_result(res,img_ori)

Parameters

Parameter Name

Description

Input / Output

Description

res

Inference result of YOLOv5

Input

img_ori

Image instance to be drawn

Input

From read_img or pl.osd_img

Return Value

Return Value

Description

None

Example Program#

The following is an example program for the YOLOv5 detection task:

from libs.YOLO import YOLOv5
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # 这里仅为示例,自定义场景请修改为您自己的测试图片、模型路径、标签名称、模型输入大小
    img_path="/sdcard/examples/utils/test_fruit.jpg"
    kmodel_path="/sdcard/examples/kmodel/fruit_det_yolov5n_320.kmodel"
    labels = ["apple","banana","orange"]
    model_input_size=[320,320]

    confidence_threshold = 0.5
    nms_threshold=0.45
    img,img_ori=read_image(img_path)
    rgb888p_size=[img.shape[2],img.shape[1]]
    # 初始化YOLOv5实例
    yolo=YOLOv5(task_type="detect",mode="image",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,conf_thresh=confidence_threshold,nms_thresh=nms_threshold,max_boxes_num=50,debug_mode=0)
    yolo.config_preprocess()
    res=yolo.run(img)
    yolo.draw_result(res,img_ori)
    yolo.deinit()
    gc.collect()

The above code demonstrates the code for performing image inference using YOLOv5.

from libs.PipeLine import PipeLine
from libs.YOLO import YOLOv5
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # 这里仅为示例,自定义场景请修改为您自己的模型路径、标签名称、模型输入大小
    kmodel_path="/sdcard/examples/kmodel/fruit_det_yolov5n_320.kmodel"
    labels = ["apple","banana","orange"]
    model_input_size=[320,320]

    # 添加显示模式,默认hdmi,可选hdmi/lcd/lt9611/st7701/hx8399,其中hdmi默认置为lt9611,分辨率1920*1080;lcd默认置为st7701,分辨率800*480
    display_mode="lcd"
    rgb888p_size=[640,360]
    confidence_threshold = 0.8
    nms_threshold=0.45
    pl=PipeLine(rgb888p_size=rgb888p_size,display_mode=display_mode)
    pl.create()
    display_size=pl.get_display_size()
    # 初始化YOLOv5实例
    yolo=YOLOv5(task_type="detect",mode="video",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,display_size=display_size,conf_thresh=confidence_threshold,nms_thresh=nms_threshold,max_boxes_num=50,debug_mode=0)
    yolo.config_preprocess()
    while True:
        with ScopedTiming("total",1):
            img=pl.get_frame()
            res=yolo.run(img)
            yolo.draw_result(res,pl.osd_img)
            pl.show_image()
            gc.collect()
    yolo.deinit()
    pl.destroy()

The above code demonstrates the code for performing video inference using YOLOv5.

YOLOv8 Class#

Constructor#

Description

The encapsulated YOLOv8 module constructor, initializes the YOLOv8 type to obtain a YOLOv8 instance.

Syntax

from libs.YOLO import YOLOv8

yolo=YOLOv8(task_type="classify",mode="image",kmodel_path="yolov8_det.kmodel",labels=["apple","banana","orange"],rgb888p_size=[1280,720],model_input_size=[320,320],conf_thresh=0.5,nms_thresh=0.25,max_boxes_num=50,debug_mode=0)

Parameters

Parameter Name

Description

Description

Type

task_type

Task type

Supports four types of tasks, optional values are ‘classify’/’detect’/’segment’/’obb’;

str

mode

Inference mode

Supports two inference modes, optional values are ‘image’/’video’, ‘image’ means inferring an image, ‘video’ means inferring a real-time video stream captured by the camera;

str

kmodel_path

kmodel path

The path of the kmodel copied to the development board;

str

labels

Class label list

Label names for different classes;

list[str]

rgb888p_size

Inference frame resolution

The resolution of the current inference frame, such as [1920,1080], [1280,720], [640,640];

list[int]

model_input_size

Model input resolution

The input resolution when training the YOLOv8 model, such as [224,224], [320,320], [640,640];

list[int]

display_size

Display resolution

Set when the inference mode is ‘video’, supports hdmi([1920,1080]) and lcd([800,480]);

list[int]

conf_thresh

Confidence threshold

Class confidence threshold for classification tasks, object confidence threshold for detection and segmentation tasks, such as 0.5;

float [0~1]

nms_thresh

nms threshold

Non-maximum suppression threshold, required for detection and segmentation tasks;

float [0~1]

mask_thresh

mask threshold

The binarization threshold for segmenting objects in the detection box in the segmentation task;

float [0~1]

max_boxes_num

Maximum number of detection boxes

The maximum number of detection boxes allowed to be returned in one frame of image;

int

kp_num

Number of keypoints

The number of keypoints in the keypoint detection task;

int

kp_dim

Keypoint dimension

The dimension of keypoints in the keypoint detection task, only 2 and 3 are supported, determined by the trained model;

int【2/3】

debug_mode

Debug mode

Whether the timing function is enabled, optional values are 0/1, 0 means no timing, 1 means timing;

int [0/1]

Return Value

Return Value

Description

YOLOv8

YOLOv8 instance

config_preprocess#

Description

YOLOv8 preprocessing configuration function.

Syntax

yolo.config_preprocess()

Parameters

Parameter Name

Description

Input / Output

Description

None

Return Value

Return Value

Description

None

run#

Description

Infer one frame of image, return the inference result for use by the draw_result method. The classification task returns the class index and score, the detection task returns a list of detection box positions, scores, and class indices, the segmentation task returns the mask result and a list of detection box positions, scores, and class indices, the rotated object detection returns a list of the four point coordinates of the rotated detection box, and the keypoint detection returns the detection box position, class index, score, and keypoint list.

Syntax

res=yolo.run(img)

Parameters

Parameter Name

Description

Input / Output

Description

img

The image to be inferred in the format of ulab.numpy.ndarray, or a frame of image obtained from the video stream through get_frame

Input

Return Value

Return Value

Description

res

Model post-processing result, the return value varies for different tasks. The classification task returns the class index and score, the detection task returns a list of detection box positions, scores, and class indices, the segmentation task returns the mask result and a list of detection box positions, scores, and class indices, the rotated object detection returns a list of the four point coordinates of the rotated detection box, and the keypoint detection returns the detection box position, class index, score, and keypoint list.

draw_result#

Description

Draws the YOLOv8 inference result on the screen or image.

Syntax

yolo.draw_result(res,img_ori)

Parameters

Parameter Name

Description

Input / Output

Description

res

The inference result of YOLOv8

Input

img_ori

The Image instance to be drawn

Input

From read_img or pl.osd_img

Return Value

Return Value

Description

None

Example Program#

The following is an example program for the YOLOv8 classification task:

from libs.YOLO import YOLOv8
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # This is only an example, please modify it to your own test image, model path, label name, and model input size for custom scenarios
    img_path="/sdcard/examples/utils/test_fruit.jpg"
    kmodel_path="/sdcard/examples/kmodel/fruit_det_yolov8n_320.kmodel"
    labels = ["apple","banana","orange"]
    model_input_size=[320,320]

    confidence_threshold = 0.5
    nms_threshold=0.45
    img,img_ori=read_image(img_path)
    rgb888p_size=[img.shape[2],img.shape[1]]
    # Initialize the YOLOv8 instance
    yolo=YOLOv8(task_type="detect",mode="image",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,conf_thresh=confidence_threshold,nms_thresh=nms_threshold,max_boxes_num=50,debug_mode=0)
    yolo.config_preprocess()
    res=yolo.run(img)
    yolo.draw_result(res,img_ori)
    yolo.deinit()
    gc.collect()

The above code gives an example of using YOLOv8 for image inference.

from libs.PipeLine import PipeLine
from libs.YOLO import YOLOv8
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # This is only an example, please modify it to your own model path, label name, and model input size for custom scenarios
    kmodel_path="/sdcard/examples/kmodel/fruit_det_yolov8n_320.kmodel"
    labels = ["apple","banana","orange"]
    model_input_size=[320,320]

    # Add display mode, default is hdmi, optional hdmi/lcd/lt9611/st7701/hx8399, where hdmi defaults to lt9611, resolution 1920*1080; lcd defaults to st7701, resolution 800*480
    display_mode="lcd"
    rgb888p_size=[640,360]
    confidence_threshold = 0.5
    nms_threshold=0.45
    # Initialize PipeLine
    pl=PipeLine(rgb888p_size=rgb888p_size,display_mode=display_mode)
    pl.create()
    display_size=pl.get_display_size()
    # Initialize the YOLOv8 instance
    yolo=YOLOv8(task_type="detect",mode="video",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,display_size=display_size,conf_thresh=confidence_threshold,nms_thresh=nms_threshold,max_boxes_num=50,debug_mode=0)
    yolo.config_preprocess()
    while True:
        with ScopedTiming("total",1):
            # Inference frame by frame
            img=pl.get_frame()
            res=yolo.run(img)
            yolo.draw_result(res,pl.osd_img)
            pl.show_image()
            gc.collect()
    yolo.deinit()
    pl.destroy()

The above code gives an example of using YOLOv8 for video inference.

YOLO11 Class#

Constructor#

Description

The encapsulated YOLO11 module constructor, initializes the YOLO11 type to obtain a YOLO11 instance.

Syntax

from libs.YOLO import YOLO11

yolo=YOLO11(task_type="segment",mode="image",kmodel_path="yolo11_det.kmodel",labels=["apple","banana","orange"],rgb888p_size=[1280,720],model_input_size=[320,320],conf_thresh=0.5,nms_thresh=0.25,mask_thresh=0.5,max_boxes_num=50,debug_mode=0)

Parameters

Parameter Name

Description

Description

Type

task_type

Task Type

Supports four types of tasks, optional values are ‘classify’/’detect’/’segment’/’obb’;

str

mode

Inference Mode

Supports two inference modes, optional values are ‘image’/’video’, ‘image’ means inference on images, ‘video’ means inference on real-time video streams captured by the camera;

str

kmodel_path

kmodel Path

Path of the kmodel copied to the development board;

str

labels

Class Label List

Label names for different categories;

list[str]

rgb888p_size

Inference Frame Resolution

Resolution of the current inference frame, such as [1920,1080], [1280,720], [640,640];

list[int]

model_input_size

Model Input Resolution

Input resolution when training the YOLO11 model, such as [224,224], [320,320], [640,640];

list[int]

display_size

Display Resolution

Set when the inference mode is ‘video’, supports hdmi([1920,1080]) and lcd([800,480]);

list[int]

conf_thresh

Confidence Threshold

Class confidence threshold for classification tasks, target confidence threshold for detection and segmentation tasks, such as 0.5;

float [0~1]

nms_thresh

NMS Threshold

Non-maximum suppression threshold, required for detection and segmentation tasks;

float [0~1]

mask_thresh

Mask Threshold

Binarization threshold for segmenting objects within detection boxes in segmentation tasks;

float [0~1]

max_boxes_num

Maximum Detection Boxes

Maximum number of detection boxes allowed to be returned in one frame of image;

int

kp_num

Number of Keypoints

Number of keypoints in the keypoint detection task;

int

kp_dim

Keypoint Dimension

Dimension of keypoints in the keypoint detection task, only supports 2 and 3, determined by the trained model;

int【2/3】

debug_mode

Debug Mode

Whether the timing function is enabled, optional 0/1, 0 means no timing, 1 means timing;

int [0/1]

Return Value

Return Value

Description

YOLO11

YOLO11 instance

config_preprocess#

Description

YOLO11 preprocessing configuration function.

Syntax

yolo.config_preprocess()

Parameters

Parameter Name

Description

Input / Output

Description

None

Return Value

Return Value

Description

None

run#

Description

Infer one frame of image, return the inference result for use by the draw_result method. Classification tasks return class indices and scores, detection tasks return lists of detection box positions, scores, and class indices, segmentation tasks return mask results and lists of detection box positions, scores, and class indices, oriented object detection returns lists of four-point coordinates of oriented detection boxes, keypoint detection returns lists of detection box positions, class indices, scores, and keypoints.

Syntax

res=yolo.run(img)

Parameters

Parameter Name

Description

Input / Output

Description

img

The image to be inferred in the format of ulab.numpy.ndarray, or a frame of image obtained from the video stream via get_frame

Input

Return Value

Return Value

Description

res

Model post-processing result, different tasks return different values, classification tasks return class indices and scores, detection tasks return lists of detection box positions, scores, and class indices, segmentation tasks return mask results and lists of detection box positions, scores, and class indices, oriented object detection returns lists of four-point coordinates of oriented detection boxes, keypoint detection returns lists of detection box positions, class indices, scores, and keypoints.

draw_result#

Description

Draw the YOLO11 inference result on the screen or image.

Syntax

yolo.draw_result(res,img_ori)

Parameters

Parameter Name

Description

Input / Output

Description

res

Inference result of YOLO11

Input

img_ori

Image instance to be drawn

Input

From read_img or pl.osd_img

Return Value

Return Value

Description

None

Example Program#

The following gives an example program for the YOLO11 segmentation task:

from libs.YOLO import YOLO11
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # This is only an example, please modify it to your own test image, model path, label name, and model input size for custom scenarios
    img_path="/sdcard/examples/utils/test_fruit.jpg"
    kmodel_path="/sdcard/examples/kmodel/fruit_det_yolo11n_320.kmodel"
    labels = ["apple","banana","orange"]
    model_input_size=[320,320]

    confidence_threshold = 0.5
    nms_threshold=0.45
    img,img_ori=read_image(img_path)
    rgb888p_size=[img.shape[2],img.shape[1]]
    # Initialize YOLO11 instance
    yolo=YOLO11(task_type="detect",mode="image",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,conf_thresh=confidence_threshold,nms_thresh=nms_threshold,max_boxes_num=50,debug_mode=0)
    yolo.config_preprocess()
    res=yolo.run(img)
    yolo.draw_result(res,img_ori)
    yolo.deinit()
    gc.collect()

The above code provides the code for using YOLO11 for image inference.

from libs.PipeLine import PipeLine
from libs.YOLO import YOLO11
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # This is only an example, please modify it to your own model path, label name, and model input size for custom scenarios
    kmodel_path="/sdcard/examples/kmodel/fruit_det_yolo11n_320.kmodel"
    labels = ["apple","banana","orange"]
    model_input_size=[320,320]

    # Add display mode, default is hdmi, optional hdmi/lcd/lt9611/st7701/hx8399, where hdmi is set to lt9611 by default with resolution 1920*1080; lcd is set to st7701 by default with resolution 800*480
    display_mode="lcd"
    rgb888p_size=[640,360]
    confidence_threshold = 0.5
    nms_threshold=0.45
    # Initialize PipeLine
    pl=PipeLine(rgb888p_size=rgb888p_size,display_mode=display_mode)
    pl.create()
    display_size=pl.get_display_size()
    # Initialize YOLO11 instance
    yolo=YOLO11(task_type="detect",mode="video",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,display_size=display_size,conf_thresh=confidence_threshold,nms_thresh=nms_threshold,max_boxes_num=50,debug_mode=0)
    yolo.config_preprocess()
    while True:
        with ScopedTiming("total",1):
            # Inference frame by frame
            img=pl.get_frame()
            res=yolo.run(img)
            yolo.draw_result(res,pl.osd_img)
            pl.show_image()
            gc.collect()
    yolo.deinit()
    pl.destroy()

The above code provides the code for using YOLO11 for video inference.

YOLO26 Class#

Constructor#

Description

Encapsulated YOLO26 module constructor, initializes the YOLO26 type to obtain a YOLO26 instance.

Syntax

from libs.YOLO import YOLO26

yolo=YOLO26(task_type="pose",mode="image",kmodel_path="yolo26n_pose.kmodel",labels=["people"],rgb888p_size=[1280,720],model_input_size=[320,320],conf_thresh=0.5,mask_thresh=0.5,kp_num=17,kp_dim=3,max_boxes_num=50,debug_mode=0)

Parameters

Parameter Name

Description

Notes

Type

task_type

Task type

Supports four types of tasks, options are ‘classify’/’detect’/’segment’/’obb’;

str

mode

Inference mode

Supports two inference modes, options are ‘image’/’video’; ‘image’ means inference on an image, ‘video’ means inference on real-time video stream captured by camera;

str

kmodel_path

kmodel path

The kmodel path copied to the development board;

str

labels

Class label list

Label names for different classes;

list[str]

rgb888p_size

Inference frame resolution

Resolution of the current inference frame, e.g., [1920,1080], [1280,720], [640,640];

list[int]

model_input_size

Model input resolution

Input resolution when training the YOLO11 model, e.g., [224,224], [320,320], [640,640];

list[int]

display_size

Display resolution

Set when the inference mode is ‘video’, supports hdmi([1920,1080]) and lcd([800,480]);

list[int]

conf_thresh

Confidence threshold

Class confidence threshold for classification task, object confidence threshold for detection and segmentation tasks, e.g., 0.5;

float [0~1]

mask_thresh

Mask threshold

Binarization threshold for segmenting objects within detection boxes in segmentation tasks;

float [0~1]

max_boxes_num

Maximum number of detection boxes

Maximum number of detection boxes allowed to be returned in one frame of image;

int

kp_num

Number of keypoints

Number of keypoints in the keypoint detection task;

int

kp_dim

Keypoint dimension

Dimension of keypoints in the keypoint detection task, only 2 and 3 are supported, determined by the trained model;

int[2/3]

debug_mode

Debug mode

Whether the timing function takes effect, options 0/1, 0 for no timing, 1 for timing;

int [0/1]

Note: The YOLO26 module no longer includes the nms_thresh parameter, because the YOLO26 model directly outputs results with semantic information.

Return Value

Return Value

Description

YOLO26

YOLO26 instance

config_preprocess#

Description

YOLO26 preprocessing configuration function.

Syntax

yolo.config_preprocess()

Parameters

Parameter Name

Description

Input / Output

Notes

None

Return Value

Return Value

Description

None

run#

Description

Performs inference on one frame of image, returns the inference result for use by the draw_result method. The classification task returns the class index and score, the detection task returns a list of detection box positions, scores, and class indices, the segmentation task returns the mask result and a list of detection box positions, scores, and class indices, the oriented object detection returns a list of four-point coordinates of the oriented detection boxes, and the keypoint detection returns the detection box positions, class indices, scores, and keypoints list.

Syntax

res=yolo.run(img)

Parameters

Parameter Name

Description

Input / Output

Notes

img

The image to be inferred in the format of ulab.numpy.ndarray, or a frame of image obtained from the video stream via get_frame

Input

Return Value

Return Value

Description

res

Model post-processing result, the return value varies for different tasks. The classification task returns the class index and score, the detection task returns a list of detection box positions, scores, and class indices, the segmentation task returns the mask result and a list of detection box positions, scores, and class indices, the oriented object detection returns a list of four-point coordinates of the oriented detection boxes, and the keypoint detection returns the detection box positions, class indices, scores, and keypoints list.

draw_result#

Description

Draws the YOLO26 inference result on the screen or image.

Syntax

yolo.draw_result(res,img_ori)

Parameters

Parameter Name

Description

Input / Output

Notes

res

Inference result of YOLO26

Input

img_ori

Image instance to be drawn

Input

From read_img or pl.osd_img

Return Value

Return Value

Description

None

Example Program#

Below is an example program for the YOLO26 segmentation task:

from libs.YOLO import YOLO26
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # This is only an example, please modify to your own test image, model path, label names, model input size, number of keypoints, and keypoint dimension for custom scenarios
    img_path="/sdcard/examples/utils/test_pose.jpg"
    kmodel_path="/sdcard/examples/kmodel/yolo26n-pose.kmodel"
    labels = ['person']
    model_input_size=[320,320]
    kp_num=17
    kp_dim=3

    confidence_threshold = 0.5
    nms_threshold=0.45
    img,img_ori=read_image(img_path)
    rgb888p_size=[img.shape[2],img.shape[1]]
    # Initialize YOLO26 model
    yolo=YOLO26(task_type="pose",mode="image",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,kp_num=kp_num,kp_dim=kp_dim,conf_thresh=confidence_threshold,max_boxes_num=100,debug_mode=0)
    yolo.config_preprocess()
    res=yolo.run(img)
    print(res)
    yolo.draw_result(res,img_ori)
    yolo.deinit()
    gc.collect()

The above code gives the code for performing image inference using YOLO26.

from libs.PipeLine import PipeLine
from libs.YOLO import YOLO26
from libs.Utils import *
import os,sys,gc
import ulab.numpy as np
import image

if __name__=="__main__":
    # This is only an example, please modify to your own model path, label names, model input size, number of keypoints, and keypoint dimension for custom scenarios
    kmodel_path="/sdcard/examples/kmodel/yolo26n-pose.kmodel"
    labels = ["person"]
    model_input_size=[320,320]
    kp_num=17
    kp_dim=3

    # Add display mode, default is hdmi, options are hdmi/lcd/lt9611/st7701/hx8399, among which hdmi defaults to lt9611 with resolution 1920*1080; lcd defaults to st7701 with resolution 800*480
    display_mode="lcd"
    rgb888p_size=[320,320]
    confidence_threshold = 0.5
    pl=PipeLine(rgb888p_size=rgb888p_size,display_mode=display_mode)
    pl.create()
    display_size=pl.get_display_size()
    # Initialize YOLO26 model
    yolo=YOLO26(task_type="pose",mode="video",kmodel_path=kmodel_path,labels=labels,rgb888p_size=rgb888p_size,model_input_size=model_input_size,display_size=display_size,kp_num=kp_num,kp_dim=kp_dim,conf_thresh=confidence_threshold,max_boxes_num=50,debug_mode=0)
    yolo.config_preprocess()
    while True:
        with ScopedTiming("total",1):
            img=pl.get_frame()
            res=yolo.run(img)
            yolo.draw_result(res,pl.osd_img)
            pl.show_image()
            gc.collect()
    yolo.deinit()
    pl.destroy()

The above code gives the code for performing video inference using YOLO26.

Comments list
Comments
Log in