File size: 1,123 Bytes
92142d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd19171
92142d8
 
 
dd19171
 
92142d8
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
import sys
from pathlib import Path
from dronescapes_reader import MultiTaskDataset
from pprint import pprint
from torch.utils.data import DataLoader
import random

def main():
    reader = MultiTaskDataset(Path(sys.argv[1]), handle_missing_data="fill_none")
    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()