File size: 1,432 Bytes
554b11d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from mmpose.apis import (inference_top_down_pose_model, init_pose_model,
                         process_mmdet_results, vis_pose_result)
from mmpose.datasets import DatasetInfo
from mmdet.apis import inference_detector, init_detector

det_model = init_detector(
    "./external/faster_rcnn_r50_fpn_coco.py", 
    "./faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth",
    device="cpu")
pose_model = init_pose_model(
    "./external/hrnet_w48_coco_256x192.py",
    "./hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth",
    device="cpu")

dataset = pose_model.cfg.data['test']['type']
dataset_info = pose_model.cfg.data['test'].get('dataset_info', None)

dataset_info = DatasetInfo(dataset_info)

def infer(image):
    mmdet_results = inference_detector(det_model, image)
    person_results = process_mmdet_results(mmdet_results, 1)

    pose_results, returned_outputs = inference_top_down_pose_model(
        pose_model,
        image,
        person_results,
        bbox_thr=0.3,
        format='xyxy',
        dataset=dataset,
        dataset_info=dataset_info,
        return_heatmap=False,
        outputs=None)

    return pose_results, returned_outputs

def draw(image, results):
    return vis_pose_result(
        pose_model,
        image,
        results,
        dataset=dataset,
        dataset_info=dataset_info,
        kpt_score_thr=0.3,
        radius=4,
        thickness=3,
        show=False,
        out_file=None)