but during the test, I have too many indices because my test data is automatically labeled by ImageFolder. A solution is to drop the classes but I don’t know How
An easy solution would be to just drop the labels and use your test data in the DataLoader loop:
for data, _ in loader:
data = data.to(device)
...
This approach is a bit hacky, so the cleaner solution would be to write your own test dataset:
class TestDataset(Dataset):
def __init__(self, path, transform=None):
self.image_paths = glob.glob(path + '*.jpg')
self.transform = transform
def __getitem__(self, index):
x = Image.open(self.image_paths[index])
if self.transform is not None:
x = self.transform(x)
return x
def __len__(self):
return len(self.image_paths)