# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Pathfinder-X2 Segmentation Benchmark.""" import os import pandas as pd import datasets _CITATION = """\ @article{suard2023pathfinder, title={Pathfinder-X2: A Challenging Dataset for Evaluating Large Language Models on Long-Range Dependencies}, author={Suard, Tyler}, journal={}, year={2023} } """ _DESCRIPTION = """\ The rapid progress of large language models has led to impressive results in a wide array of tasks. However, there remains a need for increasingly challenging datasets to evaluate these models' ability to handle long-range dependencies. In this paper, we present Pathfinder-X2, a novel dataset that builds upon the Pathfinder and Pathfinder-X datasets. Pathfinder-X2 comprises 512x512 pixel images, designed to test large language models' capacity to segment a specific white line dash "snake" with a circle at its tip among a collection of similar, distractor snakes. The increased image resolution and complexity of Pathfinder-X2 present a substantially more challenging task for large language models, contributing to the ongoing development and assessment of such models. """ _HOMEPAGE = "https://huggingface.co/datasets/Tylersuard/PathfinderX2/" _LICENSE = "C.C. B.Y. 4.0" _URLS = { "instance_segmentation": { "images": "https://pathfinder-x2.s3.us-west-1.amazonaws.com/Pathfinder-X2+images.zip", "annotations": "https://pathfinder-x2.s3.us-west-1.amazonaws.com/Pathfinder-X2+masks.zip", }, } class PathfinderX2(datasets.GeneratorBasedBuilder): """Pathfinder X2 Segmentation Benchmark dataset.""" VERSION = datasets.Version("1.0.0") BUILDER_CONFIGS = [ datasets.BuilderConfig( name="instance_segmentation", version=VERSION, description="The instance segmentation variant." ), ] DEFAULT_CONFIG_NAME = "instance_segmentation" def _info(self): features = datasets.Features( { "image": datasets.Image(), "annotation": datasets.Image(), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): urls = _URLS[self.config.name] data_dirs = dl_manager.download(urls) train_data = dl_manager.iter_archive(data_dirs["images"]), dl_manager.iter_archive( data_dirs["annotations"] ) val_data = dl_manager.iter_archive(data_dirs["images"]), dl_manager.iter_archive(data_dirs["annotations"]) test_data = dl_manager.iter_archive(data_dirs["images"]), dl_manager.iter_archive(data_dirs["annotations"]) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data": train_data, "split": "training", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data": test_data, "split": "testing"}, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "data": val_data, "split": "validation", }, ), ] def _generate_examples(self, data, split): if split == "testing": images, annotations = data for idx, (path, file) in enumerate(data): if path.endswith(".png"): yield idx, { "image": {"path": path, "bytes": file.read()}, "annotation": None, } else: images, annotations = data image_id2annot = {} # loads the annotations for the split into RAM (less than 100 MB) to support streaming for path_annot, file_annot in annotations: if split in path_annot and path_annot.endswith(".png"): image_id = os.path.basename(path_annot).split(".")[0] image_id2annot[image_id] = (path_annot, file_annot.read()) for idx, (path_img, file_img) in enumerate(images): if split in path_img and path_img.endswith(".png"): image_id = os.path.basename(path_img).split(".")[0] path_annot, bytes_annot = image_id2annot[image_id] yield idx, { "image": {"path": path_img, "bytes": file_img.read()}, "annotation": {"path": path_annot, "bytes": bytes_annot}, }