Hi fellow FastAI users !
I’m working on the PenFundanDataset for image segmentation. I’ve created a custom pytorch dataset because I find that easier than the data block api, at least for now.
Here’s my dataset:
class SemSegDataset(Dataset):
def __init__(self, path):
super().__init__()
self.path = path
self.nb_elements = int(len(glob.glob(path + '/*.png'))/2)
self.c = 3
def __getitem__(self, idx):
im = np.array(Image.open(self.path + '/im{}.png'.format(idx)))
msk = np.array(Image.open(self.path + '/msk{}.png'.format(idx)))
im_t = self.apply_transform(im)
msk_t = self.apply_transform(msk, is_x = False)
return im_t, msk_t.unsqueeze(0)
def __len__(self):
return self.nb_elements
I’ve written a few sanity checks that return satisfying results:
s_dataset = SemSegDataset('./DebugDataset')
x,y = s_dataset[0]
print(x.shape, y.shape) # torch.Size([3, 224, 224]) torch.Size([1, 224, 224])
Creating the databunch is fine, but the learner returns an error saying that the dummy batch requires an iterable instead of a built-in function :
data = DataBunch.create(s_dataset, s_dataset, bs = 2, num_workers = 1)
learn = unet_learner(data, models.resnet34, metrics=metrics, wd=1e-2)
I tracked the error to the and in the fastai/vision/learner.py
file, I changed the following line from this size = data.train_ds[0][0].size
to this size = data.train_ds[0][0].size()
. Now, in this case, I get an error saying:
Expected 4-dimensional input for 4-dimensional weight 64 3 7 7 0, but got 5-dimensional input of size [1, 3, 3, 224, 224]
Do you guys know what’s causing this ? Any tips or advices regarding creating a custom dataset in fastai ?
Thanks a lot !