Datasets:
ArXiv:
DOI:
License:
File size: 6,960 Bytes
4a613d6 37673fa 4a613d6 63632a6 c4aabc3 4a613d6 f0e1f7c 63632a6 4a613d6 c4aabc3 4a613d6 db1c650 4a613d6 9e50a10 4a613d6 9e50a10 4a613d6 9e50a10 4a613d6 593062f 4a613d6 edd07ce 4a613d6 ace1c21 4a613d6 9dedc83 4a613d6 534b22e 9126851 4a613d6 63632a6 4a613d6 0dfdc3b 4a613d6 30467d3 4a613d6 |
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# coding=utf-8
# Copyright 2022 The HuggingFace Datasets Authors and ProgramComputer.
#
# 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.
# Lint as: python3
"""VGGFace2 audio-visual human speech dataset."""
import json
import os
import re
from urllib.parse import urlparse, parse_qs
from getpass import getpass
from hashlib import sha256
from itertools import repeat
from multiprocessing import Manager, Pool, Process
from pathlib import Path
from shutil import copyfileobj
from warnings import catch_warnings, filterwarnings
from urllib3.exceptions import InsecureRequestWarning
import pandas as pd
import requests
import datasets
_DESCRIPTION = "VGGFace2 is a large-scale face recognition dataset. Images are downloaded from Google Image Search and have large variations in pose, age, illumination, ethnicity and profession."
_CITATION = """\
@article{DBLP:journals/corr/abs-1710-08092,
author = {Qiong Cao and
Li Shen and
Weidi Xie and
Omkar M. Parkhi and
Andrew Zisserman},
title = {VGGFace2: {A} dataset for recognising faces across pose and age},
journal = {CoRR},
volume = {abs/1710.08092},
year = {2017},
url = {http://arxiv.org/abs/1710.08092},
eprinttype = {arXiv},
eprint = {1710.08092},
timestamp = {Wed, 04 Aug 2021 07:50:14 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-1710-08092.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
"""
_URLS = {
"default": {
"train": "https://huggingface.co/datasets/ProgramComputer/VGGFace2/resolve/main/data/vggface2_train.tar.gz",
"test": "https://huggingface.co/datasets/ProgramComputer/VGGFace2/resolve/main/data/vggface2_test.tar.gz",
}
}
class VGGFace2(datasets.GeneratorBasedBuilder):
"""VGGFace2 is dataset contains faces from Google Search"""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig( version=VERSION
)
]
def _info(self):
features = {
"image": datasets.Image(),
"image_id": datasets.Value("string"),
"class_id": datasets.Value("string"),
"identity": datasets.Value("string"),
'gender': datasets.Value("string"),
'sample_num':datasets.Value("uint64"),
'flag':datasets.Value("bool"),
"male": datasets.Value("bool"),
"black_hair": datasets.Value("bool"),
"gray_hair": datasets.Value("bool"),
"blond_hair": datasets.Value("bool"),
"long_hair": datasets.Value("bool"),
"mustache_or_beard": datasets.Value("bool"),
"wearing_hat": datasets.Value("bool"),
"eyeglasses": datasets.Value("bool"),
"sunglasses": datasets.Value("bool"),
"mouth_open": datasets.Value("bool"),
}
return datasets.DatasetInfo(
description=_DESCRIPTION,
supervised_keys=datasets.info.SupervisedKeysData("file", "class_id"),
features=datasets.Features(features),
citation=_CITATION,
)
def _split_generators(self, dl_manager):
targets = (
["01-Male.txt", "02-Black_Hair.txt","03-Brown_Hair.txt","04-Gray_Hair.txt","05-Blond_Hair.txt","06-Long_Hair.txt","07-Mustache_or_Beard.txt","08-Wearing_Hat.txt","09-Eyeglasses.txt","10-Sunglasses.txt","11-Mouth_Open.txt"]
)
target_dict = dict(
(
re.sub(r"^\d+-|\.txt$","",target),
f"https://raw.githubusercontent.com/ox-vgg/vgg_face2/master/attributes/{target}",
)
for target in targets
)
target_dict['identity'] = "https://huggingface.co/datasets/ProgramComputer/VGGFace2/raw/main/meta/identity_meta.csv"
metadata = dl_manager.download(
target_dict
)
mapped_paths_train = dl_manager.iter_archive(
_URLS["default"]["train"]
)
mapped_paths_test = dl_manager.iter_archive(
_URLS["default"]["test"]
)
return [
datasets.SplitGenerator(
name="train",
gen_kwargs={
"paths": mapped_paths_train,
"meta_paths": metadata,
},
),
datasets.SplitGenerator(
name="test",
gen_kwargs={
"paths": mapped_paths_test,
"meta_paths": metadata,
},
),
]
def _generate_examples(self, paths, meta_paths):
key = 0
meta = pd.read_csv(
meta_paths["identity"],
sep=", "
)
for key,conf in [(k,v) for (k,v) in meta_paths.items() if k != "identity"]:
temp = pd.read_csv(conf,sep='\t', header=None)
temp.columns = ['Image_Path', key]
temp['Class_ID'] = temp['Image_Path'].str.split('/').str[0]
#temp['Image_Name'] = temp['Image_Path'].str.split('/').str[1]
temp.drop(columns=['Image_Path'], inplace=True)
meta = meta.merge(temp, on='Class_ID', how='left')
for file_path, file_obj in paths:
label = file_path.split("/")[2]
yield file_path, {
"image": {"path": file_path, "bytes": file_obj.read()},
# "image_id": datasets.Value("string"),
# "class_id": datasets.Value("string"),
# "identity": datasets.Value("string"),
# 'gender': dataset.Value("string"),
# 'sample_num':dataset.Value("uint64"),
# 'flag':dataset.Value("bool"),
# "male": datasets.Value("bool"),
# "black_hair": datasets.Value("bool"),
# "gray_hair": datasets.Value("bool"),
# "blond_hair": datasets.Value("bool"),
# "long_hair": datasets.Value("bool"),
# "mustache_or_beard": datasets.Value("bool"),
# "wearing_hat": datasets.Value("bool"),
# "eyeglasses": datasets.Value("bool"),
# "sunglasses": datasets.Value("bool"),
#"mouth_open": datasets.Value("bool")
}
key+= 1
|