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

Method forward

models/aios/postprocesses.py:1234–1511  ·  view source on GitHub ↗
(self, outputs, target_sizes, targets, data_batch_nc, not_to_xyxy=False, test=False)

Source from the content-addressed store, hash-verified

1232
1233 @torch.no_grad()
1234 def forward(self, outputs, target_sizes, targets, data_batch_nc, not_to_xyxy=False, test=False):
1235 # import pdb; pdb.set_trace()
1236 batch_size = outputs['pred_smpl_beta'].shape[0]
1237 results = []
1238 device = outputs['pred_smpl_beta'].device
1239 for body_model in self.body_model.values():
1240 body_model.to(device)
1241 # test with instance num
1242 # num_select=data_batch_nc['joint_img'][0].shape[0]
1243 num_select = self.num_select
1244 out_logits, out_bbox= outputs['pred_logits'], outputs['pred_boxes']
1245
1246 out_smpl_pose, out_smpl_beta, out_smpl_expr, out_smpl_cam, out_smpl_kp3d, out_smpl_verts = \
1247 outputs['pred_smpl_fullpose'], outputs['pred_smpl_beta'], outputs['pred_smpl_expr'], \
1248 outputs['pred_smpl_cam'], outputs['pred_smpl_kp3d'], outputs['pred_smpl_verts']
1249
1250 out_smpl_kp2d = []
1251
1252 for bs in range(batch_size):
1253 out_kp3d_i = out_smpl_kp3d[bs]
1254 out_cam_i = out_smpl_cam[bs]
1255 out_img_shape = data_batch_nc['img_shape'][bs].flip(-1)[None]
1256 # out_kp3d_i = out_kp3d_i - out_kp3d_i[:, [0]]
1257 out_kp2d_i = project_points_new(
1258 points_3d=out_kp3d_i,
1259 pred_cam=out_cam_i,
1260 focal_length=5000,
1261 camera_center=out_img_shape/2
1262 )
1263 out_smpl_kp2d.append(out_kp2d_i.detach().cpu().numpy())
1264 out_smpl_kp2d = torch.tensor(out_smpl_kp2d).to(device)
1265
1266
1267 assert len(out_logits) == len(target_sizes)
1268 assert target_sizes.shape[1] == 2
1269
1270 prob = out_logits.sigmoid()
1271 topk_values, topk_indexes = \
1272 torch.topk(prob.view(out_logits.shape[0], -1), num_select, dim=1)
1273 scores = topk_values
1274
1275 # bbox
1276 topk_boxes = topk_indexes // out_logits.shape[2]
1277 labels = topk_indexes % out_logits.shape[2]
1278
1279 if not_to_xyxy:
1280 boxes = out_bbox
1281 else:
1282 boxes = box_ops.box_cxcywh_to_xyxy(out_bbox)
1283
1284 if test:
1285 assert not not_to_xyxy
1286 boxes[:,:,2:] = boxes[:,:,2:] - boxes[:,:,:2]
1287
1288 # gather gt bbox
1289 boxes_norm = torch.gather(boxes, 1, topk_boxes.unsqueeze(-1).repeat(1,1,4))
1290 target_sizes = target_sizes.type_as(boxes)
1291 # from relative [0, 1] to absolute [0, height] coordinates

Callers

nothing calls this directly

Calls 7

project_points_newFunction · 0.90
convert_kpsFunction · 0.90
cloneMethod · 0.80
concatenateMethod · 0.80
valuesMethod · 0.45
toMethod · 0.45
detachMethod · 0.45

Tested by

no test coverage detected