Skip to content

Instantly share code, notes, and snippets.

@mpatacchiola
Last active June 28, 2019 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpatacchiola/3e82d5790f66bae39c77cdbabac883a6 to your computer and use it in GitHub Desktop.
Save mpatacchiola/3e82d5790f66bae39c77cdbabac883a6 to your computer and use it in GitHub Desktop.
This script moves the images from the `val/images` folder to the `val/class_id` folder. This is useful if you want to load the dataset with torchvision ImageFolder class. Run the script from the `tiny-imagenet-200` folder. The dataset can be downloaded from https://tiny-imagenet.herokuapp.com
import shutil
import os
for i, line in enumerate(map(lambda s: s.strip(), open("./val/val_annotations.txt"))):
name, wnid = line.split("\t")[0:2]
origin_path_file = "./val/images/" + name
destination_path = "./val/" + wnid
destination_path_file = "./val/" + wnid + "/" + name
if not os.path.exists(destination_path): os.makedirs(destination_path)
shutil.move(origin_path_file, destination_path_file)
print(destination_path_file)
os.rmdir("./val/images")
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment