def test_gpu_api(): if not hasattr(ncnn, "get_gpu_count"): return assert ncnn.create_gpu_instance() == 0 assert ncnn.get_gpu_count() > 0 assert ncnn.get_default_gpu_index() >= 0 gpuinfo = ncnn.get_gpu_info(0) check_gpuinfo(gpuinfo) vkdev = ncnn.get_gpu_device(0) assert vkdev is not None gpuinfo = vkdev.info() check_gpuinfo(gpuinfo) ncnn.destroy_gpu_instance()
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: ncnn.destroy_gpu_instance() draw_detection_objects(m, net.class_names, objects)
def __init__(self): ncnn.create_gpu_instance()