Skip to content

Commit

Permalink
[Bugfix] FlowPipe was not reading frames off the frame queue in the c…
Browse files Browse the repository at this point in the history
…orrect order
  • Loading branch information
willprice committed Apr 29, 2019
1 parent eff46b7 commit 48c2058
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/flowty/flow_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def run(self):
frame_queue = deque()
frame_iter = iter(self.src)
while len(frame_queue) < self.dilation:
frame_queue.appendleft(next(frame_iter))
frame_queue.append(next(frame_iter))
assert len(frame_queue) == self.dilation

t = time.time()
for i, target in enumerate(frame_iter):
data_load_time = time.time() - t
print("Data time (ms): ", data_load_time * 1e3)
reference = frame_queue.popleft()
frame_queue.appendleft(target)
frame_queue.append(target)
assert len(frame_queue) == self.dilation
if i % self.stride == 0:
t = time.time()
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/test_flow_pipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from flowty.flow_pipe import FlowPipe
import numpy as np


class RecordingDestination:
def __init__(self):
self.flow = []

def write(self, flow):
self.flow.append(flow)


class TestFlowPipe:
def test_1_flow_field_between_2_frames(self):
flow = self.compute_flow([1, 2])
assert len(flow) == 1
assert flow[0] == np.array([1])

def test_2_flow_fields_between_3_frames(self):
flow = self.compute_flow([1, 2, 4])
assert len(flow) == 2
assert flow == [np.array([1]), np.array([2])]

def test_1_flow_field_between_3_frames_when_dilation_is_2(self):
flow = self.compute_flow([1, 2, 3], dilation=2)
assert len(flow) == 1
assert flow[0] == np.array([2])

def test_2_flow_fields_between_4_frames_when_dilation_is_2(self):
flow = self.compute_flow([1, 2, 3, 5], dilation=2)
assert flow == [np.array([2]), np.array([3])]

def compute_flow(self, frames, dilation=1, stride=1):
src = [np.array([f]) for f in frames]

def flow_algorithm(reference, target):
print("target: {}, reference: {}".format(target ,reference))
return target - reference

dest = RecordingDestination()
pipe = FlowPipe(
src, flow_algorithm, dest, dilation=dilation, stride=stride
)
pipe.run()
return dest.flow

0 comments on commit 48c2058

Please sign in to comment.