Upload 2 files
Browse files- README.md +17 -9
- WaterFlowCountersRecognition.py +36 -12
README.md
CHANGED
|
@@ -1,16 +1,24 @@
|
|
| 1 |
---
|
| 2 |
dataset_info:
|
| 3 |
features:
|
| 4 |
-
- name:
|
| 5 |
dtype: string
|
| 6 |
- name: image
|
| 7 |
dtype: image
|
| 8 |
-
- name:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
sequence:
|
| 10 |
-
- name:
|
| 11 |
-
sequence: int64
|
| 12 |
-
- name: all_points_y
|
| 13 |
sequence: int64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
- name: name
|
| 15 |
dtype:
|
| 16 |
class_label:
|
|
@@ -29,11 +37,11 @@ dataset_info:
|
|
| 29 |
config_name: WFCR_full
|
| 30 |
splits:
|
| 31 |
- name: train
|
| 32 |
-
num_bytes:
|
| 33 |
num_examples: 1644
|
| 34 |
- name: test
|
| 35 |
-
num_bytes:
|
| 36 |
num_examples: 412
|
| 37 |
-
download_size:
|
| 38 |
-
dataset_size:
|
| 39 |
---
|
|
|
|
| 1 |
---
|
| 2 |
dataset_info:
|
| 3 |
features:
|
| 4 |
+
- name: id
|
| 5 |
dtype: string
|
| 6 |
- name: image
|
| 7 |
dtype: image
|
| 8 |
+
- name: width
|
| 9 |
+
dtype: int32
|
| 10 |
+
- name: height
|
| 11 |
+
dtype: int32
|
| 12 |
+
- name: annotations
|
| 13 |
sequence:
|
| 14 |
+
- name: bbox
|
|
|
|
|
|
|
| 15 |
sequence: int64
|
| 16 |
+
length: 4
|
| 17 |
+
- name: area
|
| 18 |
+
dtype: int64
|
| 19 |
+
- name: segmentation
|
| 20 |
+
sequence:
|
| 21 |
+
sequence: int64
|
| 22 |
- name: name
|
| 23 |
dtype:
|
| 24 |
class_label:
|
|
|
|
| 37 |
config_name: WFCR_full
|
| 38 |
splits:
|
| 39 |
- name: train
|
| 40 |
+
num_bytes: 937884
|
| 41 |
num_examples: 1644
|
| 42 |
- name: test
|
| 43 |
+
num_bytes: 239710
|
| 44 |
num_examples: 412
|
| 45 |
+
download_size: 46791554
|
| 46 |
+
dataset_size: 1177594
|
| 47 |
---
|
WaterFlowCountersRecognition.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
import datasets
|
| 5 |
|
|
@@ -62,10 +63,13 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
| 62 |
{
|
| 63 |
"id": datasets.Value("string"),
|
| 64 |
"image": datasets.Image(),
|
| 65 |
-
"
|
|
|
|
|
|
|
| 66 |
{
|
| 67 |
-
"
|
| 68 |
-
"
|
|
|
|
| 69 |
"name": datasets.ClassLabel(names=_REGION_NAME, num_classes=3),
|
| 70 |
"rotated": datasets.ClassLabel(names=_REGION_ROTETION, num_classes=4)
|
| 71 |
}
|
|
@@ -118,13 +122,16 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
| 118 |
|
| 119 |
for file in os.listdir(folder_dir):
|
| 120 |
filepath = os.path.join(folder_dir, file)
|
| 121 |
-
|
| 122 |
with open(filepath, "rb") as f:
|
| 123 |
image_bytes = f.read()
|
| 124 |
-
#print(image_bytes)
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
names = []
|
| 129 |
rotated = []
|
| 130 |
|
|
@@ -133,8 +140,22 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
| 133 |
if annotations['_via_img_metadata'][el]['filename'] == file:
|
| 134 |
|
| 135 |
for region in annotations['_via_img_metadata'][el]['regions']:
|
| 136 |
-
all_x
|
| 137 |
-
all_y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
for name in list(region['region_attributes']['name'].keys()):
|
| 139 |
names.append(name_to_id[name])
|
| 140 |
try:
|
|
@@ -147,9 +168,12 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
|
|
| 147 |
yield idx, {
|
| 148 |
"id": file,
|
| 149 |
"image": {"path": filepath, "bytes": image_bytes},
|
| 150 |
-
"
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
| 153 |
"name":names,
|
| 154 |
"rotated": rotated
|
| 155 |
}
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
import datasets
|
| 6 |
|
|
|
|
| 63 |
{
|
| 64 |
"id": datasets.Value("string"),
|
| 65 |
"image": datasets.Image(),
|
| 66 |
+
"width": datasets.Value('int32'),
|
| 67 |
+
"height": datasets.Value('int32'),
|
| 68 |
+
"annotations": datasets.Sequence(
|
| 69 |
{
|
| 70 |
+
"bbox": datasets.Sequence(datasets.Value("int64"), length=4),
|
| 71 |
+
"area": datasets.Value("int64"),
|
| 72 |
+
"segmentation": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
|
| 73 |
"name": datasets.ClassLabel(names=_REGION_NAME, num_classes=3),
|
| 74 |
"rotated": datasets.ClassLabel(names=_REGION_ROTETION, num_classes=4)
|
| 75 |
}
|
|
|
|
| 122 |
|
| 123 |
for file in os.listdir(folder_dir):
|
| 124 |
filepath = os.path.join(folder_dir, file)
|
| 125 |
+
|
| 126 |
with open(filepath, "rb") as f:
|
| 127 |
image_bytes = f.read()
|
|
|
|
| 128 |
|
| 129 |
+
image = Image.open(filepath)
|
| 130 |
+
width, height = image.size
|
| 131 |
+
|
| 132 |
+
all_bbox = []
|
| 133 |
+
all_area = []
|
| 134 |
+
all_segmentation = []
|
| 135 |
names = []
|
| 136 |
rotated = []
|
| 137 |
|
|
|
|
| 140 |
if annotations['_via_img_metadata'][el]['filename'] == file:
|
| 141 |
|
| 142 |
for region in annotations['_via_img_metadata'][el]['regions']:
|
| 143 |
+
all_x = region['shape_attributes']['all_points_x']
|
| 144 |
+
all_y = region['shape_attributes']['all_points_y']
|
| 145 |
+
x_min = min(all_x)
|
| 146 |
+
y_min = min(all_y)
|
| 147 |
+
x_max = max(all_x)
|
| 148 |
+
y_max = max(all_y)
|
| 149 |
+
p_width = x_max - x_min
|
| 150 |
+
p_height = y_max - y_min
|
| 151 |
+
bbox = [x_min, y_min, p_width, p_height ]
|
| 152 |
+
area = p_width * p_height
|
| 153 |
+
segmentation = list(zip(all_x, all_y))
|
| 154 |
+
|
| 155 |
+
all_bbox.append(bbox)
|
| 156 |
+
all_area.append(area)
|
| 157 |
+
all_segmentation.append(segmentation)
|
| 158 |
+
|
| 159 |
for name in list(region['region_attributes']['name'].keys()):
|
| 160 |
names.append(name_to_id[name])
|
| 161 |
try:
|
|
|
|
| 168 |
yield idx, {
|
| 169 |
"id": file,
|
| 170 |
"image": {"path": filepath, "bytes": image_bytes},
|
| 171 |
+
"width": width,
|
| 172 |
+
"height": height,
|
| 173 |
+
"annotations": {
|
| 174 |
+
"area": all_area,
|
| 175 |
+
"bbox": all_bbox,
|
| 176 |
+
"segmentation": all_segmentation,
|
| 177 |
"name":names,
|
| 178 |
"rotated": rotated
|
| 179 |
}
|