Commit
·
d7ecb2f
1
Parent(s):
afe5bd2
Create new file
Browse files- mortars_test3.py +94 -0
mortars_test3.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Dataset class for image dataset."""
|
2 |
+
|
3 |
+
import datasets
|
4 |
+
import os
|
5 |
+
from datasets.tasks import ImageClassification
|
6 |
+
|
7 |
+
_URLS = "mortars_data.zip"
|
8 |
+
|
9 |
+
_HOMEPAGE = "http://https://huggingface.co/datasets/apetulante/mortars_test"
|
10 |
+
|
11 |
+
_DESCRIPTION = (
|
12 |
+
"This dataset consists of test dataset of ancient mortar and with only obsidian images as zip file in it"
|
13 |
+
)
|
14 |
+
|
15 |
+
_NAMES = [
|
16 |
+
"Obsidian-1to2mm",
|
17 |
+
|
18 |
+
]
|
19 |
+
|
20 |
+
_CITATION = ""
|
21 |
+
|
22 |
+
|
23 |
+
class AncientMortarConfig(datasets.BuilderConfig):
|
24 |
+
"""BuilderConfig for COCO cats image."""
|
25 |
+
|
26 |
+
def __init__(
|
27 |
+
self,
|
28 |
+
data_url,
|
29 |
+
url,
|
30 |
+
task_templates=None,
|
31 |
+
**kwargs,
|
32 |
+
):
|
33 |
+
super(AncientMortarConfig, self).__init__(
|
34 |
+
version=datasets.Version("1.9.0", ""), **kwargs
|
35 |
+
)
|
36 |
+
self.data_url = data_url
|
37 |
+
self.url = url
|
38 |
+
self.task_templates = task_templates
|
39 |
+
|
40 |
+
class AncientMortar(datasets.GeneratorBasedBuilder):
|
41 |
+
|
42 |
+
BUILDER_CONFIGS = [
|
43 |
+
AncientMortarConfig(
|
44 |
+
name="image",
|
45 |
+
url="",
|
46 |
+
data_url="",
|
47 |
+
)
|
48 |
+
]
|
49 |
+
|
50 |
+
|
51 |
+
def _info(self):
|
52 |
+
return datasets.DatasetInfo(
|
53 |
+
description=_DESCRIPTION,
|
54 |
+
features=datasets.Features(
|
55 |
+
{
|
56 |
+
"image": datasets.Image(),
|
57 |
+
"label": datasets.ClassLabel(names=_NAMES),
|
58 |
+
}
|
59 |
+
),
|
60 |
+
supervised_keys=("image", "label"),
|
61 |
+
homepage=_HOMEPAGE,
|
62 |
+
citation=_CITATION,
|
63 |
+
task_templates=[ImageClassification(image_column="image", label_column="label")],
|
64 |
+
)
|
65 |
+
|
66 |
+
def _split_generators(self, dl_manager):
|
67 |
+
data_files = dl_manager.download_and_extract(_URLS)
|
68 |
+
|
69 |
+
return [
|
70 |
+
datasets.SplitGenerator(
|
71 |
+
name=datasets.Split.TRAIN,
|
72 |
+
gen_kwargs={
|
73 |
+
"files": dl_manager.iter_files([data_files]),
|
74 |
+
},
|
75 |
+
)
|
76 |
+
]
|
77 |
+
def _generate_examples(self, files):
|
78 |
+
"""Generate images and labels for splits."""
|
79 |
+
for i, path in enumerate(files):
|
80 |
+
file_name = os.path.basename(path)
|
81 |
+
if file_name.endswith(".bmp"):
|
82 |
+
yield i, {
|
83 |
+
"image_file_path": path,
|
84 |
+
"image": path,
|
85 |
+
"labels": os.path.basename(os.path.dirname(path)).lower(),
|
86 |
+
}
|
87 |
+
# for file_path in files:
|
88 |
+
## if file_path.startswith(_IMAGES_DIR):
|
89 |
+
# if file_path[len(_IMAGES_DIR) : -len(".bmp")] in files_to_keep:
|
90 |
+
# label = file_path.split("/")[2]
|
91 |
+
# yield file_path, {
|
92 |
+
# "image": {"path": file_path},
|
93 |
+
# "label": label,
|
94 |
+
# }
|