|
import datasets |
|
from datasets import load_dataset, Dataset |
|
|
|
from pathlib import Path |
|
import os |
|
import pandas as pd |
|
|
|
_DESCRIPTION = """\ The PatFig Dataset is a curated collection of over 18,000 patent images from more than 7, |
|
000 European patent applications, spanning the year 2020. It aims to provide a comprehensive resource for research |
|
and applications in image captioning, abstract reasoning, patent analysis, and automated documentprocessing. The |
|
overarching goal of this dataset is to advance the research in visually situated language understanding towards more |
|
hollistic consumption of the visual and textual data. |
|
""" |
|
|
|
_URL = "https://huggingface.co/datasets/danaaubakirova/patfig/tree/main" |
|
_URLS = { |
|
"train": f"{_URL}/train", |
|
"test": f"{_URL}/test", |
|
"annotations_train": f"{_URL}/annotations_train.csv", |
|
"annotations_test": f"{_URL}/annotations_test.csv", |
|
} |
|
|
|
|
|
class PatFig(datasets.GeneratorBasedBuilder): |
|
"""DatasetBuilder for patfig dataset.""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features({ |
|
"image": datasets.Image(), |
|
"short_description": datasets.Value("string"), |
|
"long_description": datasets.Value("string"), |
|
}), |
|
) |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager): |
|
downloaded_files = dl_manager.download_and_extract(_URLS) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, gen_kwargs={"images_dir": downloaded_files["train"], "annotations_dir": downloaded_files["annotations_train"]} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, gen_kwargs={"images_dir": downloaded_files["test"], "annotations_dir": downloaded_files["annotations_test"]} |
|
), |
|
] |
|
|
|
def _generate_examples(self, images_dir: str, annotations_dir: str): |
|
df = pd.read_csv(annotations_dir) |
|
|
|
for idx, row in df.iterrows(): |
|
image_path = os.path.join(images_dir, split, row["pubNumber"], row["image_name"]) |
|
yield idx, { |
|
"image": image_path, |
|
"short_description": row["descFig"], |
|
"long_description": row["description"], |
|
} |
|
|