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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
| 15 |
+
"""TODO: Add a description here."""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import csv
|
| 19 |
+
import json
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
import datasets
|
| 23 |
+
from datasets.tasks import ImageClassification
|
| 24 |
+
|
| 25 |
+
_CITATION = """\
|
| 26 |
+
@article{FeiFei2004LearningGV,
|
| 27 |
+
title={Learning Generative Visual Models from Few Training Examples: An Incremental Bayesian Approach Tested on 101 Object Categories},
|
| 28 |
+
author={Li Fei-Fei and Rob Fergus and Pietro Perona},
|
| 29 |
+
journal={Computer Vision and Pattern Recognition Workshop},
|
| 30 |
+
year={2004},
|
| 31 |
+
}
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
_DESCRIPTION = """\
|
| 35 |
+
Pictures of objects belonging to 101 categories.
|
| 36 |
+
About 40 to 800 images per category.
|
| 37 |
+
Most categories have about 50 images.
|
| 38 |
+
Collected in September 2003 by Fei-Fei Li, Marco Andreetto, and Marc'Aurelio Ranzato.
|
| 39 |
+
The size of each image is roughly 300 x 200 pixels.
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
_HOMEPAGE = "https://data.caltech.edu/records/20086"
|
| 43 |
+
|
| 44 |
+
_LICENSE = "CC BY 4.0"
|
| 45 |
+
|
| 46 |
+
_DATA_URL = "brand_new_data/caltech-101.zip"
|
| 47 |
+
# _DATA_URL = "brand_new_data/caltech-101/101_ObjectCategories.tar.gz"
|
| 48 |
+
|
| 49 |
+
_NAMES = [
|
| 50 |
+
"accordion",
|
| 51 |
+
"airplanes",
|
| 52 |
+
"anchor",
|
| 53 |
+
"ant",
|
| 54 |
+
"background_google",
|
| 55 |
+
"barrel",
|
| 56 |
+
"bass",
|
| 57 |
+
"beaver",
|
| 58 |
+
"binocular",
|
| 59 |
+
"bonsai",
|
| 60 |
+
"brain",
|
| 61 |
+
"brontosaurus",
|
| 62 |
+
"buddha",
|
| 63 |
+
"butterfly",
|
| 64 |
+
"camera",
|
| 65 |
+
"cannon",
|
| 66 |
+
"car_side",
|
| 67 |
+
"ceiling_fan",
|
| 68 |
+
"cellphone",
|
| 69 |
+
"chair",
|
| 70 |
+
"chandelier",
|
| 71 |
+
"cougar_body",
|
| 72 |
+
"cougar_face",
|
| 73 |
+
"crab",
|
| 74 |
+
"crayfish",
|
| 75 |
+
"crocodile",
|
| 76 |
+
"crocodile_head",
|
| 77 |
+
"cup",
|
| 78 |
+
"dalmatian",
|
| 79 |
+
"dollar_bill",
|
| 80 |
+
"dolphin",
|
| 81 |
+
"dragonfly",
|
| 82 |
+
"electric_guitar",
|
| 83 |
+
"elephant",
|
| 84 |
+
"emu",
|
| 85 |
+
"euphonium",
|
| 86 |
+
"ewer",
|
| 87 |
+
"faces",
|
| 88 |
+
"faces_easy",
|
| 89 |
+
"ferry",
|
| 90 |
+
"flamingo",
|
| 91 |
+
"flamingo_head",
|
| 92 |
+
"garfield",
|
| 93 |
+
"gerenuk",
|
| 94 |
+
"gramophone",
|
| 95 |
+
"grand_piano",
|
| 96 |
+
"hawksbill",
|
| 97 |
+
"headphone",
|
| 98 |
+
"hedgehog",
|
| 99 |
+
"helicopter",
|
| 100 |
+
"ibis",
|
| 101 |
+
"inline_skate",
|
| 102 |
+
"joshua_tree",
|
| 103 |
+
"kangaroo",
|
| 104 |
+
"ketch",
|
| 105 |
+
"lamp",
|
| 106 |
+
"laptop",
|
| 107 |
+
"leopards",
|
| 108 |
+
"llama",
|
| 109 |
+
"lobster",
|
| 110 |
+
"lotus",
|
| 111 |
+
"mandolin",
|
| 112 |
+
"mayfly",
|
| 113 |
+
"menorah",
|
| 114 |
+
"metronome",
|
| 115 |
+
"minaret",
|
| 116 |
+
"motorbikes",
|
| 117 |
+
"nautilus",
|
| 118 |
+
"octopus",
|
| 119 |
+
"okapi",
|
| 120 |
+
"pagoda",
|
| 121 |
+
"panda",
|
| 122 |
+
"pigeon",
|
| 123 |
+
"pizza",
|
| 124 |
+
"platypus",
|
| 125 |
+
"pyramid",
|
| 126 |
+
"revolver",
|
| 127 |
+
"rhino",
|
| 128 |
+
"rooster",
|
| 129 |
+
"saxophone",
|
| 130 |
+
"schooner",
|
| 131 |
+
"scissors",
|
| 132 |
+
"scorpion",
|
| 133 |
+
"sea_horse",
|
| 134 |
+
"snoopy",
|
| 135 |
+
"soccer_ball",
|
| 136 |
+
"stapler",
|
| 137 |
+
"starfish",
|
| 138 |
+
"stegosaurus",
|
| 139 |
+
"stop_sign",
|
| 140 |
+
"strawberry",
|
| 141 |
+
"sunflower",
|
| 142 |
+
"tick",
|
| 143 |
+
"trilobite",
|
| 144 |
+
"umbrella",
|
| 145 |
+
"watch",
|
| 146 |
+
"water_lilly",
|
| 147 |
+
"wheelchair",
|
| 148 |
+
"wild_cat",
|
| 149 |
+
"windsor_chair",
|
| 150 |
+
"wrench",
|
| 151 |
+
"yin_yang",
|
| 152 |
+
]
|
| 153 |
+
|
| 154 |
+
_TRAIN_POINTS_PER_CLASS = 30
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
class Caltech101(datasets.GeneratorBasedBuilder):
|
| 158 |
+
"""Caltech 101 dataset."""
|
| 159 |
+
|
| 160 |
+
VERSION = datasets.Version("1.0.0")
|
| 161 |
+
|
| 162 |
+
def _info(self):
|
| 163 |
+
return datasets.DatasetInfo(
|
| 164 |
+
description=_DESCRIPTION,
|
| 165 |
+
features=datasets.Features(
|
| 166 |
+
{
|
| 167 |
+
"img": datasets.Image(),
|
| 168 |
+
"label": datasets.features.ClassLabel(names=_NAMES),
|
| 169 |
+
}
|
| 170 |
+
),
|
| 171 |
+
supervised_keys=("img", "label"),
|
| 172 |
+
homepage=_HOMEPAGE,
|
| 173 |
+
license=_LICENSE,
|
| 174 |
+
citation=_CITATION,
|
| 175 |
+
task_templates=ImageClassification(
|
| 176 |
+
image_column="img", label_column="label"
|
| 177 |
+
),
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
def _split_generators(self, dl_manager):
|
| 181 |
+
# ----- Work in progress here -----
|
| 182 |
+
data_dir = dl_manager.download_and_extract(_DATA_URL)
|
| 183 |
+
files = dl_manager.iter_files(data_dir)
|
| 184 |
+
# ---------------------------------
|
| 185 |
+
return [
|
| 186 |
+
datasets.SplitGenerator(
|
| 187 |
+
name=datasets.Split.TRAIN,
|
| 188 |
+
# These kwargs will be passed to _generate_examples
|
| 189 |
+
gen_kwargs={
|
| 190 |
+
"filepath": data_dir, # TODO: change accordingly
|
| 191 |
+
"split": "train",
|
| 192 |
+
},
|
| 193 |
+
),
|
| 194 |
+
datasets.SplitGenerator(
|
| 195 |
+
name=datasets.Split.TEST,
|
| 196 |
+
# These kwargs will be passed to _generate_examples
|
| 197 |
+
gen_kwargs={
|
| 198 |
+
"filepath": data_dir, # TODO: change accordingly
|
| 199 |
+
"split": "test",
|
| 200 |
+
},
|
| 201 |
+
),
|
| 202 |
+
]
|
| 203 |
+
|
| 204 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
| 205 |
+
def _generate_examples(self, filepath, split):
|
| 206 |
+
# TODO
|
| 207 |
+
pass
|