File size: 4,949 Bytes
5612586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cdbfb65
 
5612586
 
cdbfb65
5612586
 
 
 
 
 
 
 
 
 
383bb88
76318e3
cdbfb65
76318e3
 
cdbfb65
8cc08a7
cdbfb65
 
 
 
 
 
383bb88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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_and_extract(urls)  # change from download to download_and_extract
        train_data = os.path.join(data_dirs["images"]), os.path.join(
            data_dirs["annotations"]
        )

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "data": train_data,
                    "split": "training",
                },
            ),
        ]

 def _generate_examples(self, data, split):
        if split == "training":
            images_dir, annotations_dir = data
            image_dict = {}
            annotation_dict = {}

            # loads the annotations for the split into RAM (less than 100 MB) to support streaming
            for root, _, files in os.walk(annotations_dir):
                for file_annot in files:
                    if file_annot.endswith(".png"):
                        image_id = os.path.splitext(file_annot)[0]
                        annotation_dict[image_id] = os.path.join(root, file_annot)

            idx = 0
            for root, _, files in os.walk(images_dir):
                for file_img in files:
                    if file_img.endswith(".png"):
                        image_id = os.path.splitext(file_img)[0]
                        image_dict[image_id] = os.path.join(root, file_img)

                        path_img = image_dict[image_id]
                        path_annot = annotation_dict[image_id]

                        with open(path_img, "rb") as f_img:
                            bytes_img = f_img.read()
                        with open(path_annot, "rb") as f_annot:
                            bytes_annot = f_annot.read()

                        yield idx, {
                            "image": {"path": path_img, "bytes": bytes_img},
                            "annotation": {"path": path_annot, "bytes": bytes_annot},
                        }
                        idx += 1