Web Analytics

Quickstart for beginners

This short introduction use kp to build simple edge AI application by following steps:

  1. Connect Kneron device
  2. Upload SCPU/NCPU firmware
  3. Upload NEF model
  4. Inference image

Note 1: Please using pip to install kp API and opencv-python before the following tutorial. See the Installation for details.

Note 2: Please using kneronDFUT to upgrade firmware from KDP to KDP2 before the following tutorial. See the Upgrade AI Device to KDP2 for details.


Import kp and cv2 into your program:

import kp
import cv2

Get one Kneron device USB port ID for connecting:

device_descriptors = kp.core.scan_devices()

if 0 < device_descriptors.device_descriptor_number:
    usb_port_id = device_descriptors.device_descriptor_list[0].usb_port_id
else:
    print('Error: no Kneron device connect.')
    exit(0)

Connect the device and get Kneron device handler (Device Group):

device_group = kp.core.connect_devices(usb_port_ids=[usb_port_id])

Set timeout of the USB communication (Default: infinity wait):

kp.core.set_timeout(device_group=device_group,
                    milliseconds=5000)

Upload firmware to Kneron device:

Please replace SCPU_FW_PATH, NCPU_FW_PATH by fw_scpu.bin and fw_ncpu.bin path (Please find target device firmware under res/firmware folder)

SCPU_FW_PATH = 'res/firmware/KL520/fw_scpu.bin'
NCPU_FW_PATH = 'res/firmware/KL520/fw_ncpu.bin'
kp.core.load_firmware_from_file(device_group=device_group,
                                scpu_fw_path=SCPU_FW_PATH,
                                ncpu_fw_path=NCPU_FW_PATH)

Upload NEF model to Kneron device:

Please replace MODEL_FILE_PATH by models_520.nef path (Please find target device NEF model under res/models folder)

MODEL_FILE_PATH = 'res/models/KL520/tiny_yolo_v3/models_520.nef'
model_nef_descriptor = kp.core.load_model_from_file(device_group=device_group,
                                                    file_path=MODEL_FILE_PATH)

Inference image: