|
| 1 | +import os.path as osp |
| 2 | + |
| 3 | +from dassl.data.datasets import DATASET_REGISTRY |
| 4 | + |
| 5 | +from .wilds_base import WILDSBase |
| 6 | + |
| 7 | +CATEGORIES = [ |
| 8 | + "airport", "airport_hangar", "airport_terminal", "amusement_park", |
| 9 | + "aquaculture", "archaeological_site", "barn", "border_checkpoint", |
| 10 | + "burial_site", "car_dealership", "construction_site", "crop_field", "dam", |
| 11 | + "debris_or_rubble", "educational_institution", "electric_substation", |
| 12 | + "factory_or_powerplant", "fire_station", "flooded_road", "fountain", |
| 13 | + "gas_station", "golf_course", "ground_transportation_station", "helipad", |
| 14 | + "hospital", "impoverished_settlement", "interchange", "lake_or_pond", |
| 15 | + "lighthouse", "military_facility", "multi-unit_residential", |
| 16 | + "nuclear_powerplant", "office_building", "oil_or_gas_facility", "park", |
| 17 | + "parking_lot_or_garage", "place_of_worship", "police_station", "port", |
| 18 | + "prison", "race_track", "railway_bridge", "recreational_facility", |
| 19 | + "road_bridge", "runway", "shipyard", "shopping_mall", |
| 20 | + "single-unit_residential", "smokestack", "solar_farm", "space_facility", |
| 21 | + "stadium", "storage_tank", "surface_mine", "swimming_pool", "toll_booth", |
| 22 | + "tower", "tunnel_opening", "waste_disposal", "water_treatment_facility", |
| 23 | + "wind_farm", "zoo" |
| 24 | +] |
| 25 | + |
| 26 | + |
| 27 | +@DATASET_REGISTRY.register() |
| 28 | +class FMoW(WILDSBase): |
| 29 | + """Satellite imagery classification. |
| 30 | +
|
| 31 | + 62 classes (building or land use categories). |
| 32 | +
|
| 33 | + Reference: |
| 34 | + - Christie et al. "Functional Map of the World." CVPR 2018. |
| 35 | + - Koh et al. "Wilds: A benchmark of in-the-wild distribution shifts." ICML 2021. |
| 36 | + """ |
| 37 | + |
| 38 | + dataset_dir = "fmow_v1.1" |
| 39 | + |
| 40 | + def __init__(self, cfg): |
| 41 | + super().__init__(cfg) |
| 42 | + |
| 43 | + def get_image_path(self, dataset, idx): |
| 44 | + idx = dataset.full_idxs[idx] |
| 45 | + image_name = f"rgb_img_{idx}.png" |
| 46 | + image_path = osp.join(self.dataset_dir, "images", image_name) |
| 47 | + return image_path |
| 48 | + |
| 49 | + def get_domain(self, dataset, idx): |
| 50 | + # number of regions: 5 or 6 |
| 51 | + # number of years: 16 |
| 52 | + region_id = int(dataset.metadata_array[idx][0]) |
| 53 | + year_id = int(dataset.metadata_array[idx][1]) |
| 54 | + return region_id*16 + year_id |
| 55 | + |
| 56 | + def load_classnames(self): |
| 57 | + return {i: cat for i, cat in enumerate(CATEGORIES)} |
0 commit comments