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