|
|
|
import sys |
|
from pathlib import Path |
|
sys.path.append(Path(__file__).parents[1].__str__()) |
|
from dronescapes_reader import MultiTaskDataset |
|
from dronescapes_reader.dronescapes_representations import dronescapes_task_types |
|
from pprint import pprint |
|
from torch.utils.data import DataLoader |
|
import random |
|
import numpy as np |
|
|
|
def main(): |
|
assert len(sys.argv) == 2, f"Usage ./dronescapes_viewer.py /path/to/dataset" |
|
reader = MultiTaskDataset(sys.argv[1], task_names=list(dronescapes_task_types.keys()), |
|
task_types=dronescapes_task_types, handle_missing_data="fill_nan", |
|
normalization="min_max", cache_task_stats=True) |
|
print(reader) |
|
|
|
print("== Shapes ==") |
|
pprint(reader.data_shape) |
|
|
|
print("== Random loaded item ==") |
|
rand_ix = random.randint(0, len(reader) - 1) |
|
data, name, repr_names = reader[rand_ix] |
|
pprint({k: v for k, v in data.items()}) |
|
|
|
img_data = {} |
|
for k, v in data.items(): |
|
img_data[k] = reader.name_to_task[k].plot_fn(v) if v is not None else np.zeros((*reader.data_shape[k][0:2], 3)) |
|
|
|
print("== Random loaded batch ==") |
|
batch_data, name, repr_names = reader[rand_ix: min(len(reader), rand_ix + 5)] |
|
pprint({k: v for k, v in batch_data.items()}) |
|
|
|
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()}) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|