Skip to content

Commit

Permalink
fix a bug in demo program
Browse files Browse the repository at this point in the history
  • Loading branch information
yelantf committed Oct 15, 2020
1 parent 8b43521 commit 99acc16
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions demo/action_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(
self.object_pool = MemoryPool()
self.mem_timestamps = []
self.obj_timestamps = []
self.pred_pos = 0
print("Loading action model weight from {}.".format(cfg.MODEL.WEIGHT))
_ = checkpointer.load(cfg.MODEL.WEIGHT)
print("Action model weight successfully loaded.")
Expand Down Expand Up @@ -145,9 +146,9 @@ def check_ready_timestamp(self):
before, after = self.mem_len
last_ready = last_timestamp - after * self.mem_rate
ready_num = bisect_right(self.mem_timestamps, last_ready)
return ready_num
return ready_num - self.pred_pos
else:
return len(self.mem_timestamps)
return len(self.mem_timestamps) - self.pred_pos
else:
return 0

Expand All @@ -161,6 +162,7 @@ def clear_feature(self, timestamp=None):
self.object_pool = MemoryPool()
self.mem_timestamps = []
self.obj_timestamps = []
self.pred_pos = 0
return

if self.has_memory:
Expand All @@ -173,6 +175,8 @@ def clear_feature(self, timestamp=None):
for t in self.mem_timestamps[:mem_to_release]:
del self.mem_pool["SingleVideo", t]
self.mem_timestamps = self.mem_timestamps[mem_to_release:]
self.pred_pos -= mem_to_release
self.pred_pos = max(self.pred_pos, 0)

obj_to_release = bisect_right(self.obj_timestamps, timestamp)
for t in self.obj_timestamps[:obj_to_release]:
Expand Down Expand Up @@ -216,6 +220,8 @@ def compute_prediction(self, timestamp, vid_size):

prediction = output[0]

self.pred_pos += 1

return prediction

class AVAPredictorWorker(object):
Expand Down

0 comments on commit 99acc16

Please sign in to comment.