I wrote the following code to get the name of the label of every image from a csv file which has the corresponding label for every image In this case the number of labels are three how can i modify my CustomDataset to return one-hot-encoded tensors instead of text  labels
This my code ,i have three labels namely “YOUNG”,“MIDDLE”,“OLD”.
class CustomDataset(Dataset):
  def __init__(self, labels_df, img_path, transform=None):
    self.labels_df=labels_df
    self.img_path=img_path
    self.transform=transform
    
  def __len__(self):
    return  len(self.labels_df)
  
  def __getitem__(self,idx):
    image_name=os.path.join(self.img_path, self.labels_df.ID[idx])
    #img=io.imread(image_name)
    img=Image.open(image_name).convert('RGB')
    label=self.labels_df.Class[idx]
    
    
    
    if self.transform:
      img=self.transform(img)
    return [img, label]  

This is how my csv file looks like

csv.PNG119×524 4.25 KB