Datasets:
lcolonn
commited on
feat: update loading script for JSON
Browse files
patfig.py
CHANGED
@@ -4,6 +4,7 @@ from datasets import load_dataset, Dataset, Value, Sequence, Features, DatasetIn
|
|
4 |
from pathlib import Path
|
5 |
import os
|
6 |
import pandas as pd
|
|
|
7 |
|
8 |
_DESCRIPTION = """\ The PatFig Dataset is a curated collection of over 18,000 patent images from more than 7,
|
9 |
000 European patent applications, spanning the year 2020. It aims to provide a comprehensive resource for research
|
@@ -14,18 +15,18 @@ hollistic consumption of the visual and textual data.
|
|
14 |
|
15 |
_BASE_URL = "https://huggingface.co/datasets/lcolonn/patfig/resolve/main/"
|
16 |
_METADATA_URLS = {
|
17 |
-
"annotations_train": "train/annotations_train.
|
18 |
-
"annotations_test": "test/annotations_test.
|
19 |
}
|
20 |
_IMAGES_URLS = {
|
21 |
-
"
|
22 |
-
"
|
23 |
}
|
24 |
_URLS = {
|
25 |
"train_images": "train/train_images.tar.gz",
|
26 |
"test_images": "test/test_images.tar.gz",
|
27 |
-
"annotations_train": "train/annotations_train.
|
28 |
-
"annotations_test": "test/annotations_test.
|
29 |
}
|
30 |
|
31 |
|
@@ -35,23 +36,23 @@ class PatFig(GeneratorBasedBuilder):
|
|
35 |
def _info(self):
|
36 |
return DatasetInfo(
|
37 |
description=_DESCRIPTION,
|
38 |
-
features=Features({
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
}),
|
55 |
)
|
56 |
|
57 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
@@ -62,16 +63,16 @@ class PatFig(GeneratorBasedBuilder):
|
|
62 |
name=datasets.Split.TRAIN, gen_kwargs={"images_dir": downloaded_files["train_images"], "annotations_dir": downloaded_files["annotations_train"]}
|
63 |
),
|
64 |
datasets.SplitGenerator(
|
65 |
-
name=datasets.Split.TEST, gen_kwargs={"images_dir":
|
66 |
),
|
67 |
]
|
68 |
|
69 |
def _generate_examples(self, images_dir: str, annotations_dir: str):
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
4 |
from pathlib import Path
|
5 |
import os
|
6 |
import pandas as pd
|
7 |
+
import json
|
8 |
|
9 |
_DESCRIPTION = """\ The PatFig Dataset is a curated collection of over 18,000 patent images from more than 7,
|
10 |
000 European patent applications, spanning the year 2020. It aims to provide a comprehensive resource for research
|
|
|
15 |
|
16 |
_BASE_URL = "https://huggingface.co/datasets/lcolonn/patfig/resolve/main/"
|
17 |
_METADATA_URLS = {
|
18 |
+
"annotations_train": "train/annotations_train.zip",
|
19 |
+
"annotations_test": "test/annotations_test.zip"
|
20 |
}
|
21 |
_IMAGES_URLS = {
|
22 |
+
"test_images": "train/train_images.tar.gz",
|
23 |
+
"train_images": "test/test_images.tar.gz",
|
24 |
}
|
25 |
_URLS = {
|
26 |
"train_images": "train/train_images.tar.gz",
|
27 |
"test_images": "test/test_images.tar.gz",
|
28 |
+
"annotations_train": "train/annotations_train.zip",
|
29 |
+
"annotations_test": "test/annotations_test.zip",
|
30 |
}
|
31 |
|
32 |
|
|
|
36 |
def _info(self):
|
37 |
return DatasetInfo(
|
38 |
description=_DESCRIPTION,
|
39 |
+
# features=Features({
|
40 |
+
# "image": Image(),
|
41 |
+
# "image_name": Value("string"),
|
42 |
+
# "pub_number": Value("string"),
|
43 |
+
# "title": Value("string"),
|
44 |
+
# "figs_norm": Sequence(feature=Value("string"), length=-1),
|
45 |
+
# "short_description": Sequence(feature=Value("string"), length=-1),
|
46 |
+
# "long_description": Sequence(feature=Value("string"), length=-1),
|
47 |
+
# "short_description_token_count": Value("int64"),
|
48 |
+
# "long_description_token_count": Value("int64"),
|
49 |
+
# "draft_class": Value("string"),
|
50 |
+
# "cpc_class": Value("string"),
|
51 |
+
# "relevant_terms": [{'element_identifier': Value("string"), "terms": Sequence(feature=Value("string"), length=-1)}],
|
52 |
+
# "associated_claims": Value("string"),
|
53 |
+
# "compound": Value("bool"),
|
54 |
+
# "references": Sequence(feature=Value(dtype='string'), length=-1),
|
55 |
+
# }),
|
56 |
)
|
57 |
|
58 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
|
|
63 |
name=datasets.Split.TRAIN, gen_kwargs={"images_dir": downloaded_files["train_images"], "annotations_dir": downloaded_files["annotations_train"]}
|
64 |
),
|
65 |
datasets.SplitGenerator(
|
66 |
+
name=datasets.Split.TEST, gen_kwargs={"images_dir": downloaded_files["test_images"], "annotations_dir": downloaded_files["annotations_test"]}
|
67 |
),
|
68 |
]
|
69 |
|
70 |
def _generate_examples(self, images_dir: str, annotations_dir: str):
|
71 |
+
with open(annotations_dir, "r") as f:
|
72 |
+
data = json.load(f)
|
73 |
+
for idx, record in enumerate(data):
|
74 |
+
image_path = os.path.join(images_dir, record["pub_number"], record["image_name"])
|
75 |
+
yield idx, {
|
76 |
+
"image": image_path,
|
77 |
+
**record,
|
78 |
+
}
|