2021-08-16 00:53:00 +00:00
|
|
|
import logging
|
2022-06-28 09:36:43 +00:00
|
|
|
import os
|
2021-08-16 00:53:00 +00:00
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
from PIL import Image
|
|
|
|
from torch.utils.data import Dataset
|
|
|
|
|
|
|
|
|
2022-06-27 14:40:04 +00:00
|
|
|
class SphereDataset(Dataset):
|
2022-06-28 09:36:43 +00:00
|
|
|
def __init__(self, image_dir, transform=None):
|
|
|
|
self.image_dir = image_dir
|
|
|
|
self.transform = transform
|
|
|
|
self.images = os.listdir(image_dir)
|
2021-08-16 00:53:00 +00:00
|
|
|
|
|
|
|
def __len__(self):
|
2022-06-28 09:36:43 +00:00
|
|
|
return len(self.images)
|
2022-06-27 14:40:04 +00:00
|
|
|
|
2022-06-28 09:36:43 +00:00
|
|
|
def __getitem__(self, index):
|
|
|
|
img_path = os.path.join(self.image_dir, self.images[index])
|
|
|
|
image = np.array(Image.open(img_path).convert("RGB"), dtype=np.uint8)
|
2021-08-16 00:53:00 +00:00
|
|
|
|
2022-06-29 08:20:35 +00:00
|
|
|
mask = np.zeros((image.shape[0], image.shape[1]), dtype=np.uint8)
|
2021-08-16 00:53:00 +00:00
|
|
|
|
2022-06-28 09:36:43 +00:00
|
|
|
if self.transform is not None:
|
|
|
|
augmentations = self.transform(image=image, mask=mask)
|
|
|
|
image = augmentations["image"]
|
2022-06-29 08:20:35 +00:00
|
|
|
mask = augmentations["mask"].float()
|
2021-08-16 00:53:00 +00:00
|
|
|
|
2022-06-28 09:36:43 +00:00
|
|
|
return image, mask
|