haofanwang / Score-CAM

Official implementation of Score-CAM in PyTorch
MIT License
399 stars 66 forks source link

Is it this acceleration resonable #29

Closed cyy280113999 closed 1 year ago

cyy280113999 commented 1 year ago

I found that some of activations are nearly zeros, I want to remove these calculations.

# short cut ratio
self.top_percent = 0.1
# 10% same quality

# use activation as masks
activations = self.activations

# remove useless activations by sorted mean activation , leave sub-masks 
top_count = int(self.top_percent * activations.shape[1])
channel_scores = activations.mean(axis=[2, 3], keepdim=False).flatten()
top_indice = channel_scores.argsort(0,descending=True)[:top_count]
sub_masks = activations[:, top_indice]  # only these will be computed
haofanwang commented 1 year ago

You can pre-select some maps instead of feeding all into forward passing to achieve accelerate. The visual performance should be similar.