ValueError: 1 is not in range (CustomDataSet)

Hi, I have some images in a folder. I made my CustomDataSet get these images.

def __init__(self, main_dir, label_full, transform):
           #Reading path and doing some operations
          #sorting images based on the name
        self.all_imgs = sorted(os.listdir(main_dir), key= lambda x : int(x.split("_")[0]))

def __getitem__(self, idx):
         train_label_price = torch.tensor((self.labels[idx]))
         img_loc = os.path.join(self.main_dir, self.all_imgs[idx])
        image = Image.open(img_loc).convert("RGB")
        tensor_image = self.transform(image)

        return (tensor_image.type(torch.double), train_label_price.type(torch.double))

When I am running my data_loader() method I am getting an error

def data_loader():
    # Some path and transformation ...
    train_loader = DataLoader(train_data_tensor, batch_size= 10, num_workers= 0, shuffle= False)
    
    train_data_loader_iter = iter(train_loader)
    images, labels = train_data_loader_iter.next()
    print(labels) // Nothing is printing

The error I am getting

Traceback (most recent call last):
  File "/home/akib/.local/lib/python3.8/site-packages/pandas/core/indexes/range.py", line 355, in get_loc
    return self._range.index(new_key)
ValueError: 1 is not in range

Could you tell me, why I am getting this error and why my CustomDataSet is not working?

Your code snippet doesn’t seem to include all definitions, as e.g. self.labels is not defined in the __init__ method. Based on the error message it seems self.labels (or any other missing code) is a pandas.DataFrame, which is raising this indexing issue, so you would have to make sure the length of this DataFrame matches the length of the dataset.