本文整理汇总了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]