Datasets:
Tasks:
Image Classification
Formats:
imagefolder
Sub-tasks:
multi-class-classification
Languages:
English
Size:
1K - 10K
License:
| from datasets import load_dataset, Dataset, Features, Value, Image | |
| import re | |
| import os | |
| import json | |
| import shutil | |
| features = Features({ | |
| "image": Image(decode=False), | |
| "caption": Value("string") | |
| }) | |
| ds: Dataset = load_dataset("Nechintosh/ghibli", split="train", features=features) | |
| samples = list(ds) | |
| def natural_key(filename: str): | |
| parts = re.split(r'(\d+)', filename) | |
| return [int(p) if p.isdigit() else p.lower() for p in parts] | |
| samples.sort(key=lambda s: natural_key(os.path.basename(s["image"]["path"]))) | |
| os.makedirs("data/real", exist_ok=True) | |
| with open("metadata.jsonl", "w") as f: | |
| for i, sample in enumerate(samples): | |
| caption = sample["caption"] | |
| src_path: str = sample["image"]["path"] | |
| filename = os.path.basename(src_path) | |
| dst_path = os.path.join("data/real", filename) | |
| shutil.copy(src_path, dst_path) | |
| f.write(json.dumps({ | |
| "id": f"real-{i:05d}", | |
| "image": dst_path, | |
| "label": "real", | |
| "description": caption, | |
| }) + "\n") | |