def _set_up(self): self.v_shaped = self.shapedirs.dot(self.betas) + self.v_template self.v_shaped_personal = self.v_shaped + self.v_personal if sp.issparse(self.J_regressor): self.J = sp_dot(self.J_regressor, self.v_shaped) else: self.J = ch.sum(self.J_regressor.T.reshape(-1, 1, 24) * self.v_shaped.reshape(-1, 3, 1), axis=0).T self.v_posevariation = self.posedirs.dot( posemap(self.bs_type)(self.pose)) self.v_poseshaped = self.v_shaped_personal + self.v_posevariation self.A, A_global = self._global_rigid_transformation() self.Jtr = ch.vstack([g[:3, 3] for g in A_global]) self.J_transformed = self.Jtr + self.trans.reshape((1, 3)) self.V = self.A.dot(self.weights.T) rest_shape_h = ch.hstack( (self.v_poseshaped, ch.ones((self.v_poseshaped.shape[0], 1)))) self.v_posed = ch.sum(self.V.T * rest_shape_h.reshape(-1, 4, 1), axis=1)[:, :3] self.v = self.v_posed + self.trans
def fit_consensus(frames, base_smpl, camera, frustum, model_data, nohands, icp_count, naked, display): if nohands: faces = faces_no_hands(base_smpl.f) else: faces = base_smpl.f vis_rn_b = BoundaryRenderer(camera=camera, frustum=frustum, f=faces, num_channels=1) vis_rn_m = ColoredRenderer(camera=camera, frustum=frustum, f=faces, vc=np.zeros_like(base_smpl), bgcolor=1, num_channels=1) model_template = Smpl(model_data) model_template.betas[:] = base_smpl.betas.r g_laplace = regularize_laplace() g_model = regularize_model() g_symmetry = regularize_symmetry() face_ids = get_face_vertex_ids() for step, (w_laplace, w_model, w_symmetry, sigma) in enumerate(zip( np.linspace(6.5, 4.0, icp_count) if naked else np.linspace(4.0, 2.0, icp_count), np.linspace(0.9, 0.6, icp_count) if naked else np.linspace(0.6, 0.3, icp_count), np.linspace(3.6, 1.8, icp_count), np.linspace(0.06, 0.003, icp_count), )): log.info('# Step {}'.format(step)) L = laplacian(model_template.r, base_smpl.f) delta = L.dot(model_template.r) w_laplace *= g_laplace.reshape(-1, 1) w_model *= g_model.reshape(-1, 1) w_symmetry *= g_symmetry.reshape(-1, 1) E = { 'laplace': (sp_dot(L, base_smpl.v_shaped_personal) - delta) * w_laplace, 'model': (base_smpl.v_shaped_personal - model_template) * w_model, 'symmetry': (base_smpl.v_personal + np.array([1, -1, -1]) * base_smpl.v_personal[model_data['vert_sym_idxs']]) * w_symmetry, } log.info('## Matching rays with contours') for current, f in enumerate(tqdm(frames)): E['silh_{}'.format(current)] = ray_objective(f, sigma, base_smpl, camera, vis_rn_b, vis_rn_m) #paper 2 E['face_{}'.format(current)] = ray_face(f, sigma, base_smpl, camera, face_ids) log.info('## Run optimization') ch.minimize( E, [base_smpl.v_personal, model_template.betas], method='dogleg', options={'maxiter': 15, 'e_3': 0.001}, callback=get_cb(frames[0], base_smpl, camera, frustum) if display else None )