lundi 19 juillet 2021

Dataset class is not returning length of testing dataset

My CNN model has a training, validation, and testing dataset. A part of the dataset class is as below which is able to return train_list and val_list length but I am not sure why it couldn't return test_list length. I checked the test_list before function def __len__(self) and it exists.

class dataset(Dataset):
   def __init__(self, num, transform, path0=os.getcwd(), 
                is_train=True,is_val=True, loader=loader):
               
       # produce a 64%, 16%, 20% split for training, validation and test sets.
       rng = np.random.RandomState(42)  # reproducible results with a fixed seed
       indices = np.arange(num)
       rng.shuffle(indices)

       self.train_list, self.val_list, self.test_list =np.split(indices,
       [int(.64*len(indices)), int(.8*len(indices))])  # split to 64% of training, 16% of validation and 20% of testing
       
       self.is_train = is_train
       self.is_val = is_val      
       self.loader = loader
       self.transform = transform
       
          
   def __len__(self):
      if self.is_train is True:
          print(len(self.train_list))  # works
          return len(self.train_list)
      elif self.is_val is True:
          print(len(self.val_list))
          return len(self.val_list)    # works
      else:
          print(len(self.test_list))
          return len(self.test_list)   # not working

Aucun commentaire:

Enregistrer un commentaire