Example #1
0
import sys
import cv2
import numpy as np
import ncnn
from ncnn.model_zoo import get_model
from ncnn.utils import draw_detection_objects

use_gpu = False
if ncnn.build_with_gpu():
    use_gpu = True

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: %s [imagepath]\n" % (sys.argv[0]))
        sys.exit(0)

    imagepath = sys.argv[1]

    m = cv2.imread(imagepath)
    if m is None:
        print("cv2.imread %s failed\n" % (imagepath))
        sys.exit(0)

    if use_gpu:
        ncnn.create_gpu_instance()

    net = get_model('mobilenet_ssd', num_threads=4, use_gpu=use_gpu)

    objects = net(m)

    if use_gpu:
Example #2
0
    loop_count = 4
    num_threads = ncnn.get_cpu_count()
    powersave = 0
    gpu_device = 0

    argc = len(sys.argv)
    if argc >= 2:
        loop_count = int(sys.argv[1])
    if argc >= 3:
        num_threads = int(sys.argv[2])
    if argc >= 4:
        powersave = int(sys.argv[3])
    if argc >= 5:
        gpu_device = int(sys.argv[4])

    if ncnn.build_with_gpu() == False:
        print(
            'ncnn is not build with gpu(NCNN_VULKAN), please rebuild with gpu')
        sys.exit(0)

    g_loop_count = loop_count

    g_blob_pool_allocator.set_size_compare_ratio(0.0)
    g_workspace_pool_allocator.set_size_compare_ratio(0.5)

    g_warmup_loop_count = 10

    g_vkdev = ncnn.get_gpu_device(gpu_device)

    g_blob_vkallocator = ncnn.VkBlobBufferAllocator(g_vkdev)
    g_staging_vkallocator = ncnn.VkStagingBufferAllocator(g_vkdev)