Last active
June 28, 2019 09:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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