Args: windows: (num_windows*B, window_size, window_size, C) window_size (int): Window size H (int): Height of image W (int): Width of image Returns: x: (B, H, W, C)
(windows, window_size, H, W)
| 122 | |
| 123 | |
| 124 | def window_reverse(windows, window_size, H, W): |
| 125 | """ |
| 126 | Args: |
| 127 | windows: (num_windows*B, window_size, window_size, C) |
| 128 | window_size (int): Window size |
| 129 | H (int): Height of image |
| 130 | W (int): Width of image |
| 131 | Returns: |
| 132 | x: (B, H, W, C) |
| 133 | """ |
| 134 | B = int(windows.shape[0] / (H * W / window_size / window_size)) |
| 135 | x = windows.view(B, H // window_size, W // window_size, window_size, window_size, -1) |
| 136 | x = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(B, H, W, -1) |
| 137 | return x |
| 138 | |
| 139 | |
| 140 | def calc_rel_pos_spatial( |