Ejemplo n.º 1
0
def user_test_single_dme(dev_idx, loop):
    """Test single dme."""
    # load model into Kneron device
    model_path = "../test_images/dme_yolo_224"
    kdp_wrapper.kdp_dme_load_yolo_model(dev_idx, model_path)

    image_source_h = 480
    image_source_w = 640
    image_size = image_source_w * image_source_h * 2
    frames = []
    app_id = constants.APP_TINY_YOLO3

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    # Send 1 image to the DME image buffers.
    ret, ssid = kdp_wrapper.dme_fill_buffer(dev_idx, capture, image_size,
                                            frames)
    if ret:
        return -1

    kdp_wrapper.dme_pipeline_inference(dev_idx, app_id, loop, image_size,
                                       capture, ssid, frames, handle_result)

    kdp_wrapper.kdp_exit_dme(dev_idx)
Ejemplo n.º 2
0
def user_test_cam_sync_yolo(dev_idx, _user_id, test_loop):
    """User test cam yolo."""
    image_source_w = 640
    image_source_h = 480
    image_size = image_source_w * image_source_h * 2
    frames = []

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    # Start ISI mode.
    if kdp_wrapper.start_isi(dev_idx, ISI_YOLO_ID, image_source_w,
                             image_source_h):
        return -1

    # Fill up the image buffers.
    img_id_tx = 0
    start_time = time.time()
    while (img_id_tx != test_loop):
        kdp_wrapper.sync_inference(dev_idx, ISI_YOLO_ID, image_size, capture,
                                   img_id_tx, frames, handle_result)
        img_id_tx += 1
    end_time = time.time()
    diff = end_time - start_time
    estimate_runtime = float(diff / test_loop)
    fps = float(1 / estimate_runtime)
    print("Sync inference average estimate runtime is ", estimate_runtime)
    print("Average FPS is ", fps)

    return 0
Ejemplo n.º 3
0
def user_test_single_dme(dev_idx, loop):
    """Test single dme."""
    # load model into Kneron device
    model_path = "../test_images/dme_ssd_fd"
    is_raw_ouput  = True

    kdp_wrapper.kdp_dme_load_ssd_model(dev_idx, model_path, is_raw_ouput)
    image_source_h = 480
    image_source_w = 640
    image_size = image_source_w * image_source_h * 2
    frames = []
    app_id = 0 # if app_id is 0, output raw data for kdp_wrapper.kdp_dme_inference

    # the parameters for postprocess
    anchor_path       = './examples/fdssd/models/anchor_face.npy'
    model_input_shape = (200, 200)
    score_thres       = 0.5
    nms_thres         = 0.35
    only_max          = False

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    while (loop):
        raw_res = kdp_wrapper.kdp_dme_inference(dev_idx, app_id, capture, image_size, frames)

        det_res = postprocess_(raw_res, anchor_path, model_input_shape,
                            image_source_w, image_source_h, score_thres, only_max, nms_thres)

        draw_result(dev_idx, det_res, frames)
        loop -= 1

    kdp_wrapper.kdp_exit_dme(dev_idx)
Ejemplo n.º 4
0
def user_test_single_dme(dev_idx, loop):
    """Test single dme."""
    # load model into Kneron device
    model_path = "../test_images/dme_ssd_fd"
    is_raw_ouput  = False
    kdp_wrapper.kdp_dme_load_ssd_model(dev_idx, model_path, False)

    image_source_h = 480
    image_source_w = 640
    image_size = image_source_w * image_source_h * 2
    frames = []
    app_id = constants.APP_FD_LM

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    while (loop):
        det_res = kdp_wrapper.kdp_dme_inference(dev_idx, app_id, capture, image_size, frames)
        draw_result(dev_idx, det_res, frames)
        loop -= 1
        # print("Total class {}: total detection {}".format(det_res[0], det_res[1]))
        # for i in range(det_res[1]):
        #     print("x1,y1,x2,y2:", det_res[4*i+2],det_res[4*i+3],det_res[4*i+4],det_res[4*i+5])

    kdp_wrapper.kdp_exit_dme(dev_idx)
Ejemplo n.º 5
0
def user_test_cam_ssd_fd(dev_idx, _user_id, test_loop):
    """User test cam yolo."""
    image_source_h = 480
    image_source_w = 640
    app_id = constants.APP_FD_LM
    image_size = image_source_w * image_source_h * 2
    frames = []

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    # Start ISI mode.
    if kdp_wrapper.start_isi(dev_idx, app_id, image_source_w, image_source_h):
        return -1

    # Fill up the image buffers.
    ret, img_id_tx, img_left, buffer_depth = kdp_wrapper.fill_buffer(
        dev_idx, capture, image_size, frames)
    if ret:
        return -1

    # Send the rest and get result in loop, with 2 images alternatively
    print("Companion image buffer depth = ", buffer_depth)
    return kdp_wrapper.pipeline_inference(dev_idx, app_id, test_loop,
                                          image_size, capture, img_id_tx,
                                          img_left, buffer_depth, frames,
                                          handle_result)
Ejemplo n.º 6
0
def user_test_cam_yolo(dev_idx, _user_id, test_loop):
    """User test cam yolo."""
    image_source_h = 480
    image_source_w = 640
    app_id = constants.APP_TINY_YOLO3
    image_size = image_source_w * image_source_h * 2
    frames = []

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    # Start ISI mode.
    if kdp_wrapper.start_isi_parallel(dev_idx, app_id, image_source_w, image_source_h):
        return -1

    start_time = time.time()
    # Fill up the image buffers.
    ret, img_id_tx, img_left, buffer_depth = kdp_wrapper.fill_buffer(
        dev_idx, capture, image_size, frames)
    if ret:
        return -1

    # Send the rest and get result in loop, with 2 images alternatively
    print("Companion image buffer depth = ", buffer_depth)
    kdp_wrapper.pipeline_inference(
        dev_idx, app_id, test_loop - buffer_depth, image_size,
        capture, img_id_tx, img_left, buffer_depth, frames, handle_result)

    end_time = time.time()
    diff = end_time - start_time 
    estimate_runtime = float(diff/test_loop)
    fps = float(1/estimate_runtime)    
    print("Parallel inference average estimate runtime is ", estimate_runtime)
    print("Average FPS is ", fps)

    return 0    
Ejemplo n.º 7
0
def detect_camera(dev_idx, user_id):

    # Initialize camera capture parameters
    frames      = []
    img_id_tx   = 0

    # Setup webcam capture
    capture     = kdp_wrapper.setup_capture(0, IMG_SRC_WIDTH, IMG_SRC_HEIGHT)
    if capture is None:
        print("Can't open webcam")
        return -1

    # Start ISI mode
    if (kdp_wrapper.start_isi(dev_idx, ISI_YOLO_ID, IMG_SRC_WIDTH, IMG_SRC_HEIGHT)):
        return -1

    # Perform video inference
    while True:
        kdp_examples.camera_inference(dev_idx, ISI_YOLO_ID, image_size, capture, img_id_tx, frames)
        img_id_tx += 1

    capture.release()
    cv2.destroyAllWindows()
Ejemplo n.º 8
0
def user_test_single_dme(dev_idx, loop):
    """Test single dme."""
    # load model into Kneron device
    model_path = "../test_images/dme_yolo_224"
    kdp_wrapper.kdp_dme_load_yolo_model(dev_idx, model_path)

    image_source_h = 480
    image_source_w = 640
    image_size = image_source_w * image_source_h * 2
    frames = []
    app_id = constants.APP_TINY_YOLO3

    # the parameters for postprocess
    anchor_path       = './examples/yolo/models/anchors.txt'
    class_path        = './common/coco_name_lists'
    model_input_shape = (224, 224)
    score_thres       = 0.2
    nms_thres         = 0.45
    keep_aspect_ratio = True

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    while (loop):
        raw_res = kdp_wrapper.kdp_dme_inference(dev_idx, app_id, capture, image_size, frames)

        dets = yolo_postprocess_(raw_res, anchor_path, class_path, image_source_h, image_source_w, model_input_shape,
                                 score_thres, nms_thres, keep_aspect_ratio)

        # print("dets: ", dets)

        draw_result(dev_idx, dets, frames)
        loop -= 1

    kdp_wrapper.kdp_exit_dme(dev_idx)
Ejemplo n.º 9
0
if (kdp_lib_init() < 0):
    print("Initialize kdp host lib failure\n")

print("Add kdp device ....")
dev_idx = kdp_add_dev(KDP_USB_DEV, "")
if (dev_idx < 0):
    print("Add kdp device failure\n")

print("Start kdp host lib ....\n")
if (kdp_lib_start() < 0):
    print("Start kdp host lib failure")

print("Start kdp task: ", args.task_name)

# Setup video capture device.
capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
if capture is None:
    exit()

if (args.task_name == "serial"):

    # Start ISI mode.
    if kdp_wrapper.start_isi(dev_idx, app_id, image_source_w, image_source_h):
        exit()

    img_id_tx = 0
    start_time = time.time()
    while (img_id_tx != loop_count):
        kdp_wrapper.sync_inference(dev_idx, app_id, image_size, capture,
                                   img_id_tx, frames, handle_result)
        img_id_tx += 1