Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np
import time
import multiprocessing as mp
import queue
from multiprocessing import Queue
from queue import Empty

SIZE_INC = int(2048)
CHUNK_SIZE = int(128)
Expand Down Expand Up @@ -39,12 +40,12 @@ def init_ds(self):

def run(self):
self.init_ds()
f = file('datasets_ioerrors.txt', 'a')
f = open('datasets_ioerrors.txt', 'a')
while not self.exit.is_set() or not self.q.empty():
try:
res = self.q.get(False, 1e-3)
self._save(res)
except Queue.Empty:
except Empty:
pass
except IOError:
print('IOError, continuing')
Expand All @@ -57,7 +58,7 @@ def run(self):
self.close()

def create_datasets(self, tables, compression=None):
for tname, ttype in tables.iteritems():
for tname, ttype in tables.items():
tname_split = tname.split('/')
if len(tname_split) > 1:
grpname, subtname = tname_split
Expand Down Expand Up @@ -92,7 +93,7 @@ def save(self, data):
raise Queue.Full('dataset buffer overflow')

def _save(self, data):
for col,val in data.iteritems():
for col,val in data.items():
self.outbuffers[col].append(val)
if len(self.outbuffers[col]) == self.chunk_size:
self[col][self.ptrs[col]:self.ptrs[col] + self.chunk_size] = \
Expand Down
11 changes: 6 additions & 5 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from __future__ import print_function
import os, sys, time, argparse
import Queue
from multiprocessing import Queue
from queue import Empty
import numpy as np
import h5py
from copy import deepcopy
Expand Down Expand Up @@ -133,7 +134,7 @@ def raster_evts(data):
while m.has_data and sys_ts <= tstop*1e-6:
try:
sys_ts, d = m.get()
except Queue.Empty:
except Empty:
# wait for queue to fill up
time.sleep(0.01)
continue
Expand All @@ -158,7 +159,7 @@ def raster_evts(data):
while t_pre + args.binsize < d['timestamp'] + t_offset:
# aps frame is not in current bin -> save and proceed
f_out.save(deepcopy(current_row))
current_row['dvs_frame'][:,:] = 0
current_row['dvs_frame'] = 0
current_row['timestamp'] = t_pre
t_pre += args.binsize
else:
Expand All @@ -175,7 +176,7 @@ def raster_evts(data):
if fixed_dt:
# fixed time interval bin mode
num_samples = int(np.ceil((times[-1] - t_pre) / args.binsize))
for _ in xrange(num_samples):
for _ in range(0, num_samples):
# take n events
n = (times[offset:] < t_pre + args.binsize).sum()
sel = slice(offset, offset + n)
Expand All @@ -191,7 +192,7 @@ def raster_evts(data):
else:
# fixed event count mode
num_samples = np.ceil(-float(num_evts + ev_count)/args.binsize)
for _ in xrange(int(num_samples)):
for _ in range(int(num_samples)):
n = min(int(-args.binsize - ev_count), num_evts - offset)
sel = slice(offset, offset + n)
current_row['dvs_frame'] += raster_evts(d['data'][sel])
Expand Down
2 changes: 1 addition & 1 deletion get_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
data = f[k]['data'][nnz, :]
t, v = data[:, 0] * 1e-6, data[:, 1]
curve = ip.interp1d(t, v)
tnew = np.linspace(t[0], t[-1], (t[-1] - t[0]) / tstep)
tnew = np.linspace(t[0], t[-1], int((t[-1] - t[0]) / tstep))
vout.append(curve(tnew))

out = np.hstack(vout)
Expand Down
13 changes: 8 additions & 5 deletions hdf5_deeplearn_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import h5py
import numpy as np
from scipy.misc import imresize
#from scipy.misc import imresize
from skimage.transform import resize
from collections import defaultdict

def get_real_endpoint(h5f):
Expand All @@ -15,7 +16,7 @@ def chunker(seq, size):
return (seq[pos:pos + size] for pos in xrange(0, len(seq), size))

def yield_chunker(seq, size):
for pos in xrange(0, len(seq), size):
for pos in range(0, len(seq), size):
yield seq[pos:pos + size]

def check_and_fix_timestamps(h5f):
Expand Down Expand Up @@ -237,11 +238,13 @@ def flow(self, h5fs, dataset_keys, indexes_key, batch_size, shuffle=True):
b += 1

def resize_int8(frame, size):
return imresize(frame, size)
#return imresize(frame, size)
return resize(frame, size)

def resize_int16(frame, size=(60,80), method='bilinear', climit=[-15,15]):
# Assumes data is some small amount around the mean, i.e., DVS event sums
return imresize((np.clip(frame, climit[0], climit[1]).astype('float32')+127), size, interp=method).astype('uint8')
#return imresize((np.clip(frame, climit[0], climit[1]).astype('float32')+127), size, interp=method).astype('uint8')
return resize((np.clip(frame, climit[0], climit[1]).astype('float32')+127), size).astype('uint8')

def resize_data_into_new_key(h5f, key, new_key, new_size, chunk_size=1024):
chunk_generator = yield_chunker(h5f[key], chunk_size)
Expand All @@ -255,7 +258,7 @@ def resize_data_into_new_key(h5f, key, new_key, new_size, chunk_size=1024):
elif key == 'dvs_frame':
do_resize = resize_int16
else:
raise AssertionError, 'Unknown data type'
raise AssertionError('Unknown data type')
# Initialize a resizable dataset to hold the output
resized_shape = (chunk_size,) + new_size
max_shape = (h5f[key].shape[0],) + resized_shape[1:]
Expand Down
2 changes: 1 addition & 1 deletion interfaces/caer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np
import socket, struct
import multiprocessing as mp
import Queue
from multiprocessing import Queue

HOST = "127.0.0.1"
PORT = 7777
Expand Down
2 changes: 1 addition & 1 deletion interfaces/oxc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import multiprocessing as mp
import numpy as np
from openxc.tools import dump as oxc
import Queue
from multiprocessing import Queue

class Monitor(mp.Process):
def __init__(self, bufsize=256):
Expand Down
6 changes: 3 additions & 3 deletions lasagne_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import lasagne
import cPickle as pickle
import _pickle as pickle
import numpy as np
import theano.tensor as T
# Create 5D tensor type
Expand All @@ -19,12 +19,12 @@ def save_model(filename, suffix, model, log=None, announce=True, log_only=False)
if not log_only:
# Acquire Data
data = lasagne.layers.get_all_param_values(model)
with open(param_filename, 'w') as f:
with open(param_filename, 'wb') as f:
pickle.dump(data, f)
# Generate log filename and dump
if log is not None:
log_filename = '%s.log' % (filename)
with open(log_filename, 'w') as f:
with open(log_filename, 'wb') as f:
pickle.dump(log, f)

def load_model(filename, model):
Expand Down
4 changes: 2 additions & 2 deletions view.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, filename, tables, bufsize=64):
def run(self):
while self.blocks_rem and not self.exit.is_set():
blocks_read = 0
for k in self.blocks_rem.keys():
for k in list(self.blocks_rem):
if self.q[k].full():
time.sleep(1e-6)
continue
Expand Down Expand Up @@ -591,7 +591,7 @@ def caer_event_from_row(row):
help="Examples:\n"
"-s 50%% - play file starting at 50%%\n"
"-s 66s - play file starting at 66s")
parser.add_argument('--rotate', '-r', type=bool, default=False,
parser.add_argument('--rotate', '-r', type=bool, default=True,
help="Rotate the scene 180 degrees if True, "
"Otherwise False")
args = parser.parse_args()
Expand Down