I downloaded the ImageNet dataset from Kaggle, as it seems like the original website doesn’t have it anymore. When I try to load it with Pytorch following this:
torchvision.datasets.ImageNet(root: Union[str, Path], split: str = 'train', **kwargs: Any)
I get RuntimeError: The archive ILSVRC2012_devkit_t12.tar.gz is not present in the root directory or is corrupted. You need to download it externally and place it in
As Kaggle doesn’t have the same gz
file. Instead, the data looks like:
/media/SSD2/ILSVRC/
|----Annotation
|----ImageSets
|----Data
|----CLS-LOC
|----test
|----ILSVRC2012_val_00000009.JPEG
|----ILSVRC2012_val_00000010.JPEG
|----...
|----train
|----n01440764 # this is a class
|----ILSVRC2012_val_00000010.JPEG
|----ILSVRC2012_val_00000010.JPEG
|----n01443537
|----...
|----val
|----ILSVRC2012_val_00000009.JPEG
|----ILSVRC2012_val_00000010.JPEG
|----...
I found that people on Kaggle load it differently, and I could not figure out the script they referred to here.
I was loading previous datasets like this so I can use the transformation:
trainset = torchvision.datasets.ImageNet(root='path_to_dataset', split='train', download=False, transform=transform_train)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=bs, shuffle=True, num_workers=8)
Where my transformation is something like
transform_train = transforms.Compose([
transforms.RandomCrop(32, padding=4),
transforms.Resize(size),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
])
I couldn’t find an original Pytorch script to load the dataset, which is very bizarre as this is one of the most popular datasets.