Have statistics functions return a meaningful, non-none result even if only one value is available
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:
- [ ] Documentation added/updated for www.home-assistant.io
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 runningpython3 -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:
- [ ] I have reviewed two other open pull requests in this repository.
👋 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:
- Notebooks with free GPU support: Paperspace, Colab, Kaggle
- Google Cloud Deep Learning VM. See GCP Quickstart Guide
- Amazon Deep Learning AMI. See AWS Quickstart Guide
- Docker Image. See Docker Quickstart Guide Docker Hub
Status
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.
I can't reproduce this in the latest version. Please update your ultralytics.
I can't reproduce this in the latest version. Please update your ultralytics.
Thanks for your reply. The latest version is fine.
Great to hear it's working now! If you have any more questions, feel free to ask.
Another question:
There are extra parts at the edge of the mask in YOLO11-seg predict.
In my own inference code, it is fine.
In YOLOv8-seg predict, it is also fine.
I think YOLO11-seg predict script has some difference for mask processing.
You can try passing retina_masks=True
You can try passing
retina_masks=True
It works, Thank you so much!
I need optimize my inference code, How can I implement retina_masks in my code.
@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).
@panp4n you're welcome! To implement
retina_masksin 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.
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
The code used by
retina_masksis herehttps://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.
You're welcome! If you have any more questions, feel free to ask.
The code used by
retina_masksis herehttps://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
The same model, why the mask of official predict script is better than deployment code? Do you have any recommendations?
The official script uses retina_masks=True for smoother edges. Ensure your deployment code applies similar post-processing techniques.
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
👋 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 ⭐