Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One loss Anchor selection for Class tgt #2

Open
jaideep11061982 opened this issue Jun 28, 2019 · 0 comments
Open

One loss Anchor selection for Class tgt #2

jaideep11061982 opened this issue Jun 28, 2019 · 0 comments

Comments

@jaideep11061982
Copy link

hi
below is the code for loss
in this one while building classification
clas_mask = matches>=0

Class mask will have 1 for even the bg position of anchors .
As before this we add 1 to matches tensor which has -1,-1,-1 for background, 0 for class and -2 for ignore.
that way we are taking in from Pred tensor even those anchors that are predicting the background.
Similar is the case fo bbox tensor.
Can you please let me know the rational behind taking into the account bg detecting tensor.

def _one_loss(self, clas_pred, bbox_pred, clas_tgt, bbox_tgt):
        
        bbox_tgt, clas_tgt = self._unpad(bbox_tgt, clas_tgt)
    
        matches = match_anchors(self.anchors, bbox_tgt)
    
        bbox_mask = matches>=0
        if bbox_mask.sum() != 0:
            
            bbox_pred = bbox_pred[bbox_mask]
     
            bbox_tgt = bbox_tgt[matches[bbox_mask]]
       
            bb_loss = self.reg_loss(bbox_pred, bbox_to_activ(bbox_tgt, self.anchors[bbox_mask]))
            
        else: 
            bb_loss = 0.
     
        
        matches.add_(1)
        clas_tgt = clas_tgt + 1
     
        
       
        clas_mask = matches>=0
  
        clas_pred = clas_pred[clas_mask]
    
        clas_tgt = torch.cat([clas_tgt.new_zeros(1).long(), clas_tgt]) #make one hong vector [0,1]
     
        clas_tgt = clas_tgt[matches[clas_mask]]
     
        return bb_loss , self._focal_loss(clas_pred, clas_tgt)/torch.clamp(bbox_mask.sum(), min=1.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant