Compute logits for all images in the dataset using the provided model and store them in logits_file.
(self, model, logits_file)
| 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 |
| 182 | and store them in logits_file.""" |
| 183 | |
| 184 | batch_size = 11 |
| 185 | model.eval() |
| 186 | dataloader = iter(data.DataLoader(self, batch_size=batch_size, shuffle=False)) |
| 187 | logits = np.zeros((len(self.ids), 8142)) |
| 188 | i = 0 |
| 189 | while True: |
| 190 | i += 1 |
| 191 | try: |
| 192 | batch = next(dataloader) |
| 193 | indices = np.in1d(self.ids, batch[1].detach().cpu().numpy()).nonzero()[0] |
| 194 | logits[indices] = model(batch[0].cuda()).detach().cpu().numpy().tolist() |
| 195 | if i * batch_size % 1001 == 0: |
| 196 | print(f"{i * batch_size} images processed") |
| 197 | except StopIteration: |
| 198 | break |
| 199 | |
| 200 | np.save(logits_file, logits) |
| 201 | |
| 202 | def load_inat_location_data(ip_dir, loc_file_name, ann_file_name, remove_empty=True): |
| 203 | print('Loading ' + os.path.basename(loc_file_name)) |
nothing calls this directly
no outgoing calls
no test coverage detected