Upload WaterFlowCountersRecognition.py
Browse files
WaterFlowCountersRecognition.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import collections
|
| 4 |
-
from PIL import Image
|
| 5 |
|
| 6 |
import datasets
|
| 7 |
|
|
@@ -103,8 +102,9 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
| 103 |
for indx, name in enumerate(_REGION_ROTETION):
|
| 104 |
rotation_to_id[name] = indx
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
|
|
|
| 108 |
|
| 109 |
for file in os.listdir(folder_dir):
|
| 110 |
filepath = os.path.join(folder_dir, file)
|
|
@@ -116,9 +116,9 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
| 116 |
all_y = []
|
| 117 |
names = []
|
| 118 |
|
| 119 |
-
for el in
|
| 120 |
-
if
|
| 121 |
-
for region in
|
| 122 |
all_x.append(region['shape_attributes']['all_points_x'])
|
| 123 |
all_y.append(region['shape_attributes']['all_points_y'])
|
| 124 |
names.append(name_to_id[list(region['region_attributes']['name'].keys())[0]])
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import collections
|
|
|
|
| 4 |
|
| 5 |
import datasets
|
| 6 |
|
|
|
|
| 102 |
for indx, name in enumerate(_REGION_ROTETION):
|
| 103 |
rotation_to_id[name] = indx
|
| 104 |
|
| 105 |
+
annotation_filepath = os.path.join(folder_dir, _ANNOTATION_FILENAME)
|
| 106 |
+
with open(annotation_filepath, "r") as f:
|
| 107 |
+
annotations = json.load(f)
|
| 108 |
|
| 109 |
for file in os.listdir(folder_dir):
|
| 110 |
filepath = os.path.join(folder_dir, file)
|
|
|
|
| 116 |
all_y = []
|
| 117 |
names = []
|
| 118 |
|
| 119 |
+
for el in annotations['_via_img_metadata']:
|
| 120 |
+
if annotations['_via_img_metadata'][el]['filename'] == file:
|
| 121 |
+
for region in annotations['_via_img_metadata'][el]['regions']:
|
| 122 |
all_x.append(region['shape_attributes']['all_points_x'])
|
| 123 |
all_y.append(region['shape_attributes']['all_points_y'])
|
| 124 |
names.append(name_to_id[list(region['region_attributes']['name'].keys())[0]])
|