Vadzim Kashko
commited on
Commit
•
220cb84
1
Parent(s):
0525763
refactor: script
Browse files- license_plates.py +36 -13
license_plates.py
CHANGED
@@ -66,29 +66,52 @@ class LicensePlates(datasets.GeneratorBasedBuilder):
|
|
66 |
data = dl_manager.iter_archive(data)
|
67 |
return [
|
68 |
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
69 |
-
gen_kwargs={
|
70 |
-
"data": data
|
71 |
-
}),
|
72 |
]
|
73 |
|
74 |
def _generate_examples(self, data):
|
75 |
|
76 |
annotations = []
|
77 |
-
images =
|
78 |
|
79 |
for idx, (file_path, file) in enumerate(data):
|
80 |
if file_path.endswith('.csv'):
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
yield idx, {
|
83 |
"image": {
|
84 |
-
"path":
|
85 |
-
"bytes": image
|
86 |
},
|
87 |
-
"
|
88 |
-
"path":
|
89 |
-
"bytes":
|
90 |
},
|
91 |
-
'
|
92 |
-
'
|
93 |
-
'
|
|
|
|
|
|
|
|
|
|
|
94 |
}
|
|
|
66 |
data = dl_manager.iter_archive(data)
|
67 |
return [
|
68 |
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
69 |
+
gen_kwargs={"data": data}),
|
|
|
|
|
70 |
]
|
71 |
|
72 |
def _generate_examples(self, data):
|
73 |
|
74 |
annotations = []
|
75 |
+
images = {}
|
76 |
|
77 |
for idx, (file_path, file) in enumerate(data):
|
78 |
if file_path.endswith('.csv'):
|
79 |
+
df = pd.read_csv(file_path, sep=',')
|
80 |
+
annotations.append(df)
|
81 |
+
|
82 |
+
else:
|
83 |
+
file_name = file_path.split('/')[-1]
|
84 |
+
images[file_name] = (file_path, file.read())
|
85 |
+
|
86 |
+
if len(annotations) > 1:
|
87 |
+
annotations_df = pd.concat(annotations)
|
88 |
+
else:
|
89 |
+
annotations_df = annotations[0]
|
90 |
+
|
91 |
+
annotations_df.drop(
|
92 |
+
columns=['license_plate.region', 'license_plate.color'],
|
93 |
+
inplace=True)
|
94 |
+
|
95 |
+
for row in annotations_df.itertuples(index=False):
|
96 |
+
image = images[row[0]]
|
97 |
+
name, ext = row[0].split('.')
|
98 |
+
labeled_image = images[f'{name}_labeled.{ext}']
|
99 |
+
|
100 |
yield idx, {
|
101 |
"image": {
|
102 |
+
"path": image[0],
|
103 |
+
"bytes": image[1]
|
104 |
},
|
105 |
+
"labeled_image": {
|
106 |
+
"path": labeled_image[0],
|
107 |
+
"bytes": labeled_image[1]
|
108 |
},
|
109 |
+
'bbox': row[1],
|
110 |
+
'license_plate.id': row[2],
|
111 |
+
'license_plate.visibility': row[3],
|
112 |
+
'license_plate.rows_count': row[4],
|
113 |
+
'license_plate.number': row[5],
|
114 |
+
'license_plate.serial': row[6],
|
115 |
+
'license_plate.country': row[7],
|
116 |
+
'license_plate.mask': row[8]
|
117 |
}
|