tools/smpl_utils.py
def optimize_on_joints3D(model,
                         joints3D,
                         opt_shape=False,
                         viz=True):
    """Fit the model to the given set of 3D joints
    :param model: initial SMPL model ===> is modified after optimization
    :param joints3D: 3D joint locations [16 x 3]
    :param opt_shape: boolean, if True optimizes for shape parameter betas
    :param viz: boolean, if True enables visualization during optimization
    """
    t0 = time()
    if joints3D.shape[0] == 16:
        obj_joints3D = lambda w, sigma: (w * GMOf((joints3D - model.J_transformed[get_indices_16()]), sigma))
    elif joints3D.shape[0] == 24:
        obj_joints3D = lambda w, sigma: (w * GMOf((joints3D - model.J_transformed), sigma))
    else:
        raise('How many joints?')

    # Create the pose prior (GMM over CMU)
    prior = MaxMixtureCompletePrior(n_gaussians=8).get_gmm_prior()
    pprior = lambda w: w * prior(model.pose)
    # joint angles pose prior, defined over a subset of pose parameters:
    # 55: left elbow,  90deg bend at -np.pi/2
    # 58: right elbow, 90deg bend at np.pi/2
    # 12: left knee,   90deg bend at np.pi/2
    # 15: right knee,  90deg bend at np.pi/2
    my_exp = lambda x: 10 * chumpy.exp(x)
    obj_angle = lambda w: w * chumpy.concatenate([my_exp(model.pose[55]),
                                                 my_exp(-model.pose[58]),
                                                 my_exp(-model.pose[12]),
                                                 my_exp(-model.pose[15])])
    # Visualization at optimization step
    if viz:
        def on_step(_):
            """Draw a visualization."""
            plt.figure(1, figsize=(5, 5))
            renderBody(model)
            plt.draw()
            plt.pause(1e-3)
    else:
        on_step = None

    # weight configuration (pose and shape: original values as in SMPLify)
    # the first list contains the weights for the pose prior,
    # the second list contains the weights for the shape prior
    opt_weights = zip([4.04 * 1e2, 4.04 * 1e2, 57.4, 4.78],
                      [1e2, 5 * 1e1, 1e1, .5 * 1e1])

    print('Initial: error(joints3D) = %.2f' % (obj_joints3D(100, 100).r**2).sum())

    # run the optimization in 4 stages, progressively decreasing the
    # weights for the priors
    for stage, (wpose, wbetas) in enumerate(opt_weights):
        objs = {}
        objs['joints3D'] = obj_joints3D(100., 100)
        objs['pose'] = pprior(wpose)
        objs['pose_exp'] = obj_angle(0.317 * wpose)
        if opt_shape:
            objs['betas'] = wbetas * model.betas

            chumpy.minimize(
                objs,
                x0=[model.pose, model.betas],
                method='dogleg',
                callback=on_step,
                options={'maxiter': 1000,
                         'e_3': .0001,
                         'disp': 0})
        else:
            chumpy.minimize(
                objs,
                x0=[model.pose],
                method='dogleg',
                callback=on_step,
                options={'maxiter': 1000,
                         'e_3': .0001,
                         'disp': 0})
        print('Stage %d: error(joints3D) = %.2f' % (stage, (objs['joints3D'].r**2).sum()))
    print('\nElapsed theta fitting (%d joints): %.2f sec.' % (joints3D.shape[0], (time() - t0)))
Fit the model to the given set of 3D joints
    :param model: initial SMPL model ===> is modified after optimization
    :param joints3D: 3D joint locations [16 x 3]
    :param opt_shape: boolean, if True optimizes for shape parameter betas
    :param viz: boolean, if True enables visualization during optimization
    
Fit the model to the given set of 3D joints
Fit the model to the given set of 3D joints
def optimize_on_joints3D(model,
                         joints3D,
                         opt_shape=False,
                         viz=True):
    t0 = time()
    if joints3D.shape[0] == 16:
        obj_joints3D = lambda w, sigma: (w * GMOf((joints3D - model.J_transformed[get_indices_16()]), sigma))
    elif joints3D.shape[0] == 24:
        obj_joints3D = lambda w, sigma: (w * GMOf((joints3D - model.J_transformed), sigma))
    else:
        raise('How many joints?')
    prior = MaxMixtureCompletePrior(n_gaussians=8).get_gmm_prior()
    pprior = lambda w: w * prior(model.pose)
    my_exp = lambda x: 10 * chumpy.exp(x)
    obj_angle = lambda w: w * chumpy.concatenate([my_exp(model.pose[55]),
                                                 my_exp(-model.pose[58]),
                                                 my_exp(-model.pose[12]),
                                                 my_exp(-model.pose[15])])
    if viz:
        def on_step(_):
            plt.figure(1, figsize=(5, 5))
            renderBody(model)
            plt.draw()
            plt.pause(1e-3)
    else:
        on_step = None
    opt_weights = zip([4.04 * 1e2, 4.04 * 1e2, 57.4, 4.78],
                      [1e2, 5 * 1e1, 1e1, .5 * 1e1])
    print('Initial: error(joints3D) = %.2f' % (obj_joints3D(100, 100).r**2).sum())
    for stage, (wpose, wbetas) in enumerate(opt_weights):
        objs = {}
        objs['joints3D'] = obj_joints3D(100., 100)
        objs['pose'] = pprior(wpose)
        objs['pose_exp'] = obj_angle(0.317 * wpose)
        if opt_shape:
            objs['betas'] = wbetas * model.betas
            chumpy.minimize(
                objs,
                x0=[model.pose, model.betas],
                method='dogleg',
                callback=on_step,
                options={'maxiter': 1000,
                         'e_3': .0001,
                         'disp': 0})
        else:
            chumpy.minimize(
                objs,
                x0=[model.pose],
                method='dogleg',
                callback=on_step,
                options={'maxiter': 1000,
                         'e_3': .0001,
                         'disp': 0})
        print('Stage %d: error(joints3D) = %.2f' % (stage, (objs['joints3D'].r**2).sum()))
    print('\nElapsed theta fitting (%d joints): %.2f sec.' % (joints3D.shape[0], (time() - t0)))
def optimize_on_joints3D ( model , joints3D , opt_shape = False , viz = True ) : t0 = time ( ) if joints3D . shape [ 0 ] == 16 : obj_joints3D = lambda w , sigma : ( w * GMOf ( ( joints3D - model . J_transformed [ get_indices_16 ( ) ] ) , sigma ) ) elif joints3D . shape [ 0 ] == 24 : obj_joints3D = lambda w , sigma : ( w * GMOf ( ( joints3D - model . J_transformed ) , sigma ) ) else : raise ( 'How many joints?' ) prior = MaxMixtureCompletePrior ( n_gaussians = 8 ) . get_gmm_prior ( ) pprior = lambda w : w * prior ( model . pose ) my_exp = lambda x : 10 * chumpy . exp ( x ) obj_angle = lambda w : w * chumpy . concatenate ( [ my_exp ( model . pose [ 55 ] ) , my_exp ( - model . pose [ 58 ] ) , my_exp ( - model . pose [ 12 ] ) , my_exp ( - model . pose [ 15 ] ) ] ) if viz : def on_step ( _ ) : """Draw a visualization.""" plt . figure ( 1 , figsize = ( 5 , 5 ) ) renderBody ( model ) plt . draw ( ) plt . pause ( 1e-3 ) else : on_step = None opt_weights = zip ( [ 4.04 * 1e2 , 4.04 * 1e2 , 57.4 , 4.78 ] , [ 1e2 , 5 * 1e1 , 1e1 , .5 * 1e1 ] ) print ( 'Initial: error(joints3D) = %.2f' % ( obj_joints3D ( 100 , 100 ) . r ** 2 ) . sum ( ) ) for stage , ( wpose , wbetas ) in enumerate ( opt_weights ) : objs = { } objs [ 'joints3D' ] = obj_joints3D ( 100. , 100 ) objs [ 'pose' ] = pprior ( wpose ) objs [ 'pose_exp' ] = obj_angle ( 0.317 * wpose ) if opt_shape : objs [ 'betas' ] = wbetas * model . betas chumpy . minimize ( objs , x0 = [ model . pose , model . betas ] , method = 'dogleg' , callback = on_step , options = { 'maxiter' : 1000 , 'e_3' : .0001 , 'disp' : 0 } ) else : chumpy . minimize ( objs , x0 = [ model . pose ] , method = 'dogleg' , callback = on_step , options = { 'maxiter' : 1000 , 'e_3' : .0001 , 'disp' : 0 } ) print ( 'Stage %d: error(joints3D) = %.2f' % ( stage , ( objs [ 'joints3D' ] . r ** 2 ) . sum ( ) ) ) print ( '\nElapsed theta fitting (%d joints): %.2f sec.' % ( joints3D . shape [ 0 ] , ( time ( ) - t0 ) ) )
Fit the model to the given set of 3D joints
Fit the model to the given set of 3D joints
"""Fit the model to the given set of 3D joints
    :param model: initial SMPL model ===> is modified after optimization
    :param joints3D: 3D joint locations [16 x 3]
    :param opt_shape: boolean, if True optimizes for shape parameter betas
    :param viz: boolean, if True enables visualization during optimization
    """ # Create the pose prior (GMM over CMU) # joint angles pose prior, defined over a subset of pose parameters: # 55: left elbow,  90deg bend at -np.pi/2 # 58: right elbow, 90deg bend at np.pi/2 # 12: left knee,   90deg bend at np.pi/2 # 15: right knee,  90deg bend at np.pi/2 # Visualization at optimization step """Draw a visualization.""" # weight configuration (pose and shape: original values as in SMPLify) # the first list contains the weights for the pose prior, # the second list contains the weights for the shape prior # run the optimization in 4 stages, progressively decreasing the # weights for the priors
model
initial SMPL model ===> is modified after optimization
initial SMPL model === > is modified after optimization
joints3D
3D joint locations [16 x 3]
3D joint locations [ 16 x 3 ]
opt_shape
boolean, if True optimizes for shape parameter betas
boolean if True optimizes for shape parameter betas
viz
boolean, if True enables visualization during optimization
boolean if True enables visualization during optimization