当前位置: 首页>>代码示例>>Python>>正文


Python apis.init_detector方法代码示例

本文整理汇总了Python中mmdet.apis.init_detector方法的典型用法代码示例。如果您正苦于以下问题:Python apis.init_detector方法的具体用法?Python apis.init_detector怎么用?Python apis.init_detector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mmdet.apis的用法示例。


在下文中一共展示了apis.init_detector方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def main():
    parser = ArgumentParser()
    parser.add_argument('img', help='Image file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--score-thr', type=float, default=0.3, help='bbox score threshold')
    args = parser.parse_args()

    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    result = inference_detector(model, args.img)
    # show the results
    show_result_pyplot(model, args.img, result, score_thr=args.score_thr) 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:19,代码来源:image_demo.py

示例2: main

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def main():
    args = parse_args()

    device = torch.device(args.device)

    model = init_detector(args.config, args.checkpoint, device=device)

    camera = cv2.VideoCapture(args.camera_id)

    print('Press "Esc", "q" or "Q" to exit.')
    while True:
        ret_val, img = camera.read()
        result = inference_detector(model, img)

        ch = cv2.waitKey(1)
        if ch == 27 or ch == ord('q') or ch == ord('Q'):
            break

        model.show_result(
            img, result, score_thr=args.score_thr, wait_time=1, show=True) 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:22,代码来源:webcam_demo.py

示例3: main

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def main():
    args = parse_args()

    model = init_detector(
        args.config, args.checkpoint, device=torch.device('cuda', args.device))

    camera = cv2.VideoCapture(args.camera_id)

    print('Press "Esc", "q" or "Q" to exit.')
    while True:
        ret_val, img = camera.read()
        result = inference_detector(model, img)

        ch = cv2.waitKey(1)
        if ch == 27 or ch == ord('q') or ch == ord('Q'):
            break

        show_result(
            img, result, model.CLASSES, score_thr=args.score_thr, wait_time=1) 
开发者ID:tascj,项目名称:kaggle-kuzushiji-recognition,代码行数:21,代码来源:webcam_demo.py

示例4: __init__

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def __init__(self,
                 model_config,
                 checkpoint=None,
                 streamqueue_size=3,
                 device='cuda:0'):

        self.streamqueue_size = streamqueue_size
        self.device = device
        # build the model and load checkpoint
        self.model = init_detector(
            model_config, checkpoint=None, device=self.device)
        self.streamqueue = None 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:14,代码来源:test_async.py

示例5: main

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def main():
    args = parse_args()
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint)
    # fuse conv and bn layers of the model
    fused_model = fuse_module(model)
    save_checkpoint(fused_model, args.out) 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:9,代码来源:fuse_conv_bn.py

示例6: __init__

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def __init__(self,
                 config_file,
                 checkpoint_file):
        # init RoITransformer
        self.config_file = config_file
        self.checkpoint_file = checkpoint_file
        self.cfg = Config.fromfile(self.config_file)
        self.data_test = self.cfg.data['test']
        self.dataset = get_dataset(self.data_test)
        self.classnames = self.dataset.CLASSES
        self.model = init_detector(config_file, checkpoint_file, device='cuda:0') 
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:13,代码来源:demo_large_image.py

示例7: main

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def main():
    args = parse_args()

    # build the model from a config file and a checkpoint file
    model = init_detector(args.config_file, args.checkpoint, device='cuda:0')

    # test a single image and show the results
    img = args.input
    result = inference_detector(model, img)

    # visualize the results in a new window
    # or save the visualization results to image files
    show_result(
        img, result, model.CLASSES, out_file=img.split('.')[0] + '_result.jpg') 
开发者ID:open-mmlab,项目名称:mmfashion,代码行数:16,代码来源:demo.py

示例8: main

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def main():
    args = parse_args()
    model = init_detector(args.config, args.checkpoint, device='cuda:0')
    result = inference_detector(model, args.input)
    result = result[:-1]  # ignore dummy
    show_result(
        args.input,
        result,
        CLASS_NAMES,
        show=False,
        out_file=args.output,
    ) 
开发者ID:tascj,项目名称:kaggle-kuzushiji-recognition,代码行数:14,代码来源:inference.py

示例9: inference

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def inference(detection_cfg,
              skeleton_cfg,
              dataset_cfg,
              batch_size,
              gpus=1,
              workers=4):

    dataset = call_obj(**dataset_cfg)
    data_loader = torch.utils.data.DataLoader(dataset=dataset,
                                              batch_size=batch_size * gpus,
                                              shuffle=False,
                                              num_workers=workers * gpus)

    # build detection model
    detection_model_file = detection_cfg.model_cfg
    detection_checkpoint_file = detection_cfg.checkpoint_file

    detection_model = init_detector(detection_model_file,
                                    detection_checkpoint_file,
                                    device='cuda:0')
    from IPython import embed
    embed()
    detection_model = MMDataParallel(detection_model,
                                     device_ids=range(gpus)).cuda()

    # skeleton_model_file = skeleton_cfg.model_file
    # skeleton_checkpint_file = skeleton_cfg.checkpoint_file
    # skeleton_model = init_twodimestimator(skeleton_model_file,
    #                                       skeleton_checkpint_file,
    #                                       device='cpu')
    # skeleton_model = MMDataParallel(skeleton_model, device_ids=range(gpus)).cuda()

    for idx, image in enumerate(data_loader):
        skeleton_resluts = inference_model(image, detection_model,
                                           skeleton_model)
    return skeleton_resluts 
开发者ID:open-mmlab,项目名称:mmskeleton,代码行数:38,代码来源:twodimestimation.py

示例10: worker

# 需要导入模块: from mmdet import apis [as 别名]
# 或者: from mmdet.apis import init_detector [as 别名]
def worker(video_file, index, detection_cfg, skeleton_cfg, skeleon_data_cfg,
           device, result_queue):
    os.environ["CUDA_VISIBLE_DEVICES"] = str(device)
    video_frames = mmcv.VideoReader(video_file)

    # load model
    detection_model_file = detection_cfg.model_cfg
    detection_checkpoint_file = get_mmskeleton_url(
        detection_cfg.checkpoint_file)
    detection_model = init_detector(detection_model_file,
                                    detection_checkpoint_file,
                                    device='cpu')
    skeleton_model_file = skeleton_cfg.model_cfg
    skeletion_checkpoint_file = skeleton_cfg.checkpoint_file
    skeleton_model = init_twodimestimator(skeleton_model_file,
                                          skeletion_checkpoint_file,
                                          device='cpu')

    detection_model = detection_model.cuda()
    skeleton_model = skeleton_model.cuda()

    for idx in index:
        skeleton_result = dict()
        image = video_frames[idx]
        draw_image = image.copy()
        bbox_result = inference_detector(detection_model, image)

        person_bbox, labels = VideoDemo.bbox_filter(bbox_result,
                                                    detection_cfg.bbox_thre)

        if len(person_bbox) > 0:
            person, meta = VideoDemo.skeleton_preprocess(
                image[:, :, ::-1], person_bbox, skeleon_data_cfg)
            preds, maxvals = inference_twodimestimator(skeleton_model,
                                                       person.cuda(), meta,
                                                       True)
            results = VideoDemo.skeleton_postprocess(preds, maxvals, meta)
            if skeleon_data_cfg.save_video:
                file = os.path.join(skeleon_data_cfg.img_dir,
                                    '{}.png'.format(idx))
                mmcv.imshow_det_bboxes(draw_image,
                                       person_bbox,
                                       labels,
                                       detection_model.CLASSES,
                                       score_thr=detection_cfg.bbox_thre,
                                       show=False,
                                       wait_time=0)
                save(image, draw_image, results, file)

        else:
            preds, maxvals = None, None
            if skeleon_data_cfg.save_video:
                file = os.path.join(skeleon_data_cfg.img_dir,
                                    '{}.png'.format(idx))
                mmcv.imwrite(image, file)
        skeleton_result['frame_index'] = idx
        skeleton_result['position_preds'] = preds
        skeleton_result['position_maxvals'] = maxvals
        result_queue.put(skeleton_result) 
开发者ID:open-mmlab,项目名称:mmskeleton,代码行数:61,代码来源:image2skeleton.py


注:本文中的mmdet.apis.init_detector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。