Upload WaterFlowCountersRecognition.py
Browse files
WaterFlowCountersRecognition.py
CHANGED
@@ -22,13 +22,13 @@ _REGION_NAME = ['value_a', 'value_b', 'serial']
|
|
22 |
|
23 |
_REGION_ROTETION = ['0', '90', '180', '270']
|
24 |
|
25 |
-
|
26 |
|
27 |
|
28 |
class WaterFlowCounterConfig(datasets.BuilderConfig):
|
29 |
"""Builder Config for WaterFlowCounter"""
|
30 |
|
31 |
-
def __init__(self, data_url, **kwargs):
|
32 |
"""BuilderConfig for WaterFlowCounter.
|
33 |
Args:
|
34 |
data_url: `string`, url to download the photos.
|
@@ -37,6 +37,7 @@ class WaterFlowCounterConfig(datasets.BuilderConfig):
|
|
37 |
"""
|
38 |
super(WaterFlowCounterConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
39 |
self.data_url = data_url
|
|
|
40 |
|
41 |
|
42 |
class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
@@ -50,6 +51,7 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
50 |
"train": "https://huggingface.co/datasets/SIA86/WaterFlowCountersRecognition/blob/main/data/train_photos.zip",
|
51 |
"test": "https://huggingface.co/datasets/SIA86/WaterFlowCountersRecognition/blob/main/data/test_photos.zip",
|
52 |
}
|
|
|
53 |
)
|
54 |
]
|
55 |
|
@@ -77,22 +79,26 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
77 |
|
78 |
def _split_generators(self, dl_manager):
|
79 |
data_files = dl_manager.download_and_extract(self.config.data_url)
|
|
|
|
|
80 |
return [
|
81 |
datasets.SplitGenerator(
|
82 |
name=datasets.Split.TRAIN,
|
83 |
gen_kwargs={
|
84 |
"folder_dir": data_files["train"],
|
|
|
85 |
},
|
86 |
),
|
87 |
datasets.SplitGenerator(
|
88 |
name=datasets.Split.TEST,
|
89 |
gen_kwargs={
|
90 |
"folder_dir": data_files["test"],
|
|
|
91 |
},
|
92 |
)
|
93 |
]
|
94 |
|
95 |
-
def generate_examples(self, folder_dir):
|
96 |
name_to_id = {}
|
97 |
rotation_to_id = {}
|
98 |
|
@@ -102,8 +108,8 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
102 |
for indx, name in enumerate(_REGION_ROTETION):
|
103 |
rotation_to_id[name] = indx
|
104 |
|
105 |
-
|
106 |
-
with open(
|
107 |
annotations = json.load(f)
|
108 |
|
109 |
for file in os.listdir(folder_dir):
|
|
|
22 |
|
23 |
_REGION_ROTETION = ['0', '90', '180', '270']
|
24 |
|
25 |
+
|
26 |
|
27 |
|
28 |
class WaterFlowCounterConfig(datasets.BuilderConfig):
|
29 |
"""Builder Config for WaterFlowCounter"""
|
30 |
|
31 |
+
def __init__(self, data_url, metadata_urls, **kwargs):
|
32 |
"""BuilderConfig for WaterFlowCounter.
|
33 |
Args:
|
34 |
data_url: `string`, url to download the photos.
|
|
|
37 |
"""
|
38 |
super(WaterFlowCounterConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
39 |
self.data_url = data_url
|
40 |
+
self.metadata_urls = metadata_urls
|
41 |
|
42 |
|
43 |
class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
|
51 |
"train": "https://huggingface.co/datasets/SIA86/WaterFlowCountersRecognition/blob/main/data/train_photos.zip",
|
52 |
"test": "https://huggingface.co/datasets/SIA86/WaterFlowCountersRecognition/blob/main/data/test_photos.zip",
|
53 |
}
|
54 |
+
metadata_url = "https://huggingface.co/datasets/SIA86/WaterFlowCountersRecognition/blob/main/WaterFlowCounter.json"
|
55 |
)
|
56 |
]
|
57 |
|
|
|
79 |
|
80 |
def _split_generators(self, dl_manager):
|
81 |
data_files = dl_manager.download_and_extract(self.config.data_url)
|
82 |
+
metadata_files = dl_manager.download_and_extract(self.config.metadata_url)
|
83 |
+
|
84 |
return [
|
85 |
datasets.SplitGenerator(
|
86 |
name=datasets.Split.TRAIN,
|
87 |
gen_kwargs={
|
88 |
"folder_dir": data_files["train"],
|
89 |
+
"metadata_path": metadata_files,
|
90 |
},
|
91 |
),
|
92 |
datasets.SplitGenerator(
|
93 |
name=datasets.Split.TEST,
|
94 |
gen_kwargs={
|
95 |
"folder_dir": data_files["test"],
|
96 |
+
"metadata_path": metadata_files,
|
97 |
},
|
98 |
)
|
99 |
]
|
100 |
|
101 |
+
def generate_examples(self, folder_dir, metadata_path):
|
102 |
name_to_id = {}
|
103 |
rotation_to_id = {}
|
104 |
|
|
|
108 |
for indx, name in enumerate(_REGION_ROTETION):
|
109 |
rotation_to_id[name] = indx
|
110 |
|
111 |
+
|
112 |
+
with open(metadata_path, "r") as f:
|
113 |
annotations = json.load(f)
|
114 |
|
115 |
for file in os.listdir(folder_dir):
|