I am trying to get my data loader that I have created into fastai’s ImageDataBunch
. However, when I try to do data.show_batch()
I get the following error:
--> 188 n_items = rows **2 if self.train_ds.x._square_show else rows
189 if self.dl(ds_type).batch_size < n_items: n_items = self.dl(ds_type).batch_size
190 xs = [self.train_ds.x.reconstruct(grab_idx(x, i)) for i in range(n_items)]
AttributeError: 'Data' object has no attribute 'x'
My dataset looks like below:
class Data(Dataset):
def __init__(self, df, size, base):
self.labels = df["target"].values
self.size = size
self.base = base
self.current = None
def __len__(self):
return len(self.labels)
def __getitem__(self, i):
batch = i // self.size
if self.current != self.base + str(batch) + ".npy":
self.current = self.base + str(batch) + ".npy"
self.current_batch = np.load(self.current) #.transpose((0,3,1,2))
i = i % self.size
return self.current_batch[i], self.labels[i]
Should I be trying to go down this path, or is there simply too much fiddling around to get this to work. The main reasons I want to go down this path is:
- I want to use fastai’s transforms.
- I want to use the fastai’s LR finder/ discrimnative LRs (which I understand is part of learner and not databunch).
So my questions are:
- Can I get my dataloader into a databunch + transforms?
- If not, is there a way to use say albumentations + with a fastai Learner class?
- Does my Dataset class have to return data in the format of BS x C x H x W or is it expecting BS x H x W x C