# Copyright 2020 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. import csv import json import os import datasets # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @InProceedings{huggingface:dataset, title = {K-pop girls groups dataset}, author={smwoo, Inc. }, year={2023} } """ _BASE_URL = "https://drive.google.com/u/0/uc?id=16_GUeJcC88LrB8zJni0-XdjdL14WXOVW&export=download" _METADATA_URLS = { "train": "https://drive.google.com/u/0/uc?id=1mPwH_p1-QQtY0xsFjLIzQLkAXDNyB8sO&export=download", "test": "https://drive.google.com/u/0/uc?id=1mPwH_p1-QQtY0xsFjLIzQLkAXDNyB8sO&export=download" } # You can copy an official description _DESCRIPTION = """\ This new dataset is designed to learn how to make custom dataset. """ _HOMEPAGE = "https://cislab.cau.ac.kr/" _LICENSE = "" _IMAGES_DIR = "data/" class GirlsGroupsConfig(datasets.BuilderConfig): """BuilderConfig for GirlsGroups dataset.""" def __init__(self, features, data_url, citation, url, label_classes=("False", "True"), **kwargs): super(GirlsGroupsConfig, self).__init__(version=datasets.Version("1.1.0"), **kwargs) self.features = features self.label_classes = label_classes self.data_url = data_url self.citation = citation self.url = url class GirlsGroups(datasets.GeneratorBasedBuilder): """GirlsGroups Images dataset.""" def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "image": datasets.Image(), "annotation": datasets.Value(dtype='string'), } ), homepage=_HOMEPAGE, citation=_CITATION, license=_LICENSE, ) def _split_generators(self, dl_manager): # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS archive_path = dl_manager.download(_BASE_URL) split_metadata_paths = dl_manager.download(_METADATA_URLS) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "images": dl_manager.iter_archive(archive_path), "metadata_path": split_metadata_paths["train"], }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "images": dl_manager.iter_archive(archive_path), "metadata_path": split_metadata_paths["test"], }, ), ] def _generate_examples(self, images, metadata_path): """Generate images and labels for splits.""" save_list = {} with open(metadata_path, newline='') as csvfile: spamreader = csv.reader(csvfile, delimiter=',', quotechar='|') for row in spamreader: save_list[row[0]] = row[1] for file_path, file_obj in images: yield file_path, { "image": {"path": file_path, "bytes": file_obj.read()}, "annotation" : save_list[file_path] }