# 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. """UC Merced Land Use Dataset""" import os import datasets _CITATION = """\ @inproceedings{yang2010bagofvisualwords, author = {Yi Yang and Shawn Newsam}, title = {Bag-Of-Visual-Words and Spatial Extensions for Land-Use Classification}, booktitle = {ACM SIGSPATIAL International Conference on Advances in Geographic Information Systems (ACM GIS)}, year = {2010} } """ _DESCRIPTION = """\ This is a 21 class land use image dataset meant for research purposes. There are 100 images for each of the following classes: - agricultural - airplane - baseballdiamond - beach - buildings - chaparral - denseresidential - forest - freeway - golfcourse - harbor - intersection - mediumresidential - mobilehomepark - overpass - parkinglot - river - runway - sparseresidential - storagetanks - tenniscourt Each image measures 256x256 pixels. The images were manually extracted from large images from the USGS National Map Urban Area Imagery collection for various urban areas around the country. The pixel resolution of this public domain imagery is 1 foot. For more information about the original UC Merced Land Use dataset, please visit the official dataset page: http://weegee.vision.ucmerced.edu/datasets/landuse.html Please refer to the original dataset source for any additional details, citations, or specific usage guidelines provided by the dataset creators. """ _HOMEPAGE = "http://weegee.vision.ucmerced.edu/datasets/landuse.html" _LICENSE = "cc0-1.0" _DATA_URL = "http://weegee.vision.ucmerced.edu/datasets/UCMerced_LandUse.zip" _LABEL_NAMES = [ "agricultural", "airplane", "baseballdiamond", "beach", "buildings", "chaparral", "denseresidential", "forest", "freeway", "golfcourse", "harbor", "intersection", "mediumresidential", "mobilehomepark", "overpass", "parkinglot", "river", "runway", "sparseresidential", "storagetanks", "tenniscourt", ] class UCMercedLandUse(datasets.GeneratorBasedBuilder): """A 21 class land use image dataset.""" VERSION = datasets.Version("1.0.0") BUILDER_CONFIGS = [ datasets.BuilderConfig( name="ucmerced_landuse", version=VERSION, description="UC Merced Land Use Dataset", ), ] DEFAULT_CONFIG_NAME = "ucmerced_landuse" def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "img": datasets.Image(), "label": datasets.features.ClassLabel(names=_LABEL_NAMES), } ), homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): # data_dir = dl_manager.download_and_extract(_DATA_URL) script_dir = os.path.dirname(os.path.abspath(__file__)) archive_path = os.path.join(script_dir, "UCMerced_LandUse.zip") data_dir = dl_manager.extract(archive_path) class_dirs = [ os.path.join(data_dir, "UCMerced_LandUse/Images", label) for label in _LABEL_NAMES ] return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "class_dirs": class_dirs, "split": "train", }, ), ] def _generate_examples(self, class_dirs, split): for key, class_dir in enumerate(class_dirs): class_label = os.path.basename(class_dir) # Iterate through the images in the class directory for image_filename in os.listdir(class_dir): image_path = os.path.join(class_dir, image_filename) yield key, { "img": image_path, "label": class_label, }