dronescapes / scripts /dronescapes_viewer.py
Meehai's picture
OCD
42071df
raw
history blame
2.21 kB
#!/usr/bin/env python3
import sys
from pathlib import Path
sys.path.append(Path(__file__).parents[1].__str__())
from functools import partial
from dronescapes_reader import MultiTaskDataset, DepthRepresentation, OpticalFlowRepresentation, SemanticRepresentation
from pprint import pprint
from torch.utils.data import DataLoader
import random
def main():
sema_repr = partial(SemanticRepresentation, classes=8, color_map=[[0, 255, 0], [0, 127, 0], [255, 255, 0],
[255, 255, 255], [255, 0, 0], [0, 0, 255],
[0, 255, 255], [127, 127, 63]])
reader = MultiTaskDataset(sys.argv[1], handle_missing_data="fill_none",
task_types={"depth_dpt": DepthRepresentation("depth_dpt", min_depth=0, max_depth=0.999),
"depth_sfm_manual202204": DepthRepresentation("depth_sfm_manual202204",
min_depth=0, max_depth=300),
"opticalflow_rife": OpticalFlowRepresentation,
"semantic_segprop8": sema_repr,
"semantic_mask2former_swin_mapillary_converted": sema_repr})
print(reader)
print("== Shapes ==")
pprint(reader.data_shape)
print("== Random loaded item ==")
rand_ix = random.randint(0, len(reader))
data, name, repr_names = reader[rand_ix] # get a random item
pprint({k: v for k, v in data.items()})
print("== Random loaded batch ==")
batch_data, name, repr_names = reader[rand_ix: min(len(reader), rand_ix + 5)] # get a random batch
pprint({k: v for k, v in batch_data.items()}) # Nones are converted to 0s automagically
print("== Random loaded batch using torch DataLoader ==")
loader = DataLoader(reader, collate_fn=reader.collate_fn, batch_size=5, shuffle=True)
batch_data, name, repr_names = next(iter(loader))
pprint({k: v for k, v in batch_data.items()}) # Nones are converted to 0s automagically
if __name__ == "__main__":
main()