Create input for linear classifier from intermediate features.
(x_tokens_list, use_n_blocks: int, use_avgpool: bool)
| 135 | # ============================================================================ |
| 136 | |
| 137 | def create_linear_input(x_tokens_list, use_n_blocks: int, use_avgpool: bool) -> torch.Tensor: |
| 138 | """Create input for linear classifier from intermediate features.""" |
| 139 | intermediate_output = x_tokens_list[-use_n_blocks:] |
| 140 | output = torch.cat([class_token for _, class_token in intermediate_output], dim=-1) |
| 141 | |
| 142 | if use_avgpool: |
| 143 | output = torch.cat( |
| 144 | ( |
| 145 | output, |
| 146 | torch.mean(intermediate_output[-1][0], dim=1), # patch tokens |
| 147 | ), |
| 148 | dim=-1, |
| 149 | ) |
| 150 | output = output.reshape(output.shape[0], -1) |
| 151 | |
| 152 | return output.float() |
| 153 | |
| 154 | |
| 155 | class LinearClassifier(nn.Module): |
no outgoing calls
no test coverage detected