yeezhu / SPN.pytorch

PyTorch implementation of "Soft Proposal Networks for Weakly Supervised Object Localization", ICCV 2017.
http://yzhu.work/spn.html
MIT License
211 stars 37 forks source link

Code or suggestions for extracting proposal map and generating bounding box #6

Closed zhangyuygss closed 6 years ago

zhangyuygss commented 6 years ago

I modified the model definition code to extract the proposal map and the output feature of SP layer for bounding box generating, but not sure if I was doing it right. So could you please release code for that part?

yeezhu commented 6 years ago

@zhangyuygss We plan to release more demo code later; we are too busy these days.

vadimkantorov commented 6 years ago

@yeezhu For the bounding box, does the following match your box generation procedure?

def deduce_tightest_box_from_class_specific_convolutional_map(conv_map, image_height, image_width):
  binary_map = conv_map > conv_map.mean()
  IJ = binary_map.nonzero()

  # x1, y1, x2, y2
  return (float(image_width)  * IJ[:, 1].min() / conv_map.size(1), \
          float(image_height) * IJ[:, 0].min() / conv_map.size(0), \
          float(image_width)  * IJ[:, 1].max() / conv_map.size(1), \
          float(image_height) * IJ[:, 0].max() / conv_map.size(0))

Are you doing any filtering of the binary_map to remove spurious spikes?

Thanks!

vadimkantorov commented 6 years ago

especially with the CVPR deadline approaching :)

yeezhu commented 6 years ago

@vadimkantorov Sorry for the delay. The code snippet seems fine, but we resize the map to raw image size first.

vadimkantorov commented 6 years ago

@yeezhu Thanks for getting back on this!

For generating the class-specific score map in test time, is the snippet below accurate? (it seems so from equation R_c = \sum_k w_{k,c} * U_k \cdot M in the paper, except the equation doesn't consider the bias term)

class SPNetWSL(nn.Module):
# ....
  def generate_class_specific_score_maps(self, x, use_soft_proposals = True): 
         x = self.features(x)
         x = self.spatial_pooling.adconv(x)
         x = self.spatial_pooling.maps(x)
         if use_soft_proposals:
             x = self.spatial_pooling.sp(x)
         x = self.classifier(x.unsqueeze(-1).transpose(-4, -1)).transpose(-4, -1).squeeze(-1)
         return x

Thanks :)

yeezhu commented 6 years ago

@vadimkantorov Yes, the bias term is not considered.

yeezhu commented 6 years ago

@zhangyuygss The demo was released. If you have other questions, please email me :)