PLUS Examples in Python code¶
Kneron PLUS is a API-based software library, which allows users to manipulate the AI devices.
In the Introduction, we have introduce the concept of inference flow containing these 3 main executions: Data Pre-processing, Inference, and Post-Processing.
Based on where the pre-processing is executed, there are two types of inference API has been provided in Kneron PLUS:
- Generic Image Inference : The pre-process is run on build-in AI chip KL730 via hardware component.
- Generic Data Inference : The pre-process is executed by users before running PLUS Inference API.
PLUS Examples in Python code provided in KNEO Pi are limited to these two usages. If you wish to explore the further usage of Kneron PLUS, please refer this document site for more information.
Examples¶
ScanDevice¶
This example shows how to use PLUS API to search the Kneron AI devices which were connected to KNEO Pi.
Without any external devices, you should always see the build-in KL730 in the result of this example.
[root@kneo-pi plus_python]# python ScanDevices.py
scanning kneron devices ...
number of Kneron devices found: 1
listing devices infomation as follows:
[0] USB scan index: '0'
[0] USB port ID: '5'
[0] Product ID: '0x732 (KL730)'
[0] USB link speed: 'UsbSpeed.KP_USB_SPEED_SUPER'
[0] USB port path: '5-1'
[0] KN number: '0x9011004'
[0] Connectable: 'True'
[0] Firmware: 'KDP2 Loader/L'
KL730DemoGenericImageInference¶
This example show the usage of the API kp.inference.generic_image_inference_send()
and kp.inference.generic_image_inference_receive()
.
Please refer this document for the detail information.
[root@kneo-pi plus_python]# python KL730DemoGenericImageInference.py
[Connect Device]
- Success
[Set Device Timeout]
- Success
[Upload Firmware]
- Success
[Upload Model]
- Success
[Read Image]
- Success
[Starting Inference Work]
- Starting inference loop 10 times
- ..........
[Retrieve Inference Node Output ]
- Success
[Result]
[{
"name": "output",
"shape": [
1,
255,
80,
80
],
"channels_ordering": "ChannelOrdering.KP_CHANNEL_ORDERING_CHW",
"num_data": 1632000,
"ndarray": [
...
]
}, {
"name": "618",
"shape": [
1,
255,
40,
40
],
"channels_ordering": "ChannelOrdering.KP_CHANNEL_ORDERING_CHW",
"num_data": 408000,
"ndarray": [
...
]
}, {
"name": "620",
"shape": [
1,
255,
20,
20
],
"channels_ordering": "ChannelOrdering.KP_CHANNEL_ORDERING_CHW",
"num_data": 102000,
"ndarray": [
...
]
}]
KL730DemoGenericDataInference¶
This example show the usage of the API kp.inference.generic_data_inference_send()
and kp.inference.generic_data_inference_receive()
.
Please refer this document for the detail information.
Info
This example also shows how to implement a post-process for the YOLO raw output data.
[root@kneo-pi plus_python]# python KL730DemoGenericDataInference.py
[Connect Device]
- Success
- Success
[Set Device Timeout]
- Success
[Upload Model]
- Success
[Prepare NPU Inference Data]
- Success
[Starting Inference Work]
- Starting inference loop 100 times
- ....................................................................................................
[Retrieve Inference Node Output ]
- Success
[Yolo V5 Post-Processing]
- Success
[Result]
{
"class_count": 80,
"box_count": 12,
"box_list": {
"0": {
"x1": 183,
"y1": 260,
"x2": 398,
"y2": 594,
"score": 0.8837,
"class_num": 0
},
...
}
}
KL730DemoCamGenericImageInferenceDropFrame¶
This example provdes the usage of getting image from webcam via OpenCV, and displaying the image with bounding boxes, which is the result of post-processing from the inference raw output.
The default device path of the webcam is set to /dev/video8, which may not be the same everytime due to the timing when the webcam is connected to KNEO Pi.
To search the device path of webcam, please use the command:
$ v4l2-ctl --list-devices
[root@kneo-pi ~]# v4l2-ctl --list-devices
vpl_voc2.0 (platform:vpl_voc):
/dev/video0
/dev/video1
/dev/video2
/dev/video3
/dev/video4
/dev/video5
/dev/video6
/dev/video7
USB2.0 Camera: USB2.0 Camera (usb-xhci-hcd.1.auto-1):
/dev/video8
/dev/video9
/dev/media0
Info
This example also shows how to implement a post-process for the YOLO raw output data.
[root@kneo-pi plus_python]# python KL730DemoCamGenericImageInferenceDropFrame.py
[Connect Device]
- Success
[Set Device Timeout]
- Success
[Upload Firmware]
- Success
[Upload Model]
- Success
[Model NEF Information]
{
...
}
[Configure Inference Settings]
- Success
[Starting Inference Work]
- Starting inference
KL730End2EndTutorialYoloV7¶
This example provdes how to run the example model generated from end to end model convert tutorial. To see the pidnet model conversion tutorial, check Create your own model - yoloV7
Info
For easier demo, we some extract postprocess from original yolov7 repository to this example code.
[root@kneo-pi plus_python]# python KL730End2EndTutorialYoloV7.py
[Connect Device]
- Success
[Upload Firmware]
- Success
[Upload Model]
- Success
[Starting Inference Work]
- Success
[Retrieve Inference Node Output ]
- Success
[Post Process]
save result to /media/eric/data/misc/kneopi-e2e-example/kneopi-examples/kneopi_on_board_inf.png
KL730End2EndTutorialPidnet¶
This example provdes how to run the example model generated from end to end model convert tutorial. To see the pidnet model conversion tutorial, check Create your own model - pidnet
Info
For easier demo, we some extract postprocess from original pidnet repository to this example code.
[root@kneo-pi plus_python]# python KL730End2EndTutorialPidnet.py
[Connect Device]
- Success
[Upload Firmware]
- Success
[Upload Model]
- Success
[Starting Inference Work]
- Success
[Retrieve Inference Node Output ]
- Success
[Post Process]
save result to /***YOUR_PATH***/kneopi-examples/kneopi_on_board_inf.png