Пример #1
0
def test_gpu(gpu_id=[0]):
    if len(gpu_id) > 0 and torch.cuda.is_available():
        os.environ['CUDA_VISIBLE_DEVICES'] = str(gpu_id[0])
        device = torch.device('cuda')
    else:
        device = torch.device('cpu')
    print(device)

    pose_size = 72
    beta_size = 10

    np.random.seed(9608)
    pose = torch.from_numpy(get_theta('00001'))\
            .type(torch.float64).to(device)
    betas = torch.from_numpy(get_beta('00001')) \
            .type(torch.float64).to(device)
    trans = torch.from_numpy(get_trans('00001')).type(torch.float64).to(device)
    outmesh_path = './smpl_torch.obj'

    model = SMPLModel(device=device)
    result = model(betas, pose, trans)

    verts_numpy = result.cpu().numpy()
    faces_numpy = model.faces

    np.save('../../resault/verts.npy', verts_numpy)
    np.save('../../resault/faces.npy', faces_numpy)
Пример #2
0
def smplTest():
    smpl = smpl_torch.SMPLModel(device)

    pose = torch.from_numpy(get_theta('00000')).type(torch.float64).to(device)
    beta = torch.from_numpy(get_beta('00000')) \
          .type(torch.float64).to(device)
    trans = torch.from_numpy(get_trans('00000')).type(torch.float64).to(device)

    res = smpl(beta, pose, trans)

    J = smpl.J_regressor
    J = J.mm(res)

    print(J)
Пример #3
0
def get_ellipse(x, y):
	a = np.column_stack((x, y))
	a = a - np.repeat(a.mean(axis=0), a.shape[0]).reshape(a.shape[1], a.shape[0]).T	# mean center
	(w, v) = np.linalg.eig(np.cov(a.T))
	i = np.nonzero((-w).argsort()==0)[0][0]		# indices for the top 2 eigenvalues
	j = np.nonzero((-w).argsort()==1)[0][0]	
	xy = (np.mean(x), np.mean(y))
	width = np.sqrt(w[i]) * 2
	height = np.sqrt(w[j]) * 2
	unit = np.array([1, 0])
	vi = v[:,i]
	#vi = vi / norm(vi)		# already normalized
	theta = utils.get_theta(vi, unit)
	angle = utils.rad_to_deg(theta)
	return (xy, width, height, angle)
Пример #4
0
def get_ellipse(x, y):
    a = np.column_stack((x, y))
    a = a - np.repeat(a.mean(axis=0), a.shape[0]).reshape(
        a.shape[1], a.shape[0]).T  # mean center
    (w, v) = np.linalg.eig(np.cov(a.T))
    i = np.nonzero(
        (-w).argsort() == 0)[0][0]  # indices for the top 2 eigenvalues
    j = np.nonzero((-w).argsort() == 1)[0][0]
    xy = (np.mean(x), np.mean(y))
    width = np.sqrt(w[i]) * 2
    height = np.sqrt(w[j]) * 2
    unit = np.array([1, 0])
    vi = v[:, i]
    #vi = vi / norm(vi)		# already normalized
    theta = utils.get_theta(vi, unit)
    angle = utils.rad_to_deg(theta)
    return (xy, width, height, angle)
Пример #5
0
def smpl_plot():
    smpl = smpl_np.SMPLModel('../smpl/model.pkl')
    np.random.seed(9608)
    pose = get_theta('00000')
    beta = get_beta('00000')
    trans = get_trans('00000')
    smpl.set_params(beta=beta, pose=pose, trans=trans)
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    mesh = Poly3DCollection(smpl.verts[smpl.faces], alpha=0.05)
    mesh.set_edgecolor((0.3,0.3,0.3))
    mesh.set_facecolor((0.7,0.7,0.7))
    ax.add_collection3d(mesh)

    J = smpl.J_regressor.dot(smpl.verts)
    print(J)
    print(J.shape, type(J))
    print(smpl.J_regressor.shape)
    for j in range(len(J)):
        pos1 = J[j]
        ax.scatter3D([pos1[0]], [pos1[1]], [pos1[2]], label=f"{j}")
    plt.legend()
    plt.show()
Пример #6
0
def main(img_path, json_path=None):

    input_img, proc_param, img = preprocess_image(img_path, json_path)
    # Add batch dimension: 1 x D x D x 3
    input_img = np.expand_dims(input_img, 0)

    # Theta is the 85D vector holding [camera, pose, shape]
    # where camera is 3D [s, tx, ty]
    # pose is 72D vector holding the rotation of 24 joints of SMPL in axis angle format
    # shape is 10D shape coefficients of SMPL
    device = torch.device('cuda', 0)
    smpl = SMPL('../../smpl/model_cocoplus.pkl', obj_saveable=True).to(device)
    pose = get_theta('00001')

    beta = get_beta('00001')

    vbeta = torch.tensor(np.array([beta])).float().to(device)
    vpose = torch.tensor(np.array([pose])).float().to(device)
    vcam = torch.tensor([0.9, 0, 0]).expand((1, 3)).float().to(device)

    verts, joints, _ = smpl(vbeta, vpose, get_skin=True)

    pred_kp = batch_orth_proj_idrot(joints.cpu(), vcam.cpu())

    r = torch.ones((1, 3))

    verts, joints, r = verts.cpu().numpy(), pred_kp.cpu().numpy(), vcam.cpu(
    ).numpy()

    print(img.shape)

    print(type(joints), type(verts), type(r))

    print(joints[0].shape, verts[0].shape, r[0].shape)

    visualize(img, proc_param, joints[0], verts[0], r[0])
Пример #7
0
        joint_y = torch.matmul(verts[:, :, 1], self.joint_regressor.t())
        joint_z = torch.matmul(verts[:, :, 2], self.joint_regressor.t())

        joints = torch.stack([joint_x, joint_y, joint_z], dim=2)

        if get_skin:
            return verts, joints, Rs
        else:
            return joints


if __name__ == '__main__':
    device = torch.device('cuda', 0)

    smpl = SMPL('../../smpl/model_cocoplus.pkl', obj_saveable=True).to(device)
    pose = get_theta('00002')
    pose[:3] = 0
    beta = get_beta('00002')
    cam = np.array([0.9, 0, 0])

    vbeta = torch.tensor(np.array([beta])).float().to(device)
    vpose = torch.tensor(np.array([pose])).float().to(device)
    vcam = torch.tensor(np.array([cam])).float().to(device)

    verts, j, r = smpl(vbeta, vpose, get_skin=True)
    smpl.save_obj(verts[0].cpu().numpy(), './mesh.obj')
    verts_numpy = verts.cpu().numpy()
    faces_numpy = smpl.faces
    np.save('../../resault/verts.npy', verts_numpy)
    np.save('../../resault/faces.npy', faces_numpy)
Пример #8
0
 def b_n(k, s):
     return( get_lambda(S)+get_mu()+k*get_theta(S)+s )
Пример #9
0
 def a_n(k):
     return( -get_lambda(S) * (get_mu()+k*get_theta(S)) )