Compute logits for all images in the dataset using the provided model and store them in logits_file.
(self, model, logits_file)
| 156 | return len(self.imgs) |
| 157 | |
| 158 | def compute_logits(self, model, logits_file): |
| 159 | """Compute logits for all images in the dataset using the provided model |
| 160 | and store them in logits_file.""" |
| 161 | |
| 162 | batch_size = 11 |
| 163 | model.eval() |
| 164 | dataloader = iter(data.DataLoader(self, batch_size=batch_size, shuffle=False)) |
| 165 | logits = np.zeros((len(self.ids), 8142)) |
| 166 | i = 0 |
| 167 | while True: |
| 168 | i += 1 |
| 169 | try: |
| 170 | batch = next(dataloader) |
| 171 | indices = np.in1d(self.ids, batch[1].detach().cpu().numpy()).nonzero()[0] |
| 172 | logits[indices] = model(batch[0].cuda()).detach().cpu().numpy().tolist() |
| 173 | if i * batch_size % 1001 == 0: |
| 174 | print(f"{i * batch_size} images processed") |
| 175 | except StopIteration: |
| 176 | break |
| 177 | |
| 178 | np.save(logits_file, logits) |
| 179 | |
| 180 | def compute_features(self, model, logits_file): |
| 181 | """Compute logits for all images in the dataset using the provided model |
nothing calls this directly
no outgoing calls
no test coverage detected