Spaces:
Paused
Paused
| import logging | |
| import torch | |
| from PIL import Image | |
| from torchvision import transforms | |
| from library.utils import setup_logging | |
| setup_logging() | |
| logger = logging.getLogger(__name__) | |
| class ImageLoadingDataset(torch.utils.data.Dataset): | |
| def __init__(self, image_paths): | |
| self.images = image_paths | |
| def __len__(self): | |
| return len(self.images) | |
| def __getitem__(self, idx): | |
| img_path = self.images[idx] | |
| try: | |
| image = Image.open(img_path).convert("RGB") | |
| # convert to tensor temporarily so dataloader will accept it | |
| tensor_pil = transforms.functional.pil_to_tensor(image) | |
| except Exception as e: | |
| logger.error(f"Could not load image path / 画像を読み込めません: {img_path}, error: {e}") | |
| return None | |
| return (tensor_pil, img_path) | |