SkyScenes / SkyScenes.py
apal's picture
Update SkyScenes.py
d0319c4
raw
history blame
No virus
4.72 kB
import collections
import json
import os
import datasets
_DESCRIPTION='SkyScenes, a synthetic dataset of densely annotated aerial images captured from Unmanned Aerial Vehicle (UAV) perspectives. SkyScenes is curated from CARLA to comprehensively capture diversity across layout (urban and rural maps), weather conditions, times of day, pitch angles and altitudes with corresponding semantic, instance and depth annotations.'
_HOMEPAGE = "skyscenes.github.io"
_LICENSE = "MIT"
# _CITATION = """\
# @misc{ buildings-instance-segmentation_dataset,
# title = { Buildings Instance Segmentation Dataset },
# type = { Open Source Dataset },
# author = { Roboflow Universe Projects },
# howpublished = { \\url{ https://universe.roboflow.com/roboflow-universe-projects/buildings-instance-segmentation } },
# url = { https://universe.roboflow.com/roboflow-universe-projects/buildings-instance-segmentation },
# journal = { Roboflow Universe },
# publisher = { Roboflow },
# year = { 2023 },
# month = { jan },
# note = { visited on 2023-01-18 },
# }
# """
_CATEGORIES = ["unlabeled", "building", "fence", "other", "pedestrian", "pole",
"roadline", "road", "sidewalk", "vegetation", "vehicles", "wall",
"trafficsign", "sky", "ground", "bridge", "railtrack", "guardrail",
"trafficlight", "static", "dynamic", "water", "terrain"]
class SKYSCENESConfig(datasets.BuilderConfig):
"""Builder Config for SkyScenes"""
def __init__(self, data_urls, metadata_url, **kwargs):
"""
BuilderConfig for SkyScenes.
Args:
data_urls: `dict`, name to url to download the zip file from.
**kwargs: keyword arguments forwarded to super.
"""
super(SKYSCENESConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
self.data_urls = data_urls
self.metadata_url = metadata_url
class SKYSCENES(datasets.GeneratorBasedBuilder):
"""satellite-building-segmentation instance segmentation dataset"""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
SKYSCENESConfig(
name="full",
description="Full version of skyscenes dataset.",
data_urls="https://huggingface.co/datasets/hoffman-lab/SkyScenes/resolve/main/trial_Segment/H_35_P_90/ClearNoon/Town03/Town03.tar.gz",
metadata_url = "https://huggingface.co/datasets/hoffman-lab/SkyScenes/resolve/main/Images/Town01.txt",)
# SKYSCENESConfig(
# name="mini",
# description="Mini version of satellite-building-segmentation dataset.",
# data_urls=["https://huggingface.co/datasets/hoffman-lab/SkyScenes/resolve/main/Images/H_15_P_0/ClearNight/Town01.tar.gz","https://huggingface.co/datasets/hoffman-lab/SkyScenes/blob/main/Images/H_15_P_0/ClearNight/Town02.tar.gz","https://huggingface.co/datasets/hoffman-lab/SkyScenes/blob/main/Images/H_15_P_0/ClearNight/Town03.tar.gz","https://huggingface.co/datasets/hoffman-lab/SkyScenes/blob/main/Images/H_15_P_0/ClearNight/Town04.tar.gz",]
# )
]
def _info(self):
features = datasets.Features(
{
"image": datasets.Image(),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
homepage=_HOMEPAGE,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
data_files = dl_manager.download_and_extract(self.config.data_urls)
split_metadata_paths = dl_manager.download(self.config.metadata_url)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"images": data_files,
"metadata_path": split_metadata_paths,
},
),
]
def _generate_examples(self, images, metadata_path):
"""Generate images and labels for splits."""
# with open(metadata_path, encoding="utf-8") as f:
# files_to_keep = set(f.read().split("\n"))
# print('KEEP',files_to_keep)
# for file_path, file_obj in images:
for filename in os.listdir(images):
filepath = os.path.join(images, filename)
with open(filepath, "rb") as f:
image_bytes = f.read()
# print('FILE',file_path)
# if file_path.startswith(_IMAGES_DIR):
# if file_path[len(_IMAGES_DIR) : -len(".jpg")] in files_to_keep:
# label = file_path.split("/")[2]
yield filepath, {
"image": {"path": filepath, "bytes": image_bytes},
}