MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / inference_image_based_model

Function inference_image_based_model

detrsmpl/apis/inference.py:88–201  ·  view source on GitHub ↗

Inference a single image with a list of person bounding boxes. Args: model (nn.Module): The loaded pose model. img_or_path (Union[str, np.ndarray]): Image filename or loaded image. det_results (List(dict)): the item in the dict may contain 'bbox' and/or 'trac

(
    model,
    img_or_path,
    det_results,
    bbox_thr=None,
    format='xywh',
)

Source from the content-addressed store, hash-verified

86
87
88def inference_image_based_model(
89 model,
90 img_or_path,
91 det_results,
92 bbox_thr=None,
93 format='xywh',
94):
95 """Inference a single image with a list of person bounding boxes.
96
97 Args:
98 model (nn.Module): The loaded pose model.
99 img_or_path (Union[str, np.ndarray]): Image filename or loaded image.
100 det_results (List(dict)): the item in the dict may contain
101 'bbox' and/or 'track_id'.
102 'bbox' (4, ) or (5, ): The person bounding box, which contains
103 4 box coordinates (and score).
104 'track_id' (int): The unique id for each human instance.
105 bbox_thr (float, optional): Threshold for bounding boxes.
106 Only bboxes with higher scores will be fed into the pose detector.
107 If bbox_thr is None, ignore it. Defaults to None.
108 format (str, optional): bbox format ('xyxy' | 'xywh'). Default: 'xywh'.
109 'xyxy' means (left, top, right, bottom),
110 'xywh' means (left, top, width, height).
111
112 Returns:
113 list[dict]: Each item in the list is a dictionary,
114 containing the bbox: (left, top, right, bottom, [score]),
115 SMPL parameters, vertices, kp3d, and camera.
116 """
117 # only two kinds of bbox format is supported.
118 assert format in ['xyxy', 'xywh']
119 mesh_results = []
120 if len(det_results) == 0:
121 return []
122
123 # Change for-loop preprocess each bbox to preprocess all bboxes at once.
124 bboxes = np.array([box['bbox'] for box in det_results])
125
126 # Select bboxes by score threshold
127 if bbox_thr is not None:
128 assert bboxes.shape[1] == 5
129 valid_idx = np.where(bboxes[:, 4] > bbox_thr)[0]
130 bboxes = bboxes[valid_idx]
131 det_results = [det_results[i] for i in valid_idx]
132
133 if format == 'xyxy':
134 bboxes_xyxy = bboxes
135 bboxes_xywh = xyxy2xywh(bboxes)
136 else:
137 # format is already 'xywh'
138 bboxes_xywh = bboxes
139 bboxes_xyxy = xywh2xyxy(bboxes)
140
141 # if bbox_thr remove all bounding box
142 if len(bboxes_xywh) == 0:
143 return []
144
145 cfg = model.cfg

Callers

nothing calls this directly

Calls 8

xyxy2xywhFunction · 0.90
xywh2xyxyFunction · 0.90
ComposeClass · 0.90
box2csFunction · 0.90
LoadImageClass · 0.85
parametersMethod · 0.80
copyMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected