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:
for i in imagelabels['image_id']:
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.
I am not sure about your code, but there is easier ways to handle it. You can define your custom Dataset class and have all data in each iteration just by setting batch_size=len(data) and you no longer have to change your code for different purposes. And also, you have to implement __len__ function too.
Here is conventional implementation of custom dataset class:
After creating such a Dataset, you can use it for different purposes like this:
You are welcome.
I think best way to learn about best practices is to read the well-constructed codes which in this case, we can refer to implemented models in PyTorch iteslf. For instance, ResNet, VGG, etc have been implemented by PyTorch developers and they used most general and easy ways to do it, so by reading these codes, we can adopt and have a more reliable codes.