I am trying to solve this problem by using a convolutional NN to classify an image data set to check the type of disease it is. I have reached task 1b and trying to implement the training loop. However, I am getting an error and can't understand how to implement the training loop.
I am sharing the google drive link.
The code in task 1b where I am getting an error:
import datasets ds = datasets.LesionDataset('/content/data/img', '/content/data/img/train.csv') input, label = ds print(input) print(label)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-27-dcb680f1f34a> in <module>() 4 ds = datasets.LesionDataset('/content/data/img', 5 '/content/data/img/train.csv') ----> 6 input, label = ds 7 print(input) 8 print(label) /content/drive/MyDrive/DL Assignment/datasets.py in __getitem__(self, idx) 34 def __getitem__(self, idx): 35 ---> 36 image = self.img_dir[idx] 37 label = self.labels_fname[idx] 38
'datasets' is a .py file currently in the same folder in the link shared which has the following code: You can open the link to understand it better.
import collections import csv from pathlib import Path import numpy as np import torch import torchvision.transforms as transforms from PIL import Image import pandas as pd # TODO Task 1b - Implement LesionDataset from torch.utils.data import Dataset class LesionDataset(Dataset): #The __init__ function should have the following prototype def __init__(self, img_dir, labels_fname): # is the directory path with all the image files # is the csv file with image ids and their corresponding labels self.img_dir = Path(img_dir) #image = Image.open('ISIC_0024306.jpg') # self.labels_fname = pd.read_csv(labels_fname) image = self.labels_fname['image'] #list of images store in list def __len__(self): return len(self.labels_fname) def __getitem__(self, idx): image = self.img_dir[idx] label = self.labels_fname[idx] return image, label # TODO Task 1e - Add augment flag to LesionDataset, so the __init__ function # now look like this: # def __init__(self, img_dir, labels_fname, augment=False): # TODO Task 2b - Implement TextDataset # The __init__ function should have the following prototype # def __init__(self, fname, sentence_len) # - fname is the filename of the cvs file that contains each # news headlines text and its corresponding label. # - sentence_len the maximum sentence length you want the # tokenized to return. Any sentence longer than that should # be truncated by the tokenizer. Any shorter sentence should # padded by the tokenizer. # We will be using the pretrained 'distilbert-base-uncased' transform, # so please use the appropriate tokenizer for it. NOTE: You will need # to include the relevant import statement.
I am stuck at this part. Can anyone suggest how to implement it?