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

Handled Zero Division Error in pipeline.py #344

Merged
merged 4 commits into from
Jul 10, 2024
Merged

Conversation

karthikbolla
Copy link
Contributor

This pull request addresses a division by zero error in the _get_fps() function. I've implemented a check to handle the case where total_time_s is zero to prevent the error. Additionally, I've modified the calculation of avg_ms to ensure it doesn't result in a division by zero.

Changes Made:

  • Added a conditional check in _get_fps() to handle division by zero.
  • Adjusted the calculation of avg_ms to prevent division by zero.

Fixes: #343

@benemer
Copy link
Member

benemer commented May 19, 2024

Thanks for the fix! Two cosmetic suggestions from my side, just to keep things compact.

@karthikbolla karthikbolla requested a review from benemer May 20, 2024 04:20
@nachovizzo
Copy link
Collaborator

Thanks for the fix, it is definetly helpful.

The bigger question here would be, though, how you end up with a 0.000 runtime. You might have a problem somewhere else. I agree that is not the right place to explode, but something else went wrong here

@benemer
Copy link
Member

benemer commented Jun 24, 2024

Is this PR still active? We should discuss which runtime should be reported if the total time is zero. I have two proposals:

  1. Make it NaN, this also occurs sometimes for the relative error
  2. Do not show it in the final logs

What do you think?

@karthikbolla
Copy link
Contributor Author

Is this PR still active? We should discuss which runtime should be reported if the total time is zero. I have two proposals:

  1. Make it NaN, this also occurs sometimes for the relative error
  2. Do not show it in the final logs

What do you think?

Is there any other way than returning 0?

@benemer
Copy link
Member

benemer commented Jul 10, 2024

How about

diff --git a/python/kiss_icp/pipeline.py b/python/kiss_icp/pipeline.py
index 52cb7a7..46b9d4d 100644
--- a/python/kiss_icp/pipeline.py
+++ b/python/kiss_icp/pipeline.py
@@ -184,9 +184,10 @@ class OdometryPipeline:
         fps = _get_fps()
         avg_fps = int(np.floor(fps))
         avg_ms = int(np.ceil(1e3 / fps)) if fps > 0 else 0
-        self.results.append(desc="Average Frequency", units="Hz", value=avg_fps, trunc=True)
-        self.results.append(desc="Average Runtime", units="ms", value=avg_ms, trunc=True)
 
+        if avg_fps > 0:
+            self.results.append(desc="Average Frequency", units="Hz", value=avg_fps, trunc=True)
+            self.results.append(desc="Average Runtime", units="ms", value=avg_ms, trunc=True)
 
     def _write_log(self):
         if not self.results.empty():

Wit this, we don't have think about what the correct return value would be.

@nachovizzo
Copy link
Collaborator

@karthikbolla would you please do as @benemer suggested? you can also give us access to commit there so we also ack your contribution

thanks

updated pipeline.py based on @benemer  suggestions where the results are only appended when avg fps is greater than zero
@karthikbolla
Copy link
Contributor Author

@nachovizzo @benemer I've raised a new commit based on @benemer's suggestions and also granted access to the fork.

Thank you.

benemer
benemer previously approved these changes Jul 10, 2024
Copy link
Member

@benemer benemer left a comment

Choose a reason for hiding this comment

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

Great, thank you for your contribution!

@tizianoGuadagnino tizianoGuadagnino dismissed stale reviews from benemer and themself via 452e98a July 10, 2024 11:27
@nachovizzo nachovizzo merged commit 5d42087 into PRBonn:main Jul 10, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ZeroDivisionError in pipeline.py in ‎OdometryPipeline._get_fps function
4 participants