本文整理汇总了Python中transform.Transform.revert方法的典型用法代码示例。如果您正苦于以下问题:Python Transform.revert方法的具体用法?Python Transform.revert怎么用?Python Transform.revert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transform.Transform
的用法示例。
在下文中一共展示了Transform.revert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Transform
# 需要导入模块: from transform import Transform [as 别名]
# 或者: from transform.Transform import revert [as 别名]
('data/FLIC-full', 7, flic_draw_joints, flic_swap_joints, 100),
('data/lspet_dataset', 14, lsp_draw_joints, lsp_swap_joints, 50),
('data/mpii', 16, mpii_draw_joints, mpii_swap_joints, 100)]:
args.datadir = datadir
args.joint_num = n_joints
args.min_dim = min_dim
# augmentation setting
trans = Transform(args, swap_joints)
# test data
test_fn = '%s/train_joints.csv' % args.datadir
test_dl = np.array([l.strip() for l in open(test_fn).readlines()])
result_dir = '%s/test_trans' % args.datadir
if not os.path.exists(result_dir):
os.makedirs(result_dir)
for i, line in enumerate(test_dl):
orig, input_data, label = load_data(trans, args, line)
input_data = input_data.transpose(
(0, 2, 3, 1))[0].astype(np.float32)
label = label.astype(np.float32).flatten()
cv.imwrite('%s/%d_orig.jpg' % (result_dir, i), orig)
img, label = trans.revert(input_data, label)
label = [tuple(l) for l in label]
pose = draw_joints(input_data.copy(), label)
cv.rectangle(pose, trans.bbox[0], trans.bbox[1], (0, 0, 255))
pose = np.array(pose.copy())
cv.imwrite('%s/%d_pose.jpg' % (result_dir, i), pose)
if i > 100:
break
示例2: test
# 需要导入模块: from transform import Transform [as 别名]
# 或者: from transform.Transform import revert [as 别名]
def test(args):
# augmentation setting
trans = Transform(args)
# test data
test_fn = '%s/test_joints.csv' % args.datadir
test_dl = np.array([l.strip() for l in open(test_fn).readlines()])
# load model
if args.gpu >= 0:
cuda.get_device(args.gpu).use()
model = load_model(args)
if args.gpu >= 0:
model.to_gpu()
else:
model.to_cpu()
# create output dir
epoch = int(re.search('epoch-([0-9]+)', args.param).groups()[0])
result_dir = os.path.dirname(args.param)
out_dir = '%s/test_%d' % (result_dir, epoch)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
out_log = '%s.log' % out_dir
fp = open(out_log, 'w')
mean_error = 0.0
N = len(test_dl)
for i in range(0, N, args.batchsize):
lines = test_dl[i:i + args.batchsize]
input_data, labels = load_data(trans, args, lines)
if args.gpu >= 0:
input_data = cuda.to_gpu(input_data.astype(np.float32))
labels = cuda.to_gpu(labels.astype(np.float32))
else:
input_data = input_data.astype(np.float32)
labels = labels.astype(np.float32)
x = Variable(input_data, volatile=True)
t = Variable(labels, volatile=True)
model(x, t)
if args.gpu >= 0:
preds = cuda.to_cpu(model.pred.data)
input_data = cuda.to_cpu(input_data)
labels = cuda.to_cpu(labels)
else:
preds = model.pred.data
for n, line in enumerate(lines):
img_fn = line.split(',')[args.fname_index]
img = input_data[n].transpose((1, 2, 0))
pred = preds[n]
img_pred, pred = trans.revert(img, pred)
# turn label data into image coordinates
label = labels[n]
img_label, label = trans.revert(img, label)
# calc mean_error
error = np.linalg.norm(pred - label) / len(pred)
mean_error += error
# create pred, label tuples
img_pred = np.array(img_pred.copy())
img_label = np.array(img_label.copy())
pred = [tuple(p) for p in pred]
label = [tuple(p) for p in label]
# all limbs
img_label = draw_joints(
img_label, label, args.draw_limb, args.text_scale)
img_pred = draw_joints(
img_pred, pred, args.draw_limb, args.text_scale)
msg = '{:5}/{:5} {}\terror:{}\tmean_error:{}'.format(
i + n, N, img_fn, error, mean_error / (i + n + 1))
print(msg, file=fp)
print(msg)
fn, ext = os.path.splitext(img_fn)
tr_fn = '%s/%d-%d_%s_pred%s' % (out_dir, i, n, fn, ext)
la_fn = '%s/%d-%d_%s_label%s' % (out_dir, i, n, fn, ext)
cv.imwrite(tr_fn, img_pred)
cv.imwrite(la_fn, img_label)