(captions, model, device, batch_size=256, num_workers=8, append=False)
| 90 | |
| 91 | |
| 92 | def extract_all_captions(captions, model, device, batch_size=256, num_workers=8, append=False): |
| 93 | data = torch.utils.data.DataLoader( |
| 94 | CLIPCapDataset(captions, append=append), |
| 95 | batch_size=batch_size, num_workers=num_workers, shuffle=False) |
| 96 | all_text_features = [] |
| 97 | with torch.no_grad(): |
| 98 | for b in tqdm(data): |
| 99 | b = b['caption'].to(device) |
| 100 | all_text_features.append(model.encode_text(b).cpu().numpy()) |
| 101 | all_text_features = np.vstack(all_text_features) |
| 102 | return all_text_features |
| 103 | |
| 104 | |
| 105 | def extract_all_images(images, model, datasetclass, device, batch_size=64, num_workers=8): |
no test coverage detected