models/csam.py
def apply_local_softmax(self, filter_raw, pooling_features):
        """
        Apply a softmax filter only over each receptive field. 
        The logic here closely follows that of approach2. 
        Please see that documentation for a better understanding of what is happening here.
        """
        local_mask = self.local_mask.flatten(1).transpose(1, 0)                                                         # [Nc,HW] -> [HW,Nc]

        filter_exp = torch.exp(filter_raw - filter_raw.max(dim=1, keepdim=True)[0]).squeeze(-1)                         # [B,HW]
        filter_exp_sum = torch.matmul(filter_exp, local_mask)                                                           # [B,Nc]
        filter_exp_sum_inv = 1. / (filter_exp_sum + 6.1e-5)                                                             # [B,Nc]
        exp_weighted_features = pooling_features * filter_exp.unsqueeze(-1)                                             # [B,HW,C] x [B,HW,1] -> [B,HW,C]
        exp_weighted_features_sum = torch.matmul(exp_weighted_features.transpose(2, 1), local_mask).transpose(2, 1)     # ([B,HW,C] -> [B,C,HW]) x [HW,Nc] -> [B,C,Nc] -> [B,Nc,C]
        weighted_features = exp_weighted_features_sum * filter_exp_sum_inv.unsqueeze(-1)                                # [B,Nc,C] x ([B,Nc] -> [B,Nc,1]) -> [B,Nc,C]
        return weighted_features

        Apply a softmax filter only over each receptive field. 
        The logic here closely follows that of approach2. 
        Please see that documentation for a better understanding of what is happening here.
        
Apply a softmax filter only over each receptive field.
The logic here closely follows that of approach2.
Please see that documentation for a better understanding of what is happening here.
Apply a softmax filter only over each receptive field . The logic here closely follows that of approach2 . Please see that documentation for a better understanding of what is happening here .
def apply_local_softmax(self, filter_raw, pooling_features):
        local_mask = self.local_mask.flatten(1).transpose(1, 0)                                                         
        filter_exp = torch.exp(filter_raw - filter_raw.max(dim=1, keepdim=True)[0]).squeeze(-1)                         
        filter_exp_sum = torch.matmul(filter_exp, local_mask)                                                           
        filter_exp_sum_inv = 1. / (filter_exp_sum + 6.1e-5)                                                             
        exp_weighted_features = pooling_features * filter_exp.unsqueeze(-1)                                             
        exp_weighted_features_sum = torch.matmul(exp_weighted_features.transpose(2, 1), local_mask).transpose(2, 1)     
        weighted_features = exp_weighted_features_sum * filter_exp_sum_inv.unsqueeze(-1)                                
        return weighted_features
def apply_local_softmax ( self , filter_raw , pooling_features ) : local_mask = self . local_mask . flatten ( 1 ) . transpose ( 1 , 0 ) filter_exp = torch . exp ( filter_raw - filter_raw . max ( dim = 1 , keepdim = True ) [ 0 ] ) . squeeze ( - 1 ) filter_exp_sum = torch . matmul ( filter_exp , local_mask ) filter_exp_sum_inv = 1. / ( filter_exp_sum + 6.1e-5 ) exp_weighted_features = pooling_features * filter_exp . unsqueeze ( - 1 ) exp_weighted_features_sum = torch . matmul ( exp_weighted_features . transpose ( 2 , 1 ) , local_mask ) . transpose ( 2 , 1 ) weighted_features = exp_weighted_features_sum * filter_exp_sum_inv . unsqueeze ( - 1 ) return weighted_features
Apply a softmax filter only over each receptive field.
Apply a softmax filter only over each receptive field .
"""
        Apply a softmax filter only over each receptive field. 
        The logic here closely follows that of approach2. 
        Please see that documentation for a better understanding of what is happening here.
        """ # [Nc,HW] -> [HW,Nc] # [B,HW] # [B,Nc] # [B,Nc] # [B,HW,C] x [B,HW,1] -> [B,HW,C] # ([B,HW,C] -> [B,C,HW]) x [HW,Nc] -> [B,C,Nc] -> [B,Nc,C] # [B,Nc,C] x ([B,Nc] -> [B,Nc,1]) -> [B,Nc,C]
self
filter_raw
pooling_features