From 6b8059e76dec6ffb92d9a79a157919785cddc4ca Mon Sep 17 00:00:00 2001 From: Talmo Pereira Date: Sat, 16 Mar 2024 18:12:37 -0700 Subject: [PATCH 1/3] Don't try to seek to faulty last frame on provider initialization --- sleap/nn/data/providers.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sleap/nn/data/providers.py b/sleap/nn/data/providers.py index 16f439d10..9e93d0b18 100644 --- a/sleap/nn/data/providers.py +++ b/sleap/nn/data/providers.py @@ -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): From 330d5cdfdb378c75825db61f4319a8e3668b273c Mon Sep 17 00:00:00 2001 From: Talmo Pereira Date: Sat, 16 Mar 2024 18:13:01 -0700 Subject: [PATCH 2/3] Catch seeking errors and pass --- sleap/nn/inference.py | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/sleap/nn/inference.py b/sleap/nn/inference.py index 0cabc91bb..fd107fd8b 100644 --- a/sleap/nn/inference.py +++ b/sleap/nn/inference.py @@ -1582,6 +1582,16 @@ 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() @@ -2632,6 +2642,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() @@ -3265,6 +3284,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() @@ -3770,6 +3798,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() @@ -4457,6 +4494,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() @@ -4734,6 +4780,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() From 59d105fdc9d5b9cc9f49604ce45fc0707e7d3a7f Mon Sep 17 00:00:00 2001 From: Talmo Pereira Date: Sat, 16 Mar 2024 18:43:10 -0700 Subject: [PATCH 3/3] Lint --- sleap/nn/inference.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sleap/nn/inference.py b/sleap/nn/inference.py index fd107fd8b..97a550923 100644 --- a/sleap/nn/inference.py +++ b/sleap/nn/inference.py @@ -1587,11 +1587,10 @@ def _object_builder(): # 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.) + # called for interactive prediction where we don't want any spam.) else: raise - finally: prediction_queue.put(None) object_builder.join() @@ -2642,15 +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.) + # called for interactive prediction where we don't want any spam.) else: raise - + finally: prediction_queue.put(None) object_builder.join() @@ -3289,7 +3288,7 @@ def _object_builder(): # 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.) + # called for interactive prediction where we don't want any spam.) else: raise @@ -3803,7 +3802,7 @@ def _object_builder(): # 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.) + # called for interactive prediction where we don't want any spam.) else: raise @@ -4499,7 +4498,7 @@ def _object_builder(): # 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.) + # called for interactive prediction where we don't want any spam.) else: raise @@ -4785,7 +4784,7 @@ def _object_builder(): # 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.) + # called for interactive prediction where we don't want any spam.) else: raise