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

Method inference

datasets/INFERENCE_demo.py:107–168  ·  view source on GitHub ↗
(self, outs)

Source from the content-addressed store, hash-verified

105 return result
106
107 def inference(self, outs):
108 img_paths = self.img_paths
109 for out in outs:
110 ann_idx = out['image_idx']
111 scores = out['scores'].clone().cpu().numpy()
112 img_shape = out['img_shape'].cpu().numpy()[::-1] # w, h
113 img = cv2.imread(img_paths[ann_idx]) # h, w
114 scale = img.shape[1]/img_shape[0]
115 body_bbox = out['body_bbox'].clone().cpu().numpy()
116 body_bbox = body_bbox * scale
117 joint_3d, _ = convert_kps(out['smpl_kp3d'].clone().cpu().numpy(),src='smplx',dst='smplx', approximate=True)
118
119 for i, score in enumerate(scores):
120 if score < self.score_threshold:
121 break
122 if i>self.num_person:
123 break
124 save_name = img_paths[ann_idx].split('/')[-1]
125 save_name = save_name.split('.')[0]
126 vert = out['smpl_verts'][i] + out['cam_trans'][i][None]
127 # save mesh
128 exist_result_path = glob(osp.join(self.mesh_path, save_name + '*'))
129 if len(exist_result_path) == 0:
130 person_idx = 0
131 else:
132 last_person_idx = max([
133 int(name.split('personId_')[1].split('.obj')[0])
134 for name in exist_result_path
135 ])
136 person_idx = last_person_idx + 1
137
138 save_name += '_personId_' + str(person_idx) + '.obj'
139 save_obj(osp.join(self.mesh_path, save_name), vert, faces=torch.tensor(self.body_model.faces.astype(np.int32)))
140
141 if i == 0:
142 save_name = img_paths[ann_idx].split('/')[-1][:-4]
143 cv2.imwrite(os.path.join(self.result_img_dir,img_paths[ann_idx].split('/')[-1]), img)
144 else:
145 verts = out['smpl_verts'][:i] + out['cam_trans'][:i][:, None]
146 img = mmcv.imshow_bboxes(img, body_bbox[:i], show=False, colors='green')
147 render_smpl(
148 verts=verts[None],
149 body_model=self.body_model,
150 K= np.array(
151 [[5000, 0, img_shape[0]/2],
152 [0, 5000, img_shape[1]/2],
153 [0, 0, 1]]),
154 R=None,
155 T=None,
156 output_path=os.path.join(self.result_img_dir,img_paths[ann_idx].split('/')[-1]),
157 image_array=cv2.resize(img, (img_shape[0],img_shape[1]), cv2.INTER_CUBIC),
158 in_ndc=False,
159 alpha=0.9,
160 convention='opencv',
161 projection='perspective',
162 overwrite=True,
163 no_grad=True,
164 device='cuda',

Callers

nothing calls this directly

Calls 4

convert_kpsFunction · 0.90
render_smplFunction · 0.90
save_objFunction · 0.85
cloneMethod · 0.80

Tested by

no test coverage detected