| 47 | return len(self.samples) |
| 48 | |
| 49 | def __getitem__(self, idx: int) -> Tuple[torch.Tensor, int]: |
| 50 | img_path, label = self.samples[idx] |
| 51 | |
| 52 | try: |
| 53 | image = Image.open(img_path).convert('RGB') |
| 54 | except Exception as e: |
| 55 | print(f"Error loading image {img_path}: {e}") |
| 56 | image = Image.new('RGB', (224, 224), color='black') |
| 57 | |
| 58 | if self.transform: |
| 59 | image = self.transform(image) |
| 60 | |
| 61 | if self.target_transform: |
| 62 | label = self.target_transform(label) |
| 63 | |
| 64 | return image, label |
| 65 | |
| 66 | class SyntheticDataset(Dataset): |
| 67 | def __init__( |