Commit 728f9cfc authored by David GEISSBUHLER's avatar David GEISSBUHLER
Browse files

unifinished api defs

parent 03a7e755
Pipeline #42332 passed with stage
in 14 minutes and 5 seconds
from bob.io.stream import Stream, StreamFile, StreamFilter, stream_filter, StreamServer, StreamRemote
import numpy as np
import bob.io.base
# create data sets
num_frame = 10
num_chan = 3
num_width = 40
num_height = 30
data_shape = (num_frame, num_chan, num_width, num_height)
data_a = np.random.random_sample(data_shape)
data_b = np.random.random_integers(5000, size=data_shape)
assert(data_a.shape == data_shape)
assert(data_b.shape == data_shape)
# create data file
f = bob.io.base.HDF5File('data_file.h5', 'w')
f.set('data_a', data_a)
f.set('data_b', data_b)
del f
# TODO timestamps
# TODO config
# load as stream
f = StreamFile( 'data_file.h5', 'configjson'))
color = Stream('color', f)
nir_left = Stream('nir_left_stereo', f).adjust(color)
###########
fo = StreamFile('test.h5', 'w')
so = Stream('out')
co = so.clean()
co.save(fo)
for i in range(10):
so[i] = data
# or
so.append(data)
# or
fo = StreamFile('test.h5', 'w')
so = Stream('out')
co = so.clean()
for i in range(10):
so[i] = data
fo.save(co)
from .streamfile import StreamFile
from .stream_file import StreamFile
from .stream import Stream
from .streamfilters import StreamFilter
# does that work?
from .stream_filters import *
def get_config():
......
......@@ -7,7 +7,7 @@ from builtins import str
from .utils import StreamArray
from .streamfile import StreamFile
from .stream_file import StreamFile
################################################################################
......@@ -178,3 +178,37 @@ def stream_filter(name):
return Filter
return wrapper
################################################################################
# Stream Filters
### default ###
@stream_filter("nop")
class StreamFilter(Stream):
def __init__(self, name, parent):
super().__init__(name=name, parent=parent)
pass
def get_indices(self, index):
return super().get_indices(index)
def process(self, data, indices):
assert isinstance(indices, list)
return np.stack([self.process_frame(data[i], i, indices[i]) for i in range(data.shape[0])])
def process_frame(self, data, data_index, stream_index):
return data
# load one or several frames
def load(self, index):
indices = self.get_indices(index)
# return buffered data OR load from file OR process data
if self._Stream__loaded == indices and self._Stream__data is not None:
# print('loaded', self.name)
pass
else:
self.__data = self.process(self.parent.load(indices), indices)
# buffer and return data
self.__loaded = indices
return self.__data
......@@ -7,7 +7,6 @@ from bob.ip.stereo import load_camera_config
from .config import load_data_config
class StreamFile:
def __init__(self, hdf5_file_path=None, data_format_config_file_path=None, camera_config_file_path=None, mode="r"):
if hdf5_file_path is not None:
......
......@@ -9,43 +9,7 @@ from .utils import convert_cv_to_bob, StreamArray
from bob.ip.stereo import StereoParameters
from bob.ip.stereo import stereo_match, reproject_image, CameraPair
from .stream import stream_filter, Stream
################################################################################
# Stream Filters
### default ###
@stream_filter("nop")
class StreamFilter(Stream):
def __init__(self, name, parent):
super().__init__(name=name, parent=parent)
pass
def get_indices(self, index):
return super().get_indices(index)
def process(self, data, indices):
assert isinstance(indices, list)
return np.stack([self.process_frame(data[i], i, indices[i]) for i in range(data.shape[0])])
def process_frame(self, data, data_index, stream_index):
return data
# load one or several frames
def load(self, index):
indices = self.get_indices(index)
# return buffered data OR load from file OR process data
if self._Stream__loaded == indices and self._Stream__data is not None:
# print('loaded', self.name)
pass
else:
self.__data = self.process(self.parent.load(indices), indices)
# buffer and return data
self.__loaded = indices
return self.__data
from .stream import stream_filter, Stream, StreamFilter
### channel ###
@stream_filter("select")
......@@ -67,7 +31,7 @@ class Select(StreamFilter):
### astype ###
@stream_filter("astype")
class Select(StreamFilter):
class AsType(StreamFilter):
def __init__(self, name, parent, dtype=None):
super().__init__(name=name, parent=parent)
if dtype is not None:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment