本文整理匯總了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)
示例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)
示例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)
示例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
示例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)
示例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')
示例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')
示例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,
)
示例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
示例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)