Example #1
0
    def forward(self, pred, targ):
        """
        :param pred: NxTx6
        :param targ: NxTx6
        :return: N
        """
        s = pred.size()
        num_poses = s[0] * s[1]
        abs_loss =\
            torch.exp(-self.beta) * self.loss_fn(
            pred.view(num_poses, -1)[:, :3],
            targ.view(num_poses, -1)[:, :3]
        ) + self.beta + \
            torch.exp(-self.gamma) * self.loss_fn(
                pred.view(num_poses, -1)[:, 3:],
                targ.view(num_poses, -1)[:, 3:]
            ) + self.gamma

        pred_vos = pose_utils.calc_vos_simple(pred)
        targ_vos = pose_utils.calc_vos_simple(targ)

        s = pred_vos.size()
        num_poses = s[0] * s[1]
        rel_loss =\
            torch.exp(-self.rel_beta) * self.loss_fn(
                pred_vos.view(num_poses, -1)[:, :3],
                targ_vos.view(num_poses, -1)[:, :3]
            ) + self.rel_beta +\
            torch.exp(-self.rel_gamma) * self.loss_fn(
                pred_vos.view(num_poses, -1)[:, 3:],
                targ_vos.view(num_poses, -1)[:, 3:]
            ) + self.rel_gamma

        loss = abs_loss + rel_loss
        return loss
Example #2
0
    def forward(self, pred, targ):
        """
    :param pred: N x T x 6
    :param targ: N x T x 6
    :return:
    """

        # absolute pose loss
        s = pred.size()
        abs_loss =\
          torch.exp(-self.sax) * self.t_loss_fn(pred.view(-1, *s[2:])[:, :3],
                                                targ.view(-1, *s[2:])[:, :3]) + \
          self.sax + \
          torch.exp(-self.saq) * self.q_loss_fn(pred.view(-1, *s[2:])[:, 3:],
                                                targ.view(-1, *s[2:])[:, 3:]) + \
          self.saq

        # get the VOs
        pred_vos = pose_utils.calc_vos_simple(pred)
        targ_vos = pose_utils.calc_vos_simple(targ)

        # VO loss
        s = pred_vos.size()
        vo_loss = \
          torch.exp(-self.srx) * self.t_loss_fn(pred_vos.view(-1, *s[2:])[:, :3],
                                                targ_vos.view(-1, *s[2:])[:, :3]) + \
          self.srx + \
          torch.exp(-self.srq) * self.q_loss_fn(pred_vos.view(-1, *s[2:])[:, 3:],
                                                targ_vos.view(-1, *s[2:])[:, 3:]) + \
          self.srq

        # total loss
        loss = abs_loss + vo_loss
        return loss
Example #3
0
    def forward(self, pred, targ):
        """
        :param pred: N x T x 6
        :param targ: N x T x 6
        :return:
        """

        if self.dual_target:
            pred, sem_pred = pred[0], pred[1]
            targ, sem_targ = targ[0], targ[1]
        s = pred.size()
        
        # absolute pose loss
        # get the VOs
        pred_vos = pose_utils.calc_vos_simple(pred)
        targ_vos = pose_utils.calc_vos_simple(targ)
        
        t_loss = self.t_loss_fn(pred.view(-1, *s[2:])[:, :3],
                                targ.view(-1, *s[2:])[:, :3])
        
        q_loss = self.q_loss_fn(pred.view(-1, *s[2:])[:, 3:],
                                targ.view(-1, *s[2:])[:, 3:])
        
        vo_t_loss = self.t_loss_fn(pred_vos.view(-1, *s[2:])[:, :3],
                                   targ_vos.view(-1, *s[2:])[:, :3])
        
        vo_q_loss = self.q_loss_fn(pred_vos.view(-1, *s[2:])[:, 3:],
                                   targ_vos.view(-1, *s[2:])[:, 3:])
        
        
        abs_loss =(
            torch.exp(-self.sax) * t_loss + 
            self.sax + 
            torch.exp(-self.saq) * q_loss +
            self.saq
        )
        
        vo_loss = (
            torch.exp(-self.srx) * vo_t_loss + 
            self.srx + 
            torch.exp(-self.srq) * vo_q_loss + 
            self.srq
        )
        
        loss_pose = (abs_loss + vo_loss)
        
        if self.dual_target:
            s = sem_targ.size()
            sem_targ = sem_targ.view(-1,*s[2:])
            s_loss = self.sem_loss(sem_pred, sem_targ)
            
            loss_semantic = torch.exp(-self.sas) * s_loss + self.sas
        else:
            loss_semantic = 0
        
        loss = loss_pose + loss_semantic
        return loss    
Example #4
0
    def forward(self, pred, targ):
        """
        :param pred: N x T x 6
        :param targ: N x T x 6
        :return:
        """

        
        if self.dual_target:
            pred, sem_pred = pred[0], pred[1]
            targ, sem_targ = targ[0], targ[1]
        s = pred.size()
        
        # absolute pose loss
        # get the VOs
        pred_vos = pose_utils.calc_vos_simple(pred)
        targ_vos = pose_utils.calc_vos_simple(targ)
        
        t_loss = self.t_loss_fn(pred.view(-1, *s[2:])[:, :3],
                                targ.view(-1, *s[2:])[:, :3])
        
        q_loss = self.q_loss_fn(pred.view(-1, *s[2:])[:, 3:],
                                targ.view(-1, *s[2:])[:, 3:])
        
        vo_t_loss = self.t_loss_fn(pred_vos.view(-1, *s[2:])[:, :3],
                                   targ_vos.view(-1, *s[2:])[:, :3])
        
        vo_q_loss = self.q_loss_fn(pred_vos.view(-1, *s[2:])[:, 3:],
                                   targ_vos.view(-1, *s[2:])[:, 3:])
        
        if self.learn_log:
            loss_pose = (
                t_loss / (2 * torch.exp(2 * self.sax)) +
                q_loss / (2 * torch.exp(2 * self.saq)) +
                vo_t_loss / (2 * torch.exp(2 * self.srx)) + 
                vo_q_loss / (2 * torch.exp(2 * self.srq)) +
                self.sax + self.saq + self.srx + self.srq 
            )
        else:
            loss_pose = (
                t_loss / (2 * self.sax * self.sax) +
                q_loss / (2 * self.saq * self.saq) +
                vo_t_loss / (2 * self.srx * self.srx) + 
                vo_q_loss / (2 * self.srq * self.srq) +
                torch.log(self.sax * self.saq * self.srx * self.srq)
            )
        
        if self.dual_target:
            s = sem_targ.size()
            sem_targ = sem_targ.view(-1,*s[2:])
            s_loss = self.sem_loss(sem_pred, sem_targ)
            if self.learn_log:
                loss_semantic = (s_loss / torch.exp(2 * self.sas) + 
                             self.sas)
            else:
                loss_semantic = (s_loss / (self.sas * self.sas) + 
                             torch.log(self.sas))
        else:
            loss_semantic = 0
        
        
        loss = loss_pose + loss_semantic

        return loss
Example #5
0
    def forward(self, pred, targ):
        """
        :param pred: N x T x 6
        :param targ: N x T x 6
        :return:
        """

        if self.dual_target:
            pred, sem_pred = pred[0], pred[1]
            targ, sem_targ = targ[0], targ[1]
        if len(pred.size()) < 3:
            pred = pred.unsqueeze(0)
        s = pred.size()
        
        # absolute pose loss
        # get the VOs
        pred_vos = pose_utils.calc_vos_simple(pred)
        targ_vos = pose_utils.calc_vos_simple(targ)
    
        t_loss = self.t_loss_fn(pred.view(-1, *s[2:])[:, :3],
                                targ.view(-1, *s[2:])[:, :3])
        
        q_loss = self.q_loss_fn(pred.view(-1, *s[2:])[:, 3:],
                                targ.view(-1, *s[2:])[:, 3:])
        
        
        vo_t_loss = self.t_loss_fn(pred_vos.view(-1, *s[2:])[:, :3],
                                   targ_vos.view(-1, *s[2:])[:, :3]) if not ((type(pred_vos) == list and len(pred_vos) == 0) or (type(targ_vos) == list and len(targ_vos) == 0)) else 0.0
        
        vo_q_loss = self.q_loss_fn(pred_vos.view(-1, *s[2:])[:, 3:],
                                   targ_vos.view(-1, *s[2:])[:, 3:]) if not ((type(pred_vos) == list and len(pred_vos) == 0) or (type(targ_vos) == list and len(targ_vos) == 0)) else 0.0
        
        
        abs_loss =(
            torch.exp(-self.sax) * t_loss + 
            self.sax + 
            torch.exp(-self.saq) * q_loss +
            self.saq
        )
        
        vo_loss = (
            torch.exp(-self.srx) * vo_t_loss + 
            self.srx + 
            torch.exp(-self.srq) * vo_q_loss + 
            self.srq
        )
        
        loss_pose = (abs_loss + vo_loss)
        loss_list = [t_loss, q_loss]
        
        if self.dual_target:
            s = sem_targ.size()
            sem_targ = sem_targ.view(-1,*s[2:])
            s_loss = self.sem_loss(sem_pred, sem_targ)
            
            loss_semantic = torch.exp(-self.sas) * s_loss + self.sas
            loss_list.append(s_loss)
        else:
            loss_semantic = 0
        
        loss = loss_pose + loss_semantic
        return loss, loss_list