Exemplo n.º 1
0
    def __init__(self, transform, data_split):
        self.transform = transform
        self.data_split = data_split
        self.data_path = osp.join('..', 'data', 'PW3D', 'data')
        self.human_bbox_root_dir = osp.join('..', 'data', 'PW3D',
                                            'rootnet_output',
                                            'bbox_root_pw3d_output.json')

        # SMPL joint set
        self.smpl = SMPL()
        self.face = self.smpl.face
        self.joint_regressor = self.smpl.joint_regressor
        self.vertex_num = self.smpl.vertex_num
        self.joint_num = self.smpl.joint_num
        self.joints_name = self.smpl.joints_name
        self.skeleton = self.smpl.skeleton
        self.root_joint_idx = self.smpl.root_joint_idx
        self.face_kps_vertex = self.smpl.face_kps_vertex

        # H36M joint set
        self.h36m_joints_name = ('Pelvis', 'R_Hip', 'R_Knee', 'R_Ankle',
                                 'L_Hip', 'L_Knee', 'L_Ankle', 'Torso', 'Neck',
                                 'Nose', 'Head_top', 'L_Shoulder', 'L_Elbow',
                                 'L_Wrist', 'R_Shoulder', 'R_Elbow', 'R_Wrist')
        self.h36m_root_joint_idx = self.h36m_joints_name.index('Pelvis')
        self.h36m_eval_joint = (1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15,
                                16)
        self.h36m_joint_regressor = np.load(
            osp.join('..', 'data', 'Human36M', 'J_regressor_h36m_correct.npy'))

        self.datalist = self.load_data()
Exemplo n.º 2
0
    def __init__(self, pose_backbone, pose_net, pose2feat, mesh_backbone,
                 mesh_net, param_regressor):
        super(Model, self).__init__()
        self.pose_backbone = pose_backbone
        self.pose_net = pose_net
        self.pose2feat = pose2feat
        self.mesh_backbone = mesh_backbone
        self.mesh_net = mesh_net
        self.param_regressor = param_regressor

        if 'FreiHAND' in cfg.trainset_3d + cfg.trainset_2d + [cfg.testset]:
            self.human_model = MANO()
            self.human_model_layer = self.human_model.layer.cuda()
        else:
            self.human_model = SMPL()
            self.human_model_layer = self.human_model.layer['neutral'].cuda()
        self.root_joint_idx = self.human_model.root_joint_idx
        self.mesh_face = self.human_model.face
        self.joint_regressor = self.human_model.joint_regressor
        if cfg.stage == 'lixel':
            self.trainable_modules = [
                self.pose_backbone, self.pose_net, self.pose2feat,
                self.mesh_backbone, self.mesh_net
            ]
        else:
            self.trainable_modules = [self.param_regressor]

        self.coord_loss = CoordLoss()
        self.param_loss = ParamLoss()
        self.normal_loss = NormalVectorLoss(self.mesh_face)
        self.edge_loss = EdgeLengthLoss(self.mesh_face)
Exemplo n.º 3
0
    def __init__(self, transform, data_split):
        self.transform = transform
        self.data_split = data_split
        self.img_dir = osp.join('..', 'data', 'MuCo', 'data')
        self.annot_path = osp.join('..', 'data', 'MuCo', 'data',
                                   'MuCo-3DHP.json')
        self.smpl_param_path = osp.join('..', 'data', 'MuCo', 'data',
                                        'smpl_param.json')
        self.fitting_thr = 25  # milimeter

        # MuCo joint set
        self.muco_joint_num = 21
        self.muco_joints_name = ('Head_top', 'Thorax', 'R_Shoulder', 'R_Elbow',
                                 'R_Wrist', 'L_Shoulder', 'L_Elbow', 'L_Wrist',
                                 'R_Hip', 'R_Knee', 'R_Ankle', 'L_Hip',
                                 'L_Knee', 'L_Ankle', 'Pelvis', 'Spine',
                                 'Head', 'R_Hand', 'L_Hand', 'R_Toe', 'L_Toe')
        self.muco_flip_pairs = ((2, 5), (3, 6), (4, 7), (8, 11), (9, 12),
                                (10, 13), (17, 18), (19, 20))
        self.muco_skeleton = ((0, 16), (16, 1), (1, 15), (15, 14), (14, 8),
                              (14, 11), (8, 9), (9, 10), (10, 19), (11, 12),
                              (12, 13), (13, 20), (1, 2), (2, 3), (3, 4),
                              (4, 17), (1, 5), (5, 6), (6, 7), (7, 18))
        self.muco_root_joint_idx = self.muco_joints_name.index('Pelvis')

        # H36M joint set
        self.h36m_joint_regressor = np.load(
            osp.join('..', 'data', 'Human36M', 'J_regressor_h36m_correct.npy')
        )  # use h36m joint regrssor (only use subset from original muco joint set)
        self.h36m_flip_pairs = ((1, 4), (2, 5), (3, 6), (14, 11), (15, 12),
                                (16, 13))
        self.h36m_joints_name = ('Pelvis', 'R_Hip', 'R_Knee', 'R_Ankle',
                                 'L_Hip', 'L_Knee', 'L_Ankle', 'Torso', 'Neck',
                                 'Nose', 'Head_top', 'L_Shoulder', 'L_Elbow',
                                 'L_Wrist', 'R_Shoulder', 'R_Elbow', 'R_Wrist')
        self.h36m_root_joint_idx = self.h36m_joints_name.index('Pelvis')

        # SMPL joint set
        self.smpl = SMPL()
        self.face = self.smpl.face
        self.joint_regressor = self.smpl.joint_regressor
        self.vertex_num = self.smpl.vertex_num
        self.joint_num = self.smpl.joint_num
        self.joints_name = self.smpl.joints_name
        self.flip_pairs = self.smpl.flip_pairs
        self.skeleton = self.smpl.skeleton
        self.root_joint_idx = self.smpl.root_joint_idx
        self.face_kps_vertex = self.smpl.face_kps_vertex

        self.datalist = self.load_data()
Exemplo n.º 4
0
    def __init__(self, transform, data_split):
        self.transform = transform
        self.data_split = data_split
        self.img_dir = osp.join('..', 'data', 'Human36M', 'images')
        self.annot_path = osp.join('..', 'data', 'Human36M', 'annotations')
        self.human_bbox_root_dir = osp.join('..', 'data', 'Human36M',
                                            'rootnet_output',
                                            'bbox_root_human36m_output.json')
        self.action_name = [
            'Directions', 'Discussion', 'Eating', 'Greeting', 'Phoning',
            'Posing', 'Purchases', 'Sitting', 'SittingDown', 'Smoking',
            'Photo', 'Waiting', 'Walking', 'WalkDog', 'WalkTogether'
        ]
        self.fitting_thr = 25  # milimeter

        # H36M joint set
        self.h36m_joint_num = 17
        self.h36m_joints_name = ('Pelvis', 'R_Hip', 'R_Knee', 'R_Ankle',
                                 'L_Hip', 'L_Knee', 'L_Ankle', 'Torso', 'Neck',
                                 'Nose', 'Head_top', 'L_Shoulder', 'L_Elbow',
                                 'L_Wrist', 'R_Shoulder', 'R_Elbow', 'R_Wrist')
        self.h36m_flip_pairs = ((1, 4), (2, 5), (3, 6), (14, 11), (15, 12),
                                (16, 13))
        self.h36m_skeleton = ((0, 7), (7, 8), (8, 9), (9, 10), (8, 11),
                              (11, 12), (12, 13), (8, 14), (14, 15), (15, 16),
                              (0, 1), (1, 2), (2, 3), (0, 4), (4, 5), (5, 6))
        self.h36m_root_joint_idx = self.h36m_joints_name.index('Pelvis')
        self.h36m_eval_joint = (1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15,
                                16)
        self.h36m_joint_regressor = np.load(
            osp.join('..', 'data', 'Human36M', 'J_regressor_h36m_correct.npy'))

        # SMPL joint set
        self.smpl = SMPL()
        self.face = self.smpl.face
        self.joint_regressor = self.smpl.joint_regressor
        self.vertex_num = self.smpl.vertex_num
        self.joint_num = self.smpl.joint_num
        self.joints_name = self.smpl.joints_name
        self.flip_pairs = self.smpl.flip_pairs
        self.skeleton = self.smpl.skeleton
        self.root_joint_idx = self.smpl.root_joint_idx
        self.face_kps_vertex = self.smpl.face_kps_vertex

        self.datalist = self.load_data()
Exemplo n.º 5
0
    def __init__(self, transform, data_split):
        self.transform = transform
        self.data_split = 'train' if data_split == 'train' else 'val'
        self.img_path = osp.join('..', 'data', 'MSCOCO', 'images')
        self.annot_path = osp.join('..', 'data', 'MSCOCO', 'annotations')
        self.rootnet_output_path = osp.join('..', 'data', 'MSCOCO',
                                            'rootnet_output',
                                            'bbox_root_coco_output.json')
        self.fitting_thr = 3.0  # pixel in cfg.output_hm_shape space

        # mscoco skeleton
        self.coco_joint_num = 18  # original: 17, manually added pelvis
        self.coco_joints_name = ('Nose', 'L_Eye', 'R_Eye', 'L_Ear', 'R_Ear',
                                 'L_Shoulder', 'R_Shoulder', 'L_Elbow',
                                 'R_Elbow', 'L_Wrist', 'R_Wrist', 'L_Hip',
                                 'R_Hip', 'L_Knee', 'R_Knee', 'L_Ankle',
                                 'R_Ankle', 'Pelvis')
        self.coco_skeleton = ((1, 2), (0, 1), (0, 2), (2, 4), (1, 3), (6, 8),
                              (8, 10), (5, 7), (7, 9), (12, 14), (14, 16),
                              (11, 13), (13, 15), (5, 6), (11, 12))
        self.coco_flip_pairs = ((1, 2), (3, 4), (5, 6), (7, 8), (9, 10),
                                (11, 12), (13, 14), (15, 16))
        self.coco_joint_regressor = np.load(
            osp.join('..', 'data', 'MSCOCO', 'J_regressor_coco_hip_smpl.npy'))

        # smpl skeleton
        self.smpl = SMPL()
        self.face = self.smpl.face
        self.joint_regressor = self.smpl.joint_regressor
        self.vertex_num = self.smpl.vertex_num
        self.joint_num = self.smpl.joint_num
        self.joints_name = self.smpl.joints_name
        self.flip_pairs = self.smpl.flip_pairs
        self.skeleton = self.smpl.skeleton
        self.root_joint_idx = self.smpl.root_joint_idx
        self.face_kps_vertex = self.smpl.face_kps_vertex

        self.datalist = self.load_data()
Exemplo n.º 6
0
    def __init__(self,
                 step_size=1e-2,
                 batch_size=66,
                 num_iters=100,
                 focal_length=5000,
                 device=torch.device('cuda')):

        # Store options
        self.device = device
        self.focal_length = focal_length
        self.step_size = step_size

        # Ignore the the following joints for the fitting process
        ign_joints = ['OP Neck', 'OP RHip', 'OP LHip', 'Right Hip', 'Left Hip']
        self.ign_joints = [constants.JOINT_IDS[i] for i in ign_joints]
        self.num_iters = num_iters
        # GMM pose prior
        self.pose_prior = MaxMixturePrior(prior_folder='data',
                                          num_gaussians=8,
                                          dtype=torch.float32).to(device)
        # Load SMPL model
        self.smpl = SMPL(config.SMPL_MODEL_DIR,
                         batch_size=batch_size,
                         create_transl=False).to(self.device)
Exemplo n.º 7
0
sys.path.append('..')

import os
import cv2
import ipdb
import torch
import config
import pickle
import numpy as np
from tqdm import tqdm
from utils.smpl import SMPL
from utils.geometry import batch_rodrigues

# --- predefined variables
device = torch.device('cpu')
smpl_male = SMPL(config.SMPL_MODEL_DIR, gender='male',
                 create_transl=False).to(device)
smpl_female = SMPL(config.SMPL_MODEL_DIR, gender='female',
                   create_transl=False).to(device)


def projection(smpl, smpl_trans, camPose, camIntrinsics):
    """
    projection annoted 3D joints to 2D, so that we can obtain GT 2D joints.
    """
    smpl += smpl_trans
    smpl = np.concatenate([smpl, np.ones((49, 1))], axis=1)
    smpl = np.dot(smpl, camPose.T)[:, :3]
    smpl /= smpl[:, np.newaxis, -1]
    smpl = np.dot(smpl, camIntrinsics.T)
    return smpl[:, :2]
Exemplo n.º 8
0
    #import ipdb
    #ipdb.set_trace()
    joints = (joints + 1) / 2 * 500 + 500
    for idx in range(joints.shape[0]):
        pt = joints[idx]
        cv2.circle(image, (pt[0], pt[1]), 4, np.array([197, 27, 125]).tolist(), -1)
    cv2.imwrite('tmp.jpg', image)        


if __name__ == '__main__':
    idx = 0
    mosh_file = '/data/neutrMosh/neutrSMPL_H3.6/S5/Directions 1_cam1_aligned.pkl'
    images = '/data/human36m_full_raw/images/S5_Directions_1.54138969_{:06d}.jpg'.format(idx+1)

    mosh = pkl.load(open(mosh_file, 'rb'), encoding='latin1')
    pose = mosh['new_poses'][idx]
    shape = mosh['betas']

    pose = torch.from_numpy(pose).float().unsqueeze(0)
    shape = torch.from_numpy(shape).float().unsqueeze(0)

    smpl = SMPL(config.SMPL_MODEL_DIR,
                    batch_size=1, 
                    create_transl=False).cpu()

    smpl_out = smpl(betas=shape, body_pose=pose[:,3:], global_orient=pose[:, :3])
    vertices = smpl_out.vertices
    joints = smpl_out.joints

    scatter_pose(cv2.imread(images), joints[0])