Args: x: (B, H, W, C) window_size (int): window size Returns: windows: (num_windows*B, window_size, window_size, C)
(x, window_size)
| 108 | |
| 109 | |
| 110 | def window_partition(x, window_size): |
| 111 | """ |
| 112 | Args: |
| 113 | x: (B, H, W, C) |
| 114 | window_size (int): window size |
| 115 | Returns: |
| 116 | windows: (num_windows*B, window_size, window_size, C) |
| 117 | """ |
| 118 | B, H, W, C = x.shape |
| 119 | x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) |
| 120 | windows = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(-1, window_size, window_size, C) |
| 121 | return windows |
| 122 | |
| 123 | |
| 124 | def window_reverse(windows, window_size, H, W): |