| 17 | |
| 18 | |
| 19 | class CLIPCapDataset(torch.utils.data.Dataset): |
| 20 | def __init__(self, data, append=False, prefix='A photo depicts'): |
| 21 | self.data = data |
| 22 | self.prefix = '' |
| 23 | if append: |
| 24 | self.prefix = prefix |
| 25 | if self.prefix[-1] != ' ': |
| 26 | self.prefix += ' ' |
| 27 | |
| 28 | def __getitem__(self, idx): |
| 29 | c_data = self.data[idx] |
| 30 | c_data = clip.tokenize(self.prefix + c_data, truncate=True).squeeze() |
| 31 | return {'caption': c_data} |
| 32 | |
| 33 | def __len__(self): |
| 34 | return len(self.data) |
| 35 | |
| 36 | |
| 37 | def Convert(image): |
no outgoing calls
no test coverage detected