Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graceful failing with seeking errors #1712

Merged
merged 3 commits into from
Mar 17, 2024
Merged
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
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))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 0 as the argument for self.video.get_frame to fetch a test image is a straightforward approach to avoid seeking errors. However, it would be beneficial to add a comment explaining this choice for future maintainability.

+ # Fetching the first frame (index 0) to avoid seeking errors, especially towards the end of the video.
  test_image = tf.convert_to_tensor(self.video.get_frame(0))

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
test_image = tf.convert_to_tensor(self.video.get_frame(0))
# Fetching the first frame (index 0) to avoid seeking errors, especially towards the end of the video.
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
Loading