Datasets:
pooya-mohammadi
commited on
Commit
•
fb7b28f
1
Parent(s):
8f4e405
Add persian_license_plate.py
Browse files- persian_license_plate.py +94 -0
persian_license_plate.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
import csv
|
5 |
+
|
6 |
+
import datasets
|
7 |
+
|
8 |
+
logger = datasets.logging.get_logger(__name__)
|
9 |
+
|
10 |
+
_CITATION = """"""
|
11 |
+
|
12 |
+
_DESCRIPTION = """Persian Licensee plate dataset. Primarily taken from AmirKabir University Challenge.
|
13 |
+
Annotation are provided by the authors"""
|
14 |
+
|
15 |
+
_DOWNLOAD_URLS = {
|
16 |
+
"train": "https://huggingface.co/datasets/hezarai/persian-license-plate-v1/resolve/main/persian_license_plate_train.csv",
|
17 |
+
"val": "https://huggingface.co/datasets/hezarai/persian-license-plate-v1/resolve/main/persian_license_plate_val.csv",
|
18 |
+
"test": "https://huggingface.co/datasets/hezarai/persian-license-plate-v1/resolve/main/persian_license_plate_test.csv",
|
19 |
+
'train_dataset': "https://huggingface.co/datasets/hezarai/persian-license-plate-v1/resolve/main/persian_license_plate_train.zip",
|
20 |
+
'val_dataset': "https://huggingface.co/datasets/hezarai/persian-license-plate-v1/resolve/main/persian_license_plate_val.zip",
|
21 |
+
'test_dataset': "https://huggingface.co/datasets/hezarai/persian-license-plate-v1/resolve/main/persian_license_plate_test.zip",
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
class PersianLicensePlateConfig(datasets.BuilderConfig):
|
26 |
+
def __init__(self, **kwargs):
|
27 |
+
super(PersianLicensePlateConfig, self).__init__(**kwargs)
|
28 |
+
|
29 |
+
|
30 |
+
class PersianLicensePlate(datasets.GeneratorBasedBuilder):
|
31 |
+
BUILDER_CONFIGS = [
|
32 |
+
PersianLicensePlateConfig(
|
33 |
+
name="PersianLicensePlate",
|
34 |
+
version=datasets.Version("1.0.0"),
|
35 |
+
description=_DESCRIPTION,
|
36 |
+
),
|
37 |
+
]
|
38 |
+
|
39 |
+
def _info(self):
|
40 |
+
return datasets.DatasetInfo(
|
41 |
+
description=_DESCRIPTION,
|
42 |
+
features=datasets.Features(
|
43 |
+
{
|
44 |
+
"label": datasets.Value("string"),
|
45 |
+
"filename": datasets.Value("string"),
|
46 |
+
"image": datasets.Sequence(datasets.Value("int32")),
|
47 |
+
}
|
48 |
+
),
|
49 |
+
citation=_CITATION,
|
50 |
+
)
|
51 |
+
|
52 |
+
def _split_generators(self, dl_manager):
|
53 |
+
"""
|
54 |
+
Return SplitGenerators.
|
55 |
+
"""
|
56 |
+
|
57 |
+
train_path = dl_manager.download_and_extract(_DOWNLOAD_URLS["train"])
|
58 |
+
val_path = dl_manager.download_and_extract(_DOWNLOAD_URLS['val'])
|
59 |
+
test_path = dl_manager.download_and_extract(_DOWNLOAD_URLS["test"])
|
60 |
+
|
61 |
+
archive_path = dl_manager.download(_DOWNLOAD_URLS['train_dataset'])
|
62 |
+
train_extracted_path = dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
|
63 |
+
|
64 |
+
archive_path = dl_manager.download(_DOWNLOAD_URLS['val_dataset'])
|
65 |
+
val_extracted_path = dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
|
66 |
+
|
67 |
+
archive_path = dl_manager.download(_DOWNLOAD_URLS['test_dataset'])
|
68 |
+
test_extracted_path = dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
|
69 |
+
|
70 |
+
return [
|
71 |
+
datasets.SplitGenerator(
|
72 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path, "dataset_dir": train_extracted_path}
|
73 |
+
),
|
74 |
+
datasets.SplitGenerator(
|
75 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": test_path, "dataset_dir": test_extracted_path}
|
76 |
+
),
|
77 |
+
datasets.SplitGenerator(
|
78 |
+
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": val_path, "dataset_dir": val_extracted_path}
|
79 |
+
),
|
80 |
+
]
|
81 |
+
|
82 |
+
def _generate_examples(self, filepath, dataset_dir):
|
83 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
84 |
+
|
85 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
86 |
+
csv_reader = csv.reader(csv_file, quotechar='"', skipinitialspace=True)
|
87 |
+
|
88 |
+
# Skip header
|
89 |
+
next(csv_reader, None)
|
90 |
+
|
91 |
+
for id_, row in enumerate(csv_reader):
|
92 |
+
label, filename = row
|
93 |
+
image_path = os.path.join(dataset_dir, filename)
|
94 |
+
yield id_, {"label": label, "image_path": image_path}
|