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

Function process_db_coord_batch_no_valid

util/preprocessing.py:398–480  ·  view source on GitHub ↗
(joint_img, joint_cam, do_flip,
                           img_shape, flip_pairs, img2bb_trans, rot,
                           src_joints_name, target_joints_name,
                           input_img_shape)

Source from the content-addressed store, hash-verified

396
397
398def process_db_coord_batch_no_valid(joint_img, joint_cam, do_flip,
399 img_shape, flip_pairs, img2bb_trans, rot,
400 src_joints_name, target_joints_name,
401 input_img_shape):
402 joint_img_original = joint_img.copy()
403 joint_img, joint_cam = joint_img.copy(), joint_cam.copy()
404
405 # flip augmentation
406 if do_flip:
407 joint_cam[:, :, 0] = -joint_cam[:, :, 0]
408 joint_img[:, :, 0] = img_shape[1] - 1 - joint_img[:, :, 0]
409 for pair in flip_pairs:
410 joint_img[:, pair[0], :], joint_img[:, pair[
411 1], :] = joint_img[:, pair[1], :].copy(
412 ), joint_img[:, pair[0], :].copy()
413 joint_cam[:, pair[0], :], joint_cam[:, pair[
414 1], :] = joint_cam[:, pair[1], :].copy(
415 ), joint_cam[:, pair[0], :].copy()
416
417 # 3D data rotation augmentation
418 rot_aug_mat = np.array(
419 [[np.cos(np.deg2rad(-rot)), -np.sin(np.deg2rad(-rot)), 0],
420 [np.sin(np.deg2rad(-rot)),
421 np.cos(np.deg2rad(-rot)), 0], [0, 0, 1]],
422 dtype=np.float32)
423 num_p, num_joints, joints_dim = joint_cam.shape
424 joint_cam = joint_cam.reshape(num_p * num_joints, joints_dim)
425 joint_cam[:,:-1] = np.dot(rot_aug_mat, joint_cam[:,:-1].transpose(1, 0)).transpose(1, 0)
426 joint_cam = joint_cam.reshape(num_p, num_joints, joints_dim)
427
428 # affine transformation
429 joint_img_xy1 = \
430 np.concatenate((joint_img[:, :, :2], np.ones_like(joint_img[:, :, :1])), 2)
431 joint_img_xy1 = joint_img_xy1.reshape(num_p * num_joints, 3)
432
433 joint_img[:, :, :2] = np.dot(img2bb_trans,
434 joint_img_xy1.transpose(1, 0)).transpose(
435 1, 0).reshape(num_p, num_joints, 2)
436
437 joint_img[:, :,
438 0] = joint_img[:, :,
439 0] / input_img_shape[1] * cfg.output_hm_shape[2]
440 joint_img[:, :,
441 1] = joint_img[:, :,
442 1] / input_img_shape[0] * cfg.output_hm_shape[1]
443
444 # check truncation
445 # TODO
446 # remove 3rd
447 joint_trunc = ((joint_img_original[:,:, 0] >= 0) * (joint_img[:,:, 0] >= 0) * (joint_img[:,:, 0] < cfg.output_hm_shape[2]) * \
448 (joint_img_original[:,:, 1] >= 0) *(joint_img[:,:, 1] >= 0) * (joint_img[:,:, 1] < cfg.output_hm_shape[1]) * \
449 joint_img[:,:, -1]
450 ).reshape(num_p, -1, 1).astype(np.float32)
451
452
453 # transform joints to target db joints
454
455 joint_img = transform_joint_to_other_db_batch(joint_img, src_joints_name,

Callers 3

__getitem__Method · 0.90
__getitem__Method · 0.90
__getitem__Method · 0.90

Calls 3

copyMethod · 0.80
concatenateMethod · 0.80

Tested by

no test coverage detected