Skip to content

Commit

Permalink
Graceful failing with seeking errors (#1712)
Browse files Browse the repository at this point in the history
* Don't try to seek to faulty last frame on provider initialization

* Catch seeking errors and pass

* Lint
  • Loading branch information
talmo authored Mar 17, 2024
1 parent 5fa1079 commit bab9b1b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
4 changes: 1 addition & 3 deletions sleap/nn/data/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ def make_dataset(self) -> tf.data.Dataset:
grid in order to properly map points to image coordinates.
"""
# Grab an image to test for the dtype.
test_image = tf.convert_to_tensor(
self.video.get_frame(self.video.last_frame_idx)
)
test_image = tf.convert_to_tensor(self.video.get_frame(0))
image_dtype = test_image.dtype

def py_fetch_frame(ind):
Expand Down
54 changes: 54 additions & 0 deletions sleap/nn/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,15 @@ def _object_builder():
try:
for ex in generator:
prediction_queue.put(ex)

except KeyError as e:
# Gracefully handle seeking errors by early termination.
if "Unable to load frame" in str(e):
pass # TODO: Print warning obeying verbosity? (This code path is also
# called for interactive prediction where we don't want any spam.)
else:
raise

finally:
prediction_queue.put(None)
object_builder.join()
Expand Down Expand Up @@ -2632,6 +2641,15 @@ def _object_builder():
try:
for ex in generator:
prediction_queue.put(ex)

except KeyError as e:
# Gracefully handle seeking errors by early termination.
if "Unable to load frame" in str(e):
pass # TODO: Print warning obeying verbosity? (This code path is also
# called for interactive prediction where we don't want any spam.)
else:
raise

finally:
prediction_queue.put(None)
object_builder.join()
Expand Down Expand Up @@ -3265,6 +3283,15 @@ def _object_builder():
try:
for ex in generator:
prediction_queue.put(ex)

except KeyError as e:
# Gracefully handle seeking errors by early termination.
if "Unable to load frame" in str(e):
pass # TODO: Print warning obeying verbosity? (This code path is also
# called for interactive prediction where we don't want any spam.)
else:
raise

finally:
prediction_queue.put(None)
object_builder.join()
Expand Down Expand Up @@ -3770,6 +3797,15 @@ def _object_builder():
try:
for ex in generator:
prediction_queue.put(ex)

except KeyError as e:
# Gracefully handle seeking errors by early termination.
if "Unable to load frame" in str(e):
pass # TODO: Print warning obeying verbosity? (This code path is also
# called for interactive prediction where we don't want any spam.)
else:
raise

finally:
prediction_queue.put(None)
object_builder.join()
Expand Down Expand Up @@ -4457,6 +4493,15 @@ def _object_builder():
try:
for ex in generator:
prediction_queue.put(ex)

except KeyError as e:
# Gracefully handle seeking errors by early termination.
if "Unable to load frame" in str(e):
pass # TODO: Print warning obeying verbosity? (This code path is also
# called for interactive prediction where we don't want any spam.)
else:
raise

finally:
prediction_queue.put(None)
object_builder.join()
Expand Down Expand Up @@ -4734,6 +4779,15 @@ def _object_builder():
try:
for ex in generator:
prediction_queue.put(ex)

except KeyError as e:
# Gracefully handle seeking errors by early termination.
if "Unable to load frame" in str(e):
pass # TODO: Print warning obeying verbosity? (This code path is also
# called for interactive prediction where we don't want any spam.)
else:
raise

finally:
prediction_queue.put(None)
object_builder.join()
Expand Down

0 comments on commit bab9b1b

Please sign in to comment.