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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 The HuggingFace Datasets Authors.
|
| 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 |
+
"""Sun397 loading script."""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
import csv
|
| 18 |
+
import json
|
| 19 |
+
import os
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
|
| 22 |
+
import datasets
|
| 23 |
+
|
| 24 |
+
_CITATION = """\
|
| 25 |
+
@INPROCEEDINGS{Xiao:2010,
|
| 26 |
+
author={J. {Xiao} and J. {Hays} and K. A. {Ehinger} and A. {Oliva} and A. {Torralba} },
|
| 27 |
+
booktitle={2010 IEEE Computer Society Conference on Computer Vision and Pattern Recognition},
|
| 28 |
+
title={SUN database: Large-scale scene recognition from abbey to zoo},
|
| 29 |
+
year={2010},
|
| 30 |
+
volume={},
|
| 31 |
+
number={},
|
| 32 |
+
pages={3485-3492},
|
| 33 |
+
keywords={computer vision;human factors;image classification;object recognition;visual databases;SUN database;large-scale scene recognition;abbey;zoo;scene categorization;computer vision;scene understanding research;scene category;object categorization;scene understanding database;state-of-the-art algorithms;human scene classification performance;finer-grained scene representation;Sun;Large-scale systems;Layout;Humans;Image databases;Computer vision;Anthropometry;Bridges;Legged locomotion;Spatial databases},
|
| 34 |
+
doi={10.1109/CVPR.2010.5539970},
|
| 35 |
+
ISSN={1063-6919},
|
| 36 |
+
month={June},}
|
| 37 |
+
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
_DESCRIPTION = """\
|
| 41 |
+
Scene UNderstanding (SUN) database contains 899 categories. The number of images varies across categories, but there are at least 100 images per category, and 108,754 images in total. Images are in jpg, png, or gif format. The images provided here are for research purposes only.
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
_HOMEPAGE = "https://vision.princeton.edu/projects/2010/SUN/"
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
_LICENSE = ""
|
| 48 |
+
|
| 49 |
+
_URLs = {
|
| 50 |
+
"images": "http://vision.princeton.edu/projects/2010/SUN/SUN397.tar.gz",
|
| 51 |
+
"partitions": "http://vision.princeton.edu/projects/2010/SUN/download/Partitions.zip",
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
_VERSION = datasets.Version("1.0.0")
|
| 55 |
+
|
| 56 |
+
_NAMES = [
|
| 57 |
+
"abbey",
|
| 58 |
+
"airplane_cabin",
|
| 59 |
+
"airport_terminal",
|
| 60 |
+
"alley",
|
| 61 |
+
"amphitheater",
|
| 62 |
+
"amusement_arcade",
|
| 63 |
+
"amusement_park",
|
| 64 |
+
"anechoic_chamber",
|
| 65 |
+
"apartment_building/outdoor",
|
| 66 |
+
"apse/indoor",
|
| 67 |
+
"aquarium",
|
| 68 |
+
"aqueduct",
|
| 69 |
+
"arch",
|
| 70 |
+
"archive",
|
| 71 |
+
"arrival_gate/outdoor",
|
| 72 |
+
"art_gallery",
|
| 73 |
+
"art_school",
|
| 74 |
+
"art_studio",
|
| 75 |
+
"assembly_line",
|
| 76 |
+
"athletic_field/outdoor",
|
| 77 |
+
"atrium/public",
|
| 78 |
+
"attic",
|
| 79 |
+
"auditorium",
|
| 80 |
+
"auto_factory",
|
| 81 |
+
"badlands",
|
| 82 |
+
"badminton_court/indoor",
|
| 83 |
+
"baggage_claim",
|
| 84 |
+
"bakery/shop",
|
| 85 |
+
"balcony/exterior",
|
| 86 |
+
"balcony/interior",
|
| 87 |
+
"ball_pit",
|
| 88 |
+
"ballroom",
|
| 89 |
+
"bamboo_forest",
|
| 90 |
+
"banquet_hall",
|
| 91 |
+
"bar",
|
| 92 |
+
"barn",
|
| 93 |
+
"barndoor",
|
| 94 |
+
"baseball_field",
|
| 95 |
+
"basement",
|
| 96 |
+
"basilica",
|
| 97 |
+
"basketball_court/outdoor",
|
| 98 |
+
"bathroom",
|
| 99 |
+
"batters_box",
|
| 100 |
+
"bayou",
|
| 101 |
+
"bazaar/indoor",
|
| 102 |
+
"bazaar/outdoor",
|
| 103 |
+
"beach",
|
| 104 |
+
"beauty_salon",
|
| 105 |
+
"bedroom",
|
| 106 |
+
"berth",
|
| 107 |
+
"biology_laboratory",
|
| 108 |
+
"bistro/indoor",
|
| 109 |
+
"boardwalk",
|
| 110 |
+
"boat_deck",
|
| 111 |
+
"boathouse",
|
| 112 |
+
"bookstore",
|
| 113 |
+
"booth/indoor",
|
| 114 |
+
"botanical_garden",
|
| 115 |
+
"bow_window/indoor",
|
| 116 |
+
"bow_window/outdoor",
|
| 117 |
+
"bowling_alley",
|
| 118 |
+
"boxing_ring",
|
| 119 |
+
"brewery/indoor",
|
| 120 |
+
"bridge",
|
| 121 |
+
"building_facade",
|
| 122 |
+
"bullring",
|
| 123 |
+
"burial_chamber",
|
| 124 |
+
"bus_interior",
|
| 125 |
+
"butchers_shop",
|
| 126 |
+
"butte",
|
| 127 |
+
"cabin/outdoor",
|
| 128 |
+
"cafeteria",
|
| 129 |
+
"campsite",
|
| 130 |
+
"campus",
|
| 131 |
+
"canal/natural",
|
| 132 |
+
"canal/urban",
|
| 133 |
+
"candy_store",
|
| 134 |
+
"canyon",
|
| 135 |
+
"car_interior/backseat",
|
| 136 |
+
"car_interior/frontseat",
|
| 137 |
+
"carrousel",
|
| 138 |
+
"casino/indoor",
|
| 139 |
+
"castle",
|
| 140 |
+
"catacomb",
|
| 141 |
+
"cathedral/indoor",
|
| 142 |
+
"cathedral/outdoor",
|
| 143 |
+
"cavern/indoor",
|
| 144 |
+
"cemetery",
|
| 145 |
+
"chalet",
|
| 146 |
+
"cheese_factory",
|
| 147 |
+
"chemistry_lab",
|
| 148 |
+
"chicken_coop/indoor",
|
| 149 |
+
"chicken_coop/outdoor",
|
| 150 |
+
"childs_room",
|
| 151 |
+
"church/indoor",
|
| 152 |
+
"church/outdoor",
|
| 153 |
+
"classroom",
|
| 154 |
+
"clean_room",
|
| 155 |
+
"cliff",
|
| 156 |
+
"cloister/indoor",
|
| 157 |
+
"closet",
|
| 158 |
+
"clothing_store",
|
| 159 |
+
"coast",
|
| 160 |
+
"cockpit",
|
| 161 |
+
"coffee_shop",
|
| 162 |
+
"computer_room",
|
| 163 |
+
"conference_center",
|
| 164 |
+
"conference_room",
|
| 165 |
+
"construction_site",
|
| 166 |
+
"control_room",
|
| 167 |
+
"control_tower/outdoor",
|
| 168 |
+
"corn_field",
|
| 169 |
+
"corral",
|
| 170 |
+
"corridor",
|
| 171 |
+
"cottage_garden",
|
| 172 |
+
"courthouse",
|
| 173 |
+
"courtroom",
|
| 174 |
+
"courtyard",
|
| 175 |
+
"covered_bridge/exterior",
|
| 176 |
+
"creek",
|
| 177 |
+
"crevasse",
|
| 178 |
+
"crosswalk",
|
| 179 |
+
"cubicle/office",
|
| 180 |
+
"dam",
|
| 181 |
+
"delicatessen",
|
| 182 |
+
"dentists_office",
|
| 183 |
+
"desert/sand",
|
| 184 |
+
"desert/vegetation",
|
| 185 |
+
"diner/indoor",
|
| 186 |
+
"diner/outdoor",
|
| 187 |
+
"dinette/home",
|
| 188 |
+
"dinette/vehicle",
|
| 189 |
+
"dining_car",
|
| 190 |
+
"dining_room",
|
| 191 |
+
"discotheque",
|
| 192 |
+
"dock",
|
| 193 |
+
"doorway/outdoor",
|
| 194 |
+
"dorm_room",
|
| 195 |
+
"driveway",
|
| 196 |
+
"driving_range/outdoor",
|
| 197 |
+
"drugstore",
|
| 198 |
+
"electrical_substation",
|
| 199 |
+
"elevator/door",
|
| 200 |
+
"elevator/interior",
|
| 201 |
+
"elevator_shaft",
|
| 202 |
+
"engine_room",
|
| 203 |
+
"escalator/indoor",
|
| 204 |
+
"excavation",
|
| 205 |
+
"factory/indoor",
|
| 206 |
+
"fairway",
|
| 207 |
+
"fastfood_restaurant",
|
| 208 |
+
"field/cultivated",
|
| 209 |
+
"field/wild",
|
| 210 |
+
"fire_escape",
|
| 211 |
+
"fire_station",
|
| 212 |
+
"firing_range/indoor",
|
| 213 |
+
"fishpond",
|
| 214 |
+
"florist_shop/indoor",
|
| 215 |
+
"food_court",
|
| 216 |
+
"forest/broadleaf",
|
| 217 |
+
"forest/needleleaf",
|
| 218 |
+
"forest_path",
|
| 219 |
+
"forest_road",
|
| 220 |
+
"formal_garden",
|
| 221 |
+
"fountain",
|
| 222 |
+
"galley",
|
| 223 |
+
"game_room",
|
| 224 |
+
"garage/indoor",
|
| 225 |
+
"garbage_dump",
|
| 226 |
+
"gas_station",
|
| 227 |
+
"gazebo/exterior",
|
| 228 |
+
"general_store/indoor",
|
| 229 |
+
"general_store/outdoor",
|
| 230 |
+
"gift_shop",
|
| 231 |
+
"golf_course",
|
| 232 |
+
"greenhouse/indoor",
|
| 233 |
+
"greenhouse/outdoor",
|
| 234 |
+
"gymnasium/indoor",
|
| 235 |
+
"hangar/indoor",
|
| 236 |
+
"hangar/outdoor",
|
| 237 |
+
"harbor",
|
| 238 |
+
"hayfield",
|
| 239 |
+
"heliport",
|
| 240 |
+
"herb_garden",
|
| 241 |
+
"highway",
|
| 242 |
+
"hill",
|
| 243 |
+
"home_office",
|
| 244 |
+
"hospital",
|
| 245 |
+
"hospital_room",
|
| 246 |
+
"hot_spring",
|
| 247 |
+
"hot_tub/outdoor",
|
| 248 |
+
"hotel/outdoor",
|
| 249 |
+
"hotel_room",
|
| 250 |
+
"house",
|
| 251 |
+
"hunting_lodge/outdoor",
|
| 252 |
+
"ice_cream_parlor",
|
| 253 |
+
"ice_floe",
|
| 254 |
+
"ice_shelf",
|
| 255 |
+
"ice_skating_rink/indoor",
|
| 256 |
+
"ice_skating_rink/outdoor",
|
| 257 |
+
"iceberg",
|
| 258 |
+
"igloo",
|
| 259 |
+
"industrial_area",
|
| 260 |
+
"inn/outdoor",
|
| 261 |
+
"islet",
|
| 262 |
+
"jacuzzi/indoor",
|
| 263 |
+
"jail/indoor",
|
| 264 |
+
"jail_cell",
|
| 265 |
+
"jewelry_shop",
|
| 266 |
+
"kasbah",
|
| 267 |
+
"kennel/indoor",
|
| 268 |
+
"kennel/outdoor",
|
| 269 |
+
"kindergarden_classroom",
|
| 270 |
+
"kitchen",
|
| 271 |
+
"kitchenette",
|
| 272 |
+
"labyrinth/outdoor",
|
| 273 |
+
"lake/natural",
|
| 274 |
+
"landfill",
|
| 275 |
+
"landing_deck",
|
| 276 |
+
"laundromat",
|
| 277 |
+
"lecture_room",
|
| 278 |
+
"library/indoor",
|
| 279 |
+
"library/outdoor",
|
| 280 |
+
"lido_deck/outdoor",
|
| 281 |
+
"lift_bridge",
|
| 282 |
+
"lighthouse",
|
| 283 |
+
"limousine_interior",
|
| 284 |
+
"living_room",
|
| 285 |
+
"lobby",
|
| 286 |
+
"lock_chamber",
|
| 287 |
+
"locker_room",
|
| 288 |
+
"mansion",
|
| 289 |
+
"manufactured_home",
|
| 290 |
+
"market/indoor",
|
| 291 |
+
"market/outdoor",
|
| 292 |
+
"marsh",
|
| 293 |
+
"martial_arts_gym",
|
| 294 |
+
"mausoleum",
|
| 295 |
+
"medina",
|
| 296 |
+
"moat/water",
|
| 297 |
+
"monastery/outdoor",
|
| 298 |
+
"mosque/indoor",
|
| 299 |
+
"mosque/outdoor",
|
| 300 |
+
"motel",
|
| 301 |
+
"mountain",
|
| 302 |
+
"mountain_snowy",
|
| 303 |
+
"movie_theater/indoor",
|
| 304 |
+
"museum/indoor",
|
| 305 |
+
"music_store",
|
| 306 |
+
"music_studio",
|
| 307 |
+
"nuclear_power_plant/outdoor",
|
| 308 |
+
"nursery",
|
| 309 |
+
"oast_house",
|
| 310 |
+
"observatory/outdoor",
|
| 311 |
+
"ocean",
|
| 312 |
+
"office",
|
| 313 |
+
"office_building",
|
| 314 |
+
"oil_refinery/outdoor",
|
| 315 |
+
"oilrig",
|
| 316 |
+
"operating_room",
|
| 317 |
+
"orchard",
|
| 318 |
+
"outhouse/outdoor",
|
| 319 |
+
"pagoda",
|
| 320 |
+
"palace",
|
| 321 |
+
"pantry",
|
| 322 |
+
"park",
|
| 323 |
+
"parking_garage/indoor",
|
| 324 |
+
"parking_garage/outdoor",
|
| 325 |
+
"parking_lot",
|
| 326 |
+
"parlor",
|
| 327 |
+
"pasture",
|
| 328 |
+
"patio",
|
| 329 |
+
"pavilion",
|
| 330 |
+
"pharmacy",
|
| 331 |
+
"phone_booth",
|
| 332 |
+
"physics_laboratory",
|
| 333 |
+
"picnic_area",
|
| 334 |
+
"pilothouse/indoor",
|
| 335 |
+
"planetarium/outdoor",
|
| 336 |
+
"playground",
|
| 337 |
+
"playroom",
|
| 338 |
+
"plaza",
|
| 339 |
+
"podium/indoor",
|
| 340 |
+
"podium/outdoor",
|
| 341 |
+
"pond",
|
| 342 |
+
"poolroom/establishment",
|
| 343 |
+
"poolroom/home",
|
| 344 |
+
"power_plant/outdoor",
|
| 345 |
+
"promenade_deck",
|
| 346 |
+
"pub/indoor",
|
| 347 |
+
"pulpit",
|
| 348 |
+
"putting_green",
|
| 349 |
+
"racecourse",
|
| 350 |
+
"raceway",
|
| 351 |
+
"raft",
|
| 352 |
+
"railroad_track",
|
| 353 |
+
"rainforest",
|
| 354 |
+
"reception",
|
| 355 |
+
"recreation_room",
|
| 356 |
+
"residential_neighborhood",
|
| 357 |
+
"restaurant",
|
| 358 |
+
"restaurant_kitchen",
|
| 359 |
+
"restaurant_patio",
|
| 360 |
+
"rice_paddy",
|
| 361 |
+
"riding_arena",
|
| 362 |
+
"river",
|
| 363 |
+
"rock_arch",
|
| 364 |
+
"rope_bridge",
|
| 365 |
+
"ruin",
|
| 366 |
+
"runway",
|
| 367 |
+
"sandbar",
|
| 368 |
+
"sandbox",
|
| 369 |
+
"sauna",
|
| 370 |
+
"schoolhouse",
|
| 371 |
+
"sea_cliff",
|
| 372 |
+
"server_room",
|
| 373 |
+
"shed",
|
| 374 |
+
"shoe_shop",
|
| 375 |
+
"shopfront",
|
| 376 |
+
"shopping_mall/indoor",
|
| 377 |
+
"shower",
|
| 378 |
+
"skatepark",
|
| 379 |
+
"ski_lodge",
|
| 380 |
+
"ski_resort",
|
| 381 |
+
"ski_slope",
|
| 382 |
+
"sky",
|
| 383 |
+
"skyscraper",
|
| 384 |
+
"slum",
|
| 385 |
+
"snowfield",
|
| 386 |
+
"squash_court",
|
| 387 |
+
"stable",
|
| 388 |
+
"stadium/baseball",
|
| 389 |
+
"stadium/football",
|
| 390 |
+
"stage/indoor",
|
| 391 |
+
"staircase",
|
| 392 |
+
"street",
|
| 393 |
+
"subway_interior",
|
| 394 |
+
"subway_station/platform",
|
| 395 |
+
"supermarket",
|
| 396 |
+
"sushi_bar",
|
| 397 |
+
"swamp",
|
| 398 |
+
"swimming_pool/indoor",
|
| 399 |
+
"swimming_pool/outdoor",
|
| 400 |
+
"synagogue/indoor",
|
| 401 |
+
"synagogue/outdoor",
|
| 402 |
+
"television_studio",
|
| 403 |
+
"temple/east_asia",
|
| 404 |
+
"temple/south_asia",
|
| 405 |
+
"tennis_court/indoor",
|
| 406 |
+
"tennis_court/outdoor",
|
| 407 |
+
"tent/outdoor",
|
| 408 |
+
"theater/indoor_procenium",
|
| 409 |
+
"theater/indoor_seats",
|
| 410 |
+
"thriftshop",
|
| 411 |
+
"throne_room",
|
| 412 |
+
"ticket_booth",
|
| 413 |
+
"toll_plaza",
|
| 414 |
+
"topiary_garden",
|
| 415 |
+
"tower",
|
| 416 |
+
"toyshop",
|
| 417 |
+
"track/outdoor",
|
| 418 |
+
"train_railway",
|
| 419 |
+
"train_station/platform",
|
| 420 |
+
"tree_farm",
|
| 421 |
+
"tree_house",
|
| 422 |
+
"trench",
|
| 423 |
+
"underwater/coral_reef",
|
| 424 |
+
"utility_room",
|
| 425 |
+
"valley",
|
| 426 |
+
"van_interior",
|
| 427 |
+
"vegetable_garden",
|
| 428 |
+
"veranda",
|
| 429 |
+
"veterinarians_office",
|
| 430 |
+
"viaduct",
|
| 431 |
+
"videostore",
|
| 432 |
+
"village",
|
| 433 |
+
"vineyard",
|
| 434 |
+
"volcano",
|
| 435 |
+
"volleyball_court/indoor",
|
| 436 |
+
"volleyball_court/outdoor",
|
| 437 |
+
"waiting_room",
|
| 438 |
+
"warehouse/indoor",
|
| 439 |
+
"water_tower",
|
| 440 |
+
"waterfall/block",
|
| 441 |
+
"waterfall/fan",
|
| 442 |
+
"waterfall/plunge",
|
| 443 |
+
"watering_hole",
|
| 444 |
+
"wave",
|
| 445 |
+
"wet_bar",
|
| 446 |
+
"wheat_field",
|
| 447 |
+
"wind_farm",
|
| 448 |
+
"windmill",
|
| 449 |
+
"wine_cellar/barrel_storage",
|
| 450 |
+
"wine_cellar/bottle_storage",
|
| 451 |
+
"wrestling_ring/indoor",
|
| 452 |
+
"yard",
|
| 453 |
+
"youth_hostel",
|
| 454 |
+
]
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
class Sun397Config(datasets.BuilderConfig):
|
| 458 |
+
def __init__(self, partition, **kwargs):
|
| 459 |
+
super(Sun397Config, self).__init__(**kwargs)
|
| 460 |
+
self.partition = partition
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
class Sun397Dataset(datasets.GeneratorBasedBuilder):
|
| 464 |
+
|
| 465 |
+
BUILDER_CONFIGS = [
|
| 466 |
+
Sun397Config(
|
| 467 |
+
name=f"standard-part{partition:d}-120k",
|
| 468 |
+
version=_VERSION,
|
| 469 |
+
partition=partition,
|
| 470 |
+
description=f"Train and test splits from the official partition number {partition:d}.",
|
| 471 |
+
)
|
| 472 |
+
for partition in range(1, 10 + 1)
|
| 473 |
+
]
|
| 474 |
+
|
| 475 |
+
# DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
| 476 |
+
|
| 477 |
+
def _info(self):
|
| 478 |
+
features = datasets.Features(
|
| 479 |
+
{
|
| 480 |
+
"image": datasets.Image(),
|
| 481 |
+
"label": datasets.features.ClassLabel(names=_NAMES),
|
| 482 |
+
}
|
| 483 |
+
)
|
| 484 |
+
return datasets.DatasetInfo(
|
| 485 |
+
description=_DESCRIPTION,
|
| 486 |
+
features=features,
|
| 487 |
+
homepage=_HOMEPAGE,
|
| 488 |
+
license=_LICENSE,
|
| 489 |
+
citation=_CITATION,
|
| 490 |
+
)
|
| 491 |
+
|
| 492 |
+
def _split_generators(self, dl_manager):
|
| 493 |
+
data_dir = dl_manager.download_and_extract(_URLs)
|
| 494 |
+
data_dir = {key: Path(path) for key, path in data_dir.items()}
|
| 495 |
+
data_dir["images"] = data_dir["images"] / "SUN397"
|
| 496 |
+
subset_images = self._get_partition_subsets_images(
|
| 497 |
+
data_dir["images"], data_dir["partitions"]
|
| 498 |
+
)
|
| 499 |
+
return [
|
| 500 |
+
datasets.SplitGenerator(
|
| 501 |
+
name=datasets.Split.TRAIN,
|
| 502 |
+
gen_kwargs={
|
| 503 |
+
"images_dir": data_dir["images"],
|
| 504 |
+
"subset_images": subset_images["tr"],
|
| 505 |
+
},
|
| 506 |
+
),
|
| 507 |
+
datasets.SplitGenerator(
|
| 508 |
+
name=datasets.Split.TEST,
|
| 509 |
+
gen_kwargs={
|
| 510 |
+
"images_dir": data_dir["images"],
|
| 511 |
+
"subset_images": subset_images["te"],
|
| 512 |
+
},
|
| 513 |
+
),
|
| 514 |
+
datasets.SplitGenerator(
|
| 515 |
+
name="other",
|
| 516 |
+
gen_kwargs={
|
| 517 |
+
"images_dir": data_dir["images"],
|
| 518 |
+
"subset_images": subset_images["va"],
|
| 519 |
+
},
|
| 520 |
+
),
|
| 521 |
+
]
|
| 522 |
+
|
| 523 |
+
def _load_image_set_from_file(self, filepath):
|
| 524 |
+
with open(filepath, mode="r") as f:
|
| 525 |
+
return set([line.strip() for line in f])
|
| 526 |
+
|
| 527 |
+
def _get_all_image_paths(self, images_dir):
|
| 528 |
+
return [
|
| 529 |
+
str(path)[len(str(images_dir)) :] for path in images_dir.rglob("sun_*.jpg")
|
| 530 |
+
]
|
| 531 |
+
|
| 532 |
+
def _get_partition_subsets_images(self, images_dir, partitions_dir):
|
| 533 |
+
# Get the ID of all images in the dataset.
|
| 534 |
+
all_images = set(self._get_all_image_paths(images_dir))
|
| 535 |
+
# Load the images in the training/test split of this partition.
|
| 536 |
+
partition = self.config.partition
|
| 537 |
+
filenames = {
|
| 538 |
+
"tr": f"Training_{partition:02d}.txt",
|
| 539 |
+
"te": f"Testing_{partition:02d}.txt",
|
| 540 |
+
}
|
| 541 |
+
splits_sets = {}
|
| 542 |
+
for split, filename in filenames.items():
|
| 543 |
+
filepath = partitions_dir / filename
|
| 544 |
+
splits_sets[split] = self._load_image_set_from_file(filepath)
|
| 545 |
+
# Put the remaining images in the dataset into the "validation" split.
|
| 546 |
+
splits_sets["va"] = all_images - (splits_sets["tr"] | splits_sets["te"])
|
| 547 |
+
return splits_sets
|
| 548 |
+
|
| 549 |
+
def _generate_examples(self, images_dir, subset_images):
|
| 550 |
+
for image_name in subset_images:
|
| 551 |
+
label = "/".join(image_name.split("/")[2:-1])
|
| 552 |
+
image_path = images_dir / image_name
|
| 553 |
+
record = {"image": str(image_path), "label": label}
|
| 554 |
+
yield image_name, record
|