本文整理匯總了Python中utils.image.transform_preds方法的典型用法代碼示例。如果您正苦於以下問題:Python image.transform_preds方法的具體用法?Python image.transform_preds怎麽用?Python image.transform_preds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utils.image
的用法示例。
在下文中一共展示了image.transform_preds方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: demo_image
# 需要導入模塊: from utils import image [as 別名]
# 或者: from utils.image import transform_preds [as 別名]
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()
示例2: multi_pose_post_process
# 需要導入模塊: from utils import image [as 別名]
# 或者: from utils.image import transform_preds [as 別名]
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
示例3: convert_eval_format
# 需要導入模塊: from utils import image [as 別名]
# 或者: from utils.image import transform_preds [as 別名]
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
示例4: convert_eval_format
# 需要導入模塊: from utils import image [as 別名]
# 或者: from utils.image import transform_preds [as 別名]
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
示例5: post_process
# 需要導入模塊: from utils import image [as 別名]
# 或者: from utils.image import transform_preds [as 別名]
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]