CoolFace
Datasetpublic

hf-internal-testing/fixtures-captioning

\\n

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes2.8kdownloads
fixtures-captioning.py80 linesDownload Raw Back to root
1# coding=utf-82# Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8#     http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15import textwrap16import datasets17_CITATION = """\\n"""18_DESCRIPTION = """\\n"""19class FixturesCaptioningConfig(datasets.BuilderConfig):20    """BuilderConfig for fixtures captioning"""21    def __init__(22        self,23        data_url,24        url,25        task_templates=None,26        **kwargs,27    ):28        super(FixturesCaptioningConfig, self).__init__(29            version=datasets.Version("1.9.0", ""), **kwargs30        )31        self.data_url = data_url32        self.url = url33        self.task_templates = task_templates34        35class FixturesCaptioning(datasets.GeneratorBasedBuilder):36    """Fixtures for captioning and VQA models. Includes 4 images."""37    BUILDER_CONFIGS = [38        FixturesCaptioningConfig(39            name="image",40            description=textwrap.dedent(""),41            url="",42            data_url="",43        )44    ]45    DEFAULT_CONFIG_NAME = "image"46    def _info(self):47        return datasets.DatasetInfo(48            description=_DESCRIPTION,49            features=datasets.Features(50                {51                    "id": datasets.Value("string"),52                    "file": datasets.Value("string"),53                }54            ),55            supervised_keys=("file",),56            homepage=self.config.url,57            citation=_CITATION,58        )59    def _split_generators(self, dl_manager):60        61        DL_URLS = [62            f"https://huggingface.co/datasets/hf-internal-testing/fixtures-captioning/raw/main/{name}"63            for name in ["bbox_sample_image.jpeg", "bus.png", "chart.png", "skateboard.png"]64        ]65        archive_path = dl_manager.download_and_extract(DL_URLS)66        return [67            datasets.SplitGenerator(68                name=datasets.Split.TEST,69                gen_kwargs={"archive_path": archive_path},70            ),71        ]72    def _generate_examples(self, archive_path):73        """Generate examples."""74        for i, filename in enumerate(archive_path):75            key = str(i)76            example = {77                "id": key,78                "file": filename,79            }80            yield key, example