Extract one frame feature everytime.
(model, frame, return_h_w=False)
| 151 | |
| 152 | |
| 153 | def extract_feature(model, frame, return_h_w=False): |
| 154 | """Extract one frame feature everytime.""" |
| 155 | out = model.get_intermediate_layers(frame.unsqueeze(0).cuda(), n=1)[0] |
| 156 | # out = out[:, 1:, :] # we discard the [CLS] token |
| 157 | h, w = int(frame.shape[1] / model.patch_embed.patch_size), int(frame.shape[2] / model.patch_embed.patch_size) |
| 158 | dim = out.shape[-1] |
| 159 | out = out[0].reshape(h, w, dim) |
| 160 | out = out.reshape(-1, dim) |
| 161 | if return_h_w: |
| 162 | return out, h, w |
| 163 | return out |
| 164 | |
| 165 | |
| 166 | def imwrite_indexed(filename, array, color_palette): |
no test coverage detected