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

How to deal with the conv in SE module? #54

Closed
RainFrost1 opened this issue Aug 22, 2023 · 4 comments
Closed

How to deal with the conv in SE module? #54

RainFrost1 opened this issue Aug 22, 2023 · 4 comments

Comments

@RainFrost1
Copy link

No description provided.

@WailordHe
Copy link

same question

@yxchng
Copy link

yxchng commented Aug 29, 2023

any updates?

@RainFrost1
Copy link
Author

Looking forward your reply, any suggestions? @keyu-tian

@keyu-tian
Copy link
Owner

keyu-tian commented Aug 31, 2023

@RainFrost1 @will1973 @yxchng SE module contains two linear layers (channel-wise) and one global average pooling. No changes required to the linear layers. As for the global pooling on a masked feature map, one should calculate the mean value at unmasked positions only. To implement this you can use our function _get_active_ex_or_ii in https://github.com/keyu-tian/SparK/blob/main/pretrain/encoder.py#L30 like:

class SparseGlobalAveragePooling(nn.Module):
    def forward(self, x):   # shape: BCHW
        B, C, H, W = x.shape
        unmasked_positions = _get_active_ex_or_ii(H=H, W=W, returning_active_ex=True)  # shape: B1HW
        mean = (x * unmasked_positions).sum(dim=(2,3), keepdims=True) / unmasked_positions.sum(dim=(2,3), keepdims=True)
        return mean         # shape: BC11

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

4 participants