Exemple #1
0
    def eval_colllision(self):

        coll_list = []
        cont_list = []
        for ii in range(8000):
            filename = os.path.join(self.input_data_file, 'body_gen_{:06d}.pkl'.format(ii))
            
            if not os.path.exists(filename):
                continue

            with open(filename, 'rb') as f:
                body_param_input = pickle.load(f)


            xh, self.cam_ext, self.cam_int= BodyParamParser.body_params_parse_fitting(body_param_input)
            xhr = GeometryTransformer.convert_to_6D_rot(xh)
            self.xhr_rec = xhr

            T_mat = np.eye(4)
            T_mat[1,:] = np.array([0,-1,0,0])
            T_mat[2,:] = np.array([0,0,-1,0])
            T_mat = torch.tensor(T_mat, dtype=torch.float32, device=self.device)
            T_mat = T_mat.unsqueeze(0)
            trans = torch.matmul(self.cam_ext[:1],T_mat)

            loss_rec, loss_vposer, loss_contact, loss_collision = self.cal_loss(xhr, trans)

            coll_list.append(loss_collision.item())
            cont_list.append(loss_contact.item())

        return coll_list, cont_list
Exemple #2
0
    def fitting(self, input_data_file):

        with open(input_data_file, 'rb') as f:
            body_param_input = pickle.load(f)

        xh, self.cam_ext, self.cam_int = BodyParamParser.body_params_parse_fitting(
            body_param_input)
        xhr = GeometryTransformer.convert_to_6D_rot(xh)
        self.xhr_rec.data = xhr.clone()

        for ii in range(self.num_iter):

            self.optimizer.zero_grad()

            loss_rec, loss_vposer, loss_contact, loss_collision = self.cal_loss(
                xhr, self.cam_ext)
            loss = loss_rec + loss_vposer + loss_contact + loss_collision
            if self.verbose:
                print(
                    '[INFO][fitting] iter={:d}, l_rec={:f}, l_vposer={:f}, l_contact={:f}, l_collision={:f}'
                    .format(ii, loss_rec.item(), loss_vposer.item(),
                            loss_contact.item(), loss_collision.item()))

            loss.backward(retain_graph=True)
            self.optimizer.step()

        print('[INFO][fitting] fitting finish, returning optimal value')

        xh_rec = GeometryTransformer.convert_to_3D_rot(self.xhr_rec)

        return xh_rec
Exemple #3
0
def fitting(fittingconfig):

    input_data_file = fittingconfig['input_data_file']
    with open(input_data_file, 'rb') as f:
        body_param_input = pickle.load(f)

    xh, _, _ = BodyParamParser.body_params_parse_fitting(body_param_input)

    return xh.detach().cpu().numpy()
Exemple #4
0
    def fitting(self, input_data_file):


        with open(input_data_file, 'rb') as f:
            body_param_input = pickle.load(f)

        xh, self.cam_ext, self.cam_int= BodyParamParser.body_params_parse_fitting(body_param_input)
        xhr = GeometryTransformer.convert_to_6D_rot(xh)
        self.xhr_rec.data = xhr.clone()

        T_mat = np.eye(4)
        T_mat[1,:] = np.array([0,-1,0,0])
        T_mat[2,:] = np.array([0,0,-1,0])
        T_mat = torch.tensor(T_mat, dtype=torch.float32, device=self.device)
        T_mat = T_mat.unsqueeze(0)
        trans = torch.matmul(self.cam_ext[:1],T_mat)
        


        for ii in range(self.num_iter):

            self.optimizer.zero_grad()

            loss_rec, loss_vposer, loss_contact, loss_collision = self.cal_loss(xhr, trans)
            loss = loss_rec + loss_vposer + loss_contact + loss_collision
            if self.verbose:
                print('[INFO][fitting] iter={:d}, l_rec={:f}, l_vposer={:f}, l_contact={:f}, l_collision={:f}'.format(
                                        ii, loss_rec.item(), loss_vposer.item(), 
                                        loss_contact.item(), loss_collision.item()) )

            loss.backward(retain_graph=True)
            self.optimizer.step()


        print('[INFO][fitting] fitting finish, returning optimal value')


        xh_rec =  GeometryTransformer.convert_to_3D_rot(self.xhr_rec)

        return xh_rec