Brandon Maximilian Wu
commited on
Commit
·
717b5e0
1
Parent(s):
7eed242
Update info.
Browse files- anime-tagging-dataset.py +48 -0
anime-tagging-dataset.py
CHANGED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import List
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
from datasets.tasks import ImageClassification
|
6 |
+
|
7 |
+
|
8 |
+
logger = datasets.logging.get_logger(__name__)
|
9 |
+
|
10 |
+
_DESCRIPTION = "Anime tagging."
|
11 |
+
|
12 |
+
tags = ['long_hair', 'original', 'headphones', 'open_mouth', 'hoshino_katsura', 'brown_hair', 'shoes', 'elbow_gloves', 'flower', 'glasses', 'bow', 'sitting', 'scan', 'yellow_eyes', 'hatsune_miku', 'uniform', 'suzumiya_haruhi_no_yuuutsu', 'purple_hair', 'flat_chest', 'thigh-highs', 'ponytail', 'vector', 'ribbon', 'blonde_hair', 'cat_ears', 'red_eyes', '1girl', 'hair_ornament', 'hat', 'sky', 'seifuku', 'water', 'smile', 'brown_eyes', 'bad_id', 'twintails', 'black_hair', 'pink_hair', 'vocaloid', 'ahoge', 'red_hair', 'tagme', 'monochrome', 'cleavage', 'nail_polish', 'hair_ribbon', 'weapon', 'wings', 'legs', 'necktie', 'touhou', 'zettai_ryouiki', 'dress', 'purple_eyes', 'solo', 'closed_eyes', 'catgirl', 'male', 'blue_hair', 'midriff', 'navel', 'white_hair', 'skirt', 'aqua_hair', 'scarf', 'jewelry', 'trap', 'kagamine_len', 'animal_ears', 'very_long_hair', 'wink', 'pantyhose', 'socks', 'green_eyes', 'nagato_yuki', 'sword', 'thigh_highs', 'boots', 'swimsuit', 'd.gray-man', 'wallpaper', 'blue_eyes', 'blush', 'detached_sleeves', 'bikini', 'short_hair', 'japanese_clothes', 'kimono', 'thighhighs', 'green_hair', 'hair_bow', 'multiple_girls', 'tail', 'highres', 'breasts', 'white', 'school_uniform', 'gloves', 'megurine_luka', 'itou_noiji']
|
13 |
+
|
14 |
+
|
15 |
+
class AnimeTagging(datasets.GeneratorBasedBuilder):
|
16 |
+
def _info(self):
|
17 |
+
return datasets.DatasetInfo(
|
18 |
+
description=_DESCRIPTION,
|
19 |
+
features=datasets.Features(
|
20 |
+
{
|
21 |
+
"image_file_path": datasets.Value("string"),
|
22 |
+
"labels": datasets.features.ClassLabel(names=tags),
|
23 |
+
}
|
24 |
+
),
|
25 |
+
supervised_keys=("image_file_path", "labels"),
|
26 |
+
task_templates=[
|
27 |
+
ImageClassification(
|
28 |
+
image_file_path_column="image_file_path", label_column="labels", labels=tags
|
29 |
+
)
|
30 |
+
],
|
31 |
+
)
|
32 |
+
|
33 |
+
# def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
34 |
+
# images_path = Path(dl_manager.download_and_extract(_URL)) / "PetImages"
|
35 |
+
# return [
|
36 |
+
# datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"images_path": images_path}),
|
37 |
+
# ]
|
38 |
+
|
39 |
+
def _generate_examples(self, images_path):
|
40 |
+
logger.info("generating examples from = %s", images_path)
|
41 |
+
for i, filepath in enumerate(images_path.glob("**/*.jpg")):
|
42 |
+
with filepath.open("rb") as f:
|
43 |
+
if b"JFIF" in f.peek(10):
|
44 |
+
yield str(i), {
|
45 |
+
"image_file_path": str(filepath),
|
46 |
+
"labels": filepath.parent.name.lower(),
|
47 |
+
}
|
48 |
+
continue
|