Python utils.image.transform_preds() Examples

The following are 7 code examples of utils.image.transform_preds(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module utils.image , or try the search function .
Example #1
Source File: demo.py    From pytorch-pose-hg-3d with GNU General Public License v3.0 6 votes vote down vote up
def demo_image(image, model, opt):
  s = max(image.shape[0], image.shape[1]) * 1.0
  c = np.array([image.shape[1] / 2., image.shape[0] / 2.], dtype=np.float32)
  trans_input = get_affine_transform(
      c, s, 0, [opt.input_w, opt.input_h])
  inp = cv2.warpAffine(image, trans_input, (opt.input_w, opt.input_h),
                         flags=cv2.INTER_LINEAR)
  inp = (inp / 255. - mean) / std
  inp = inp.transpose(2, 0, 1)[np.newaxis, ...].astype(np.float32)
  inp = torch.from_numpy(inp).to(opt.device)
  out = model(inp)[-1]
  pred = get_preds(out['hm'].detach().cpu().numpy())[0]
  pred = transform_preds(pred, c, s, (opt.output_w, opt.output_h))
  pred_3d = get_preds_3d(out['hm'].detach().cpu().numpy(), 
                         out['depth'].detach().cpu().numpy())[0]
  
  debugger = Debugger()
  debugger.add_img(image)
  debugger.add_point_2d(pred, (255, 0, 0))
  debugger.add_point_3d(pred_3d, 'b')
  debugger.show_all_imgs(pause=False)
  debugger.show_3d() 
Example #2
Source File: centernet_tensorrt_engine.py    From centerpose with MIT License 5 votes vote down vote up
def multi_pose_post_process(self, dets, c, s, h, w):
        # dets: batch x max_dets x 40
        # return list of 39 in image coord
        ret = []
        for i in range(dets.shape[0]):
            bbox = transform_preds(dets[i, :, :4].reshape(-1, 2), c[i], s[i], (w, h))
            pts = transform_preds(dets[i, :, 5:39].reshape(-1, 2), c[i], s[i], (w, h))
            top_preds = np.concatenate(
                [bbox.reshape(-1, 4), dets[i, :, 4:5], 
                pts.reshape(-1, 34), dets[i, :, 39:56]], axis=1).astype(np.float32).tolist()
            ret.append({np.ones(1, dtype=np.int32)[0]: top_preds})
        return ret 
Example #3
Source File: coco.py    From pytorch-pose-hg-3d with GNU General Public License v3.0 5 votes vote down vote up
def convert_eval_format(self, pred, conf, meta):
    preds = np.zeros((pred.shape[0], pred.shape[1], 2))
    for i in range(pred.shape[0]):
      preds[i] = transform_preds(
        pred[i], meta['center'][i].numpy(), meta['scale'][i].numpy(), 
        [self.opt.output_h, self.opt.output_w])

    ret = []
    for i in range(pred.shape[0]):
      kpts = np.concatenate([preds[i], conf[i]], axis=1).astype(
        np.int32).reshape(self.num_joints * 3).tolist()
      score = int(meta['score'][i])
      ret.append({'category_id': 1, 'image_id': int(meta['image_id'].numpy()), \
                  'keypoints': kpts, 'score': score})
    return ret 
Example #4
Source File: mpii.py    From pytorch-pose-hg-3d with GNU General Public License v3.0 5 votes vote down vote up
def convert_eval_format(self, pred, conf, meta):
    ret = np.zeros((pred.shape[0], pred.shape[1], 2))
    for i in range(pred.shape[0]):
      ret[i] = transform_preds(
        pred[i], meta['center'][i].numpy(), meta['scale'][i].numpy(), 
        [self.opt.output_h, self.opt.output_w])
    return ret 
Example #5
Source File: exdet.py    From CenterNet-CondInst with MIT License 5 votes vote down vote up
def post_process(self, dets, meta, scale=1):
    out_width, out_height = meta['out_width'], meta['out_height']
    dets = dets.detach().cpu().numpy().reshape(2, -1, 14)
    dets[1, :, [0, 2]] = out_width - dets[1, :, [2, 0]]
    dets = dets.reshape(1, -1, 14)
    dets[0, :, 0:2] = transform_preds(
      dets[0, :, 0:2], meta['c'], meta['s'], (out_width, out_height))
    dets[0, :, 2:4] = transform_preds(
      dets[0, :, 2:4], meta['c'], meta['s'], (out_width, out_height))
    dets[:, :, 0:4] /= scale
    return dets[0] 
Example #6
Source File: exdet.py    From centerNet-deep-sort with GNU General Public License v3.0 5 votes vote down vote up
def post_process(self, dets, meta, scale=1):
    out_width, out_height = meta['out_width'], meta['out_height']
    dets = dets.detach().cpu().numpy().reshape(2, -1, 14)
    dets[1, :, [0, 2]] = out_width - dets[1, :, [2, 0]]
    dets = dets.reshape(1, -1, 14)
    dets[0, :, 0:2] = transform_preds(
      dets[0, :, 0:2], meta['c'], meta['s'], (out_width, out_height))
    dets[0, :, 2:4] = transform_preds(
      dets[0, :, 2:4], meta['c'], meta['s'], (out_width, out_height))
    dets[:, :, 0:4] /= scale
    return dets[0] 
Example #7
Source File: exdet.py    From CenterNet with MIT License 5 votes vote down vote up
def post_process(self, dets, meta, scale=1):
    out_width, out_height = meta['out_width'], meta['out_height']
    dets = dets.detach().cpu().numpy().reshape(2, -1, 14)
    dets[1, :, [0, 2]] = out_width - dets[1, :, [2, 0]]
    dets = dets.reshape(1, -1, 14)
    dets[0, :, 0:2] = transform_preds(
      dets[0, :, 0:2], meta['c'], meta['s'], (out_width, out_height))
    dets[0, :, 2:4] = transform_preds(
      dets[0, :, 2:4], meta['c'], meta['s'], (out_width, out_height))
    dets[:, :, 0:4] /= scale
    return dets[0]