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

add *Swin MLP*: a hierarchical fully MLP architecture using shifted windows. #90

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
update
  • Loading branch information
zeliu98 committed Jul 3, 2021
commit ddb0e50235038d1b6cfd2f174066ec6908ed2eb9
11 changes: 6 additions & 5 deletions models/swin_mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as checkpoint
import numpy as np
from timm.models.layers import DropPath, to_2tuple, trunc_normal_


Expand Down Expand Up @@ -167,12 +166,14 @@ def extra_repr(self) -> str:
def flops(self):
flops = 0
H, W = self.input_resolution
Hp = int(np.ceil(H / self.window_size)) * self.window_size
Wp = int(np.ceil(W / self.window_size)) * self.window_size
# norm1
flops += self.dim * H * W
# W-MSA/SW-MSA
nW = Hp * Wp / self.window_size / self.window_size

# Window/Shifted-Window Spatial MLP
if self.shift_size > 0:
nW = (H / self.window_size + 1) * (W / self.window_size + 1)
else:
nW = H * W / self.window_size / self.window_size
flops += nW * self.dim * (self.window_size * self.window_size) * (self.window_size * self.window_size)
# mlp
flops += 2 * H * W * self.dim * self.dim * self.mlp_ratio
Expand Down