I am training my model in Slurm and using the preprocessed UW-Madison GI Tract Medical Segmentation Dataset from learnopencv.com.
The Model trained around 82 epochs but at the half of 83 epochs it stops and show this error FileNotFoundError: [Errno 2] No such file or directory: './data/dataset_UWM_GI_Tract_train_valid/train/images/case77_day20_slice_0095_266_266_1.50_1.50.png'
.
.
I have used another model to train with same dataset and eventually it works fine.
This is my code for dataset.
class MedicalDataset1(Dataset):
def __init__(self, image_paths, mask_paths, img_size, ds_mean, ds_std, is_train=False):
self.image_paths = image_paths
self.mask_paths = mask_paths
self.is_train = is_train
self.img_size = img_size
self.ds_mean = ds_mean
self.ds_std = ds_std
self.transforms = self.setup_transforms(mean=self.ds_mean, std=self.ds_std)
self.train_imgs = sorted(os.listdir(image_paths))
self.train_msks = sorted(os.listdir(mask_paths))
def __len__(self):
return len(self.train_imgs)
def setup_transforms(self, mean, std):
transforms = []
if self.is_train:
transforms.extend([
A.HorizontalFlip(p=0.5), A.VerticalFlip(p=0.5),
A.ShiftScaleRotate(scale_limit=0.12, rotate_limit=0.15, shift_limit=0.12, p=0.5),
A.RandomBrightnessContrast(p=0.5),
A.CoarseDropout(max_holes=8, max_height=self.img_size[1]//20, max_width=self.img_size[0]//20, min_holes=5, fill_value=0, mask_fill_value=0, p=0.5)
])
transforms.extend([
A.Normalize(mean=mean, std=std, always_apply=True),
ToTensorV2(always_apply=True), # (H, W, C) --> (C, H, W)
])
return A.Compose(transforms)
def __getitem__(self, idx):
img_filename = self.train_imgs[idx]
mask_filename = self.train_msks[idx]
img_path = os.path.join(self.image_paths, img_filename)
mask_path = os.path.join(self.mask_paths, mask_filename)
image = np.array(Image.open(img_path).convert('RGB').resize((224,224),Image.NEAREST))
mask = np.array(Image.open(mask_path).resize((224,224),Image.NEAREST))
transformed = self.transforms(image=image, mask=mask)
image, mask = transformed["image"], transformed["mask"].to(torch.long)
return image, mask