# Copyright 2021 Cory Paik. All Rights Reserved. # # 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. # ============================================================================== """ The Color Dataset (CoDa) TODO """ import json import datasets _CITATION = """\ """ _DESCRIPTION = """\ """ _HOMEPAGE = 'https://github.com/nala-cub/coda' _LICENSE = 'Apache 2.0' _URL = 'https://huggingface.co/datasets/corypaik/coda/resolve/main/data' _URLs = { 'default': { 'train': f'{_URL}/default_train.jsonl', 'validation': f'{_URL}/default_validation.jsonl', 'test': f'{_URL}/default_test.jsonl', } } class Coda(datasets.GeneratorBasedBuilder): VERSION = datasets.Version('1.0.0') # TODO(corypaik): add object and annotation configs. def _info(self): features = datasets.Features({ 'class_id': datasets.Value('string'), 'display_name': datasets.Value('string'), 'ngram': datasets.Value('string'), 'label': datasets.Sequence(datasets.Value('float')), 'object_group': datasets.ClassLabel(names=('Single', 'Multi', 'Any')), 'text': datasets.Value('string'), 'template_group': datasets.ClassLabel(names=('clip-imagenet', 'text-masked')), 'template_idx': datasets.Value('int32') }) return datasets.DatasetInfo(description=_DESCRIPTION, features=features, supervised_keys=None, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION) def _split_generators(self, dl_manager): """ Returns SplitGenerators.""" files = dl_manager.download_and_extract(_URLs[self.config.name]) return [ datasets.SplitGenerator(datasets.Split.TRAIN, gen_kwargs={'path': files['train']}), datasets.SplitGenerator(datasets.Split.VALIDATION, gen_kwargs={'path': files['validation']}), datasets.SplitGenerator(datasets.Split.TEST, gen_kwargs={'path': files['test']}), ] def _generate_examples(self, path): with open(path, 'r') as f: for _id, line in enumerate(f.readlines()): yield _id, json.loads(line)