Search code examples
pytorchtorchtorchvisionimagenet

Problem with Loading tiny imagenet via torch DataLoader


I'm using tiny-imagenet-200 and I'm not sure that loading them with torch.utils.data.DataLoader is possible or not. I downloaded tiny-imagenet-200 from Stanford site, but the format of validation set in a directory with name val_0 to val_9999 and the label of them is in a .txt. How can I load this directory via torch.utils.data.DataLoader? I tried:

datasets.ImageFolder(args.val_dir, transforms.Compose([
            OpencvResize(256),
            transforms.CenterCrop(224),
            ToBGRTensor(),
        ]) 

but it doesn't work.


Solution

  • You can't do that using ImageFolder directly. There are alternatives, though:

    • You can read the annotation file and re-structure the directories to enable the usage of ImageFolder, as in here;
    • You can implement a custom Dataset. Luckly, as Tiny ImageNet is a popular dataset, you can find many implementations online. For instance, this one.