Skip to content

For anyone who would like to use this with torchvision #1

Description

@Surayuth

You need to change the names of class folders (0, 1, 2, ..) to index codes which are specified in the json files.
The example below shows how you could create 'val' dataset using torchvision:

import os
from pathlib import Path

with open('path/to/ImageNet_class_index.json') as f:
    d = json.load(f)

root = Path("path/to/ImageNet/val")
for path in root.iterdir():
    idx = path.name
    new_path = path.parent / d[idx][0]
    os.rename(str(path), str(new_path))

Then, you can create imagenet dataset using torchvision by

dataset = ImageNet(root="ImageNet", split="val")

Note that you also need ILSVRC2012_devkit_t12.tar.gz which can be downloaded from the imagenet website.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions