Last active
April 5, 2023 13:03
-
-
Save CookieLau/05bca97ab963ff09c04a87e8f7e06598 to your computer and use it in GitHub Desktop.
download tiny-ImageNet using `datasets` and save as ImageNet train/test split with individual categorical sub-directory
This file contains hidden or 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
from datasets import load_dataset | |
import os | |
from PIL import Image | |
from tqdm import tqdm | |
os.makedirs("train", exist_ok=True) | |
os.chdir("train") | |
tiny_imagenet = load_dataset('Maysee/tiny-imagenet', split='train') | |
size = 100000 | |
for i in tqdm(range(size)): | |
img = tiny_imagenet[i]['image'] | |
label = tiny_imagenet[i]['label'] | |
os.makedirs(str(label), exist_ok=True) | |
img.save(f"{label}/{i}.jpg") | |
os.chdir("../") | |
os.makedirs("val", exist_ok=True) | |
os.chdir("val") | |
tiny_imagenet = load_dataset('Maysee/tiny-imagenet', split='valid') | |
size = 10000 | |
for i in tqdm(range(size)): | |
img = tiny_imagenet[i]['image'] | |
label = tiny_imagenet[i]['label'] | |
os.makedirs(str(label), exist_ok=True) | |
img.save(f"{label}/{i}.jpg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment