Args: x: (B, H, W, C) window_size (int): window size Returns: windows: (num_windows*B, window_size, window_size, C)
(x, window_size)
| 99 | |
| 100 | |
| 101 | def window_partition(x, window_size): |
| 102 | """ |
| 103 | Args: |
| 104 | x: (B, H, W, C) |
| 105 | window_size (int): window size |
| 106 | Returns: |
| 107 | windows: (num_windows*B, window_size, window_size, C) |
| 108 | """ |
| 109 | B, H, W, C = x.shape |
| 110 | x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) |
| 111 | windows = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(-1, window_size, window_size, C) |
| 112 | return windows |
| 113 | |
| 114 | |
| 115 | def window_reverse(windows, window_size, H, W): |