File size: 5,404 Bytes
5612586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ebbc67
5612586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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},
                    }