I was trying to rewrite my code from fastai1 to fastai2 due to GPU incompatibility, and I run into a problem with extracting images:
fastai1 (extract all images from train_ds): data.train_ds.x
I have 100,000 images as input, and my list comprehension technique doesn’t work (the thread was killed every time I try to run it): [x[0] for x in data.train_ds]
Is there a better way to extract all the images in fastai2 from train_ds?
I wanted to create a custom dataset based on fastai Dataset class which perform some changes to images and labels. The data object I created is similar to
I think dls.train.xs only works for Tabular data with TabularPandas (please correct me if I am wrong), but I had used DataBlock which doesn’t have ‘.train.xs’ as an attribution (sorry for not mentioning this in the question)?
Yes! The reason why I want to extract all the images is to custom changes to the dataset. Since the way I structured my code (creating a custom dataset) allows me to use getitem(self, i), I just extract the images using img[i][0] there.
# loop through all the indexes of your dataloader
for i in data.train_ds.get_idxs():
# create a file that has the index in the filename
with open(f'train{i}.datatype', 'w') as f:
# write create_item output to file
f.write(data.train_ds.create_item(i)