1aurent commited on
Commit
0ab7718
·
1 Parent(s): b1cfaf3

Delete ICDAR-2011.py

Browse files
Files changed (1) hide show
  1. ICDAR-2011.py +0 -119
ICDAR-2011.py DELETED
@@ -1,119 +0,0 @@
1
- """Dataset class for Individuality Of Handwriting dataset."""
2
-
3
- import itertools
4
- import pathlib
5
- import zipfile
6
-
7
- import tqdm
8
- from datasets.tasks import ImageClassification
9
-
10
- import datasets
11
-
12
- _BASE_URLS = {
13
- "train": "http://iapr-tc11.org/dataset/ICDAR_SignatureVerification/SigComp2011/sigComp2011-trainingSet.zip",
14
- "test": "http://iapr-tc11.org/dataset/ICDAR_SignatureVerification/SigComp2011/sigComp2011-test.zip"
15
- }
16
-
17
- _BASE_URLS_PWD = b"I hereby accept the SigComp 2011 disclaimer."
18
-
19
- _HOMEPAGE = "http://iapr-tc11.org/mediawiki/index.php/ICDAR_2011_Signature_Verification_Competition_(SigComp2011)"
20
-
21
- _DESCRIPTION = """
22
- The collection contains simultaneously acquired online and offline samples.
23
- The collection contains offline and online signature samples.
24
- The offline dataset comprises PNG images, scanned at 400 dpi, RGB color.
25
- The online dataset comprises ascii files with the format: X, Y, Z (per line).
26
- """
27
-
28
- _NAMES = [
29
- "genuine",
30
- "forgeries",
31
- ]
32
-
33
-
34
- class ICDAR2011(datasets.GeneratorBasedBuilder):
35
- """ICDAR-2011 Images dataset."""
36
-
37
- def _info(self):
38
- return datasets.DatasetInfo(
39
- description=_DESCRIPTION,
40
- features=datasets.Features(
41
- {
42
- "image": datasets.Image(),
43
- "label": datasets.ClassLabel(names=_NAMES),
44
- "forger": datasets.Value("int32"),
45
- "writer": datasets.Value("uint32"),
46
- "attempt": datasets.Value("uint32"),
47
- }
48
- ),
49
- supervised_keys=("image", "label"),
50
- homepage=_HOMEPAGE,
51
- task_templates=[ImageClassification(image_column="image", label_column="label")],
52
- )
53
-
54
- def _split_generators(self, dl_manager):
55
- train_archive_path = pathlib.Path(dl_manager.download(_BASE_URLS["train"]))
56
- test_archive_path = pathlib.Path(dl_manager.download(_BASE_URLS["test"]))
57
-
58
- with zipfile.ZipFile(train_archive_path, 'r') as zf:
59
- train_dir = train_archive_path.parent / "extracted" / train_archive_path.name
60
- print(train_dir)
61
- for member in tqdm.tqdm(zf.infolist(), desc="Extracting training data"):
62
- try:
63
- if not pathlib.Path(train_dir / member.filename).exists():
64
- zf.extract(member, train_dir, pwd=_BASE_URLS_PWD)
65
- except zipfile.error:
66
- print("Error extracting", member.filename)
67
- zf.close()
68
-
69
- with zipfile.ZipFile(test_archive_path, 'r') as zf:
70
- test_dir = test_archive_path.parent / "extracted" / test_archive_path.name
71
- for member in tqdm.tqdm(zf.infolist(), desc="Extracting test data"):
72
- try:
73
- if not pathlib.Path(test_dir / member.filename).exists():
74
- zf.extract(member, test_dir, pwd=_BASE_URLS_PWD)
75
- except zipfile.error:
76
- print("Error extracting", member.filename)
77
- zf.close()
78
-
79
- return [
80
- datasets.SplitGenerator(
81
- name=datasets.Split.TRAIN,
82
- gen_kwargs={
83
- "data_dir": train_dir,
84
- },
85
- ),
86
- datasets.SplitGenerator(
87
- name=datasets.Split.TEST,
88
- gen_kwargs={
89
- "data_dir": test_dir,
90
- },
91
- ),
92
- ]
93
-
94
- def _generate_examples(self, data_dir):
95
- """Generate images and labels for splits."""
96
- rglob_lowercase = pathlib.Path(data_dir).rglob("*.png")
97
- rglob_uppercase = pathlib.Path(data_dir).rglob("*.PNG")
98
- rglob = itertools.chain(rglob_lowercase, rglob_uppercase)
99
-
100
- for index, filepath in enumerate(rglob):
101
- filename = filepath.with_suffix("").name
102
- prefix, attempt = filename.split("_")
103
-
104
- if len(prefix) == 7:
105
- forger = prefix[:4]
106
- writer = prefix[4:]
107
- label = "forgeries"
108
- else:
109
- writer = prefix
110
- forger = -1
111
- label = "genuine"
112
-
113
- yield index, {
114
- "image": str(filepath),
115
- "label": label,
116
- "forger": forger,
117
- "writer": writer,
118
- "attempt": attempt,
119
- }