I have a csv file which has the names of the specific images which have to be loaded into a dataloader from a folder. This csv file also contains the labels/classes of the images. I tried using a dataset class. I had written the below code:
class data(Dataset): def __init__(self,type='train',transform=None): self.imagecsv='' if type=='train': self.imagecsv=traincsv else: self.imagecsv=testcsv imagelabels=self.imagecsv[['image_id','Labels']] images= for i in imagelabels['image_id']: image=imread(os.path.join(path,i+'.jpg')) images.append(image) imagelabels['images']=images imagelabels.drop(columns='image_id') def __getitem__(self,idx): return imagelabels['images'][idx],imagelabels['Labels'][idx]
When I try to run this code, the system crashes everytime. I am running it on google colab with a GPU. I know I haven’t added an index parameter in the getitem function, it is because I need all the images whose names are specified in the training csv file. Is there a cleaner implementation which won’t crash my system? I also tried using Image.open but the system crashed again.