admin commited on
Commit ·
d396904
1
Parent(s): 586d4ca
sync ms
Browse files- README.md +1 -1
- insecta.py +13 -23
README.md
CHANGED
|
@@ -20,7 +20,7 @@ from datasets import load_dataset
|
|
| 20 |
|
| 21 |
ds = load_dataset(
|
| 22 |
"Genius-Society/insecta",
|
| 23 |
-
split="
|
| 24 |
cache_dir="./__pycache__",
|
| 25 |
trust_remote_code=True,
|
| 26 |
)
|
|
|
|
| 20 |
|
| 21 |
ds = load_dataset(
|
| 22 |
"Genius-Society/insecta",
|
| 23 |
+
split="train",
|
| 24 |
cache_dir="./__pycache__",
|
| 25 |
trust_remote_code=True,
|
| 26 |
)
|
insecta.py
CHANGED
|
@@ -19,9 +19,10 @@ class insecta(datasets.GeneratorBasedBuilder):
|
|
| 19 |
{
|
| 20 |
"image": datasets.Image(),
|
| 21 |
"label": datasets.Value("string"),
|
|
|
|
| 22 |
}
|
| 23 |
),
|
| 24 |
-
supervised_keys=("image", "
|
| 25 |
homepage=_URL,
|
| 26 |
license="mit",
|
| 27 |
version="0.0.1",
|
|
@@ -65,40 +66,29 @@ class insecta(datasets.GeneratorBasedBuilder):
|
|
| 65 |
files = self._get_files("已鉴定")
|
| 66 |
for file in tqdm(files, desc="Parsing classes"):
|
| 67 |
imgs = self._get_files(file["Path"])
|
|
|
|
| 68 |
for img in imgs:
|
| 69 |
dataset.append(
|
| 70 |
{
|
| 71 |
-
"image":
|
| 72 |
-
"label":
|
|
|
|
| 73 |
}
|
| 74 |
)
|
| 75 |
|
| 76 |
random.shuffle(dataset)
|
| 77 |
-
data_count = len(dataset)
|
| 78 |
-
p80 = int(data_count * 0.8)
|
| 79 |
-
p90 = int(data_count * 0.9)
|
| 80 |
|
| 81 |
return [
|
| 82 |
datasets.SplitGenerator(
|
| 83 |
name=datasets.Split.TRAIN,
|
| 84 |
-
gen_kwargs={
|
| 85 |
-
|
| 86 |
-
},
|
| 87 |
-
),
|
| 88 |
-
datasets.SplitGenerator(
|
| 89 |
-
name=datasets.Split.VALIDATION,
|
| 90 |
-
gen_kwargs={
|
| 91 |
-
"files": dataset[p80:p90],
|
| 92 |
-
},
|
| 93 |
-
),
|
| 94 |
-
datasets.SplitGenerator(
|
| 95 |
-
name=datasets.Split.TEST,
|
| 96 |
-
gen_kwargs={
|
| 97 |
-
"files": dataset[p90:],
|
| 98 |
-
},
|
| 99 |
-
),
|
| 100 |
]
|
| 101 |
|
| 102 |
def _generate_examples(self, files):
|
| 103 |
for i, path in enumerate(files):
|
| 104 |
-
yield i,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
{
|
| 20 |
"image": datasets.Image(),
|
| 21 |
"label": datasets.Value("string"),
|
| 22 |
+
"latin": datasets.Value("string"),
|
| 23 |
}
|
| 24 |
),
|
| 25 |
+
supervised_keys=("image", "latin"),
|
| 26 |
homepage=_URL,
|
| 27 |
license="mit",
|
| 28 |
version="0.0.1",
|
|
|
|
| 66 |
files = self._get_files("已鉴定")
|
| 67 |
for file in tqdm(files, desc="Parsing classes"):
|
| 68 |
imgs = self._get_files(file["Path"])
|
| 69 |
+
label, latin = str(file["Name"]).split(" ", 1)
|
| 70 |
for img in imgs:
|
| 71 |
dataset.append(
|
| 72 |
{
|
| 73 |
+
"image": f"{_URL}/resolve/master/" + img["Path"],
|
| 74 |
+
"label": label.strip(),
|
| 75 |
+
"latin": latin.strip(),
|
| 76 |
}
|
| 77 |
)
|
| 78 |
|
| 79 |
random.shuffle(dataset)
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
return [
|
| 82 |
datasets.SplitGenerator(
|
| 83 |
name=datasets.Split.TRAIN,
|
| 84 |
+
gen_kwargs={"files": dataset},
|
| 85 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
]
|
| 87 |
|
| 88 |
def _generate_examples(self, files):
|
| 89 |
for i, path in enumerate(files):
|
| 90 |
+
yield i, {
|
| 91 |
+
"image": self._dld_img(path["image"]),
|
| 92 |
+
"label": path["label"],
|
| 93 |
+
"latin": path["latin"],
|
| 94 |
+
}
|