-
Notifications
You must be signed in to change notification settings - Fork 1
/
DVSGenerator.py
45 lines (36 loc) · 1.34 KB
/
DVSGenerator.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
import os, sys
import torch
import dvs2tensor
import argparse
def sparse_generator_func(packet_size, buffer_size, ID):
"""
Generates sparse data from DVS camera data
"""
dvsdataconv = dvs2tensor.DVSDataConv(packet_size, buffer_size)
dvsdataconv.connect2camera(ID)
dvsdataconv.startdatastream()
try:
while True:
yield dvsdataconv.update()
except GeneratorExit:
exitcode = dvsdataconv.stopdatastream()
if __name__ == "__main__":
# Get input arguments from shell
parser = argparse.ArgumentParser("Stream sparse tensor data")
# General Configs
parser.add_argument("--events", default=1000, type=int, help="Specify number of events")
parser.add_argument("--id", default=1, type=int, help="Specify camera id")
# Event configs
parser.add_argument("--packet_size", default=1000, type=int, help="Specify interval size")
parser.add_argument("--buffer", default=512, type=int, help="Specify size of buffer")
# Get arguments
args = parser.parse_args()
gen = sparse_generator_func(args.packet_size, args.buffer, args.id)
i = 0
# Iterate over generator
for sparse_tensor in gen:
print("First part of tensor: " + str(sparse_tensor))
print("Tensor size: " + str(sparse_tensor.shape))
i+= 1
if i == args.events:
break