core icon indicating copy to clipboard operation
core copied to clipboard

Have statistics functions return a meaningful, non-none result even if only one value is available

Open unfug-at-github opened this issue 1 year ago • 16 comments

Have statistics functions return a meaningful, non-none result even if only one value is available

Breaking change

Proposed change

Currently many of the statistics function return none when only one value is available, however, a meaningful value exists (e.g. the average of { 17.5 } is 17.5). This change will return a value for all of those cases. None will still be returned in cases where no value is available.

Type of change

  • [ ] Dependency upgrade
  • [x] Bugfix (non-breaking change which fixes an issue)
  • [ ] New integration (thank you!)
  • [ ] New feature (which adds functionality to an existing integration)
  • [ ] Deprecation (breaking change to happen in the future)
  • [ ] Breaking change (fix/feature causing existing functionality to break)
  • [ ] Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • [x] The code change is tested and works locally.
  • [x] Local tests pass. Your PR cannot be merged unless tests pass
  • [x] There is no commented out code in this PR.
  • [x] I have followed the development checklist
  • [x] I have followed the perfect PR recommendations
  • [x] The code has been formatted using Ruff (ruff format homeassistant tests)
  • [x] Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • [ ] The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • [ ] New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

unfug-at-github avatar Oct 02 '24 13:10 unfug-at-github

👋 Hello @panp4n, thank you for your interest in Ultralytics 🚀!

We recommend checking out our Docs where you can find many Python and CLI examples. They might have answers to common questions.

For your 🐛 Bug Report, please provide a minimum reproducible example to help us debug the issue you're experiencing with YOLO11-seg.

If you have custom training ❓ Questions, please give more details, such as dataset image examples and training logs. Also, ensure you're following our Tips for Best Training Results.

Consider joining our community! For real-time chat, visit Discord 🎧. Prefer discussions? Head over to Discourse, or check out our Subreddit.

Upgrade

Make sure you're using the latest version by upgrading the ultralytics package along with all requirements in a Python>=3.8 environment with PyTorch>=1.8:

pip install -U ultralytics

Environments

YOLO runs well in various environments with dependencies like CUDA/CUDNN:

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are passing, which confirms proper operation across different systems.

This is an automated response; an Ultralytics engineer will assist you soon.

UltralyticsAssistant avatar Oct 08 '24 02:10 UltralyticsAssistant

I can't reproduce this in the latest version. Please update your ultralytics.

Y-T-G avatar Oct 08 '24 09:10 Y-T-G

I can't reproduce this in the latest version. Please update your ultralytics.

Thanks for your reply. The latest version is fine.

panp4n avatar Oct 08 '24 09:10 panp4n

Great to hear it's working now! If you have any more questions, feel free to ask.

glenn-jocher avatar Oct 08 '24 15:10 glenn-jocher

Another question: There are extra parts at the edge of the mask in YOLO11-seg predict. image

In my own inference code, it is fine. image

In YOLOv8-seg predict, it is also fine. image I think YOLO11-seg predict script has some difference for mask processing.

panp4n avatar Oct 09 '24 01:10 panp4n

You can try passing retina_masks=True

Y-T-G avatar Oct 09 '24 04:10 Y-T-G

You can try passing retina_masks=True

It works, Thank you so much! image

I need optimize my inference code, How can I implement retina_masks in my code.

panp4n avatar Oct 09 '24 06:10 panp4n

@panp4n you're welcome! To implement retina_masks in your code, you can set the parameter when calling the model's predict function, like this: model.predict(source, retina_masks=True).

glenn-jocher avatar Oct 09 '24 07:10 glenn-jocher

@panp4n you're welcome! To implement retina_masks in your code, you can set the parameter when calling the model's predict function, like this: model.predict(source, retina_masks=True).

I knew that, I want to know how to implement mask post-process like retina_masks in the onnxruntime or openvino inference. As you can see, the edge of this mask is rough. image

panp4n avatar Oct 09 '24 08:10 panp4n

The code used by retina_masks is here

https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/ultralytics/utils/ops.py#L689

https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/ultralytics/models/yolo/segment/predict.py#L49-L50

Y-T-G avatar Oct 09 '24 08:10 Y-T-G

The code used by retina_masks is here

https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/ultralytics/utils/ops.py#L689

https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/ultralytics/models/yolo/segment/predict.py#L49-L50

Thank you! This helps me a lot.

panp4n avatar Oct 09 '24 08:10 panp4n

You're welcome! If you have any more questions, feel free to ask.

glenn-jocher avatar Oct 09 '24 16:10 glenn-jocher

The code used by retina_masks is here

https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/ultralytics/utils/ops.py#L689

https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/ultralytics/models/yolo/segment/predict.py#L49-L50

https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/ultralytics/utils/ops.py#L729 I can't reproduce this align_corners=False by using OpenCV C++ api . The example also uses cv2.resize(), My code is similar to this. There is still a gap in effectiveness. https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py#L256-L258

panp4n avatar Oct 10 '24 01:10 panp4n

The same model, why the mask of official predict script is better than deployment code? Do you have any recommendations?

panp4n avatar Oct 10 '24 02:10 panp4n

The official script uses retina_masks=True for smoother edges. Ensure your deployment code applies similar post-processing techniques.

glenn-jocher avatar Oct 10 '24 12:10 glenn-jocher

Use the mask for drawing, instead of segments. And don't apply a large confidence threshold like in the example. Use 0.0.

https://github.com/ultralytics/ultralytics/blob/8154a27e9b332dd2dac7a107003462f0e20f6179/examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py#L227

Y-T-G avatar Oct 10 '24 22:10 Y-T-G

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

  • Docs: https://docs.ultralytics.com
  • HUB: https://hub.ultralytics.com
  • Community: https://community.ultralytics.com

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

github-actions[bot] avatar Nov 21 '24 00:11 github-actions[bot]