Skip to content

Conversation

john-rocky
Copy link
Contributor

@john-rocky john-rocky commented Aug 6, 2025

  • Add setNumItemsThreshold, setConfidenceThreshold, setIouThreshold methods
  • Add getter methods for current threshold values
  • Add setThresholds method for batch configuration
  • Update README.md with threshold configuration documentation
  • Fix How to set numItemsThreshold #149: Enable programmatic threshold configuration

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Adds easy, programmatic control of detection thresholds across the iOS SDK, simplifies predictor loading, and streamlines visualization capture — with minor performance and code quality improvements. 🚀

📊 Key Changes

  • Object detection loop optimized to iterate up to min(results.count, numItemsThreshold) for cleaner, faster processing.
  • New public threshold APIs in YOLO:
    • setNumItemsThreshold, setConfidenceThreshold, setIouThreshold, plus setThresholds(...) and corresponding getters.
  • YOLOView gains matching threshold setters/getters that sync UI sliders and predictor values.
  • README expanded with “Threshold Configuration” section and usage examples for YOLO and YOLOView/YOLOCamera.
  • Predictor loading in YOLO.swift refactored to a single completion handler for all tasks (detect/segment/pose/OBB/classify).
  • YOLOCamera model path resolution simplified; uses an assert (debug-only) instead of fatalError.
  • Visualization capture unified: replaces multiple copy helpers with copyVisualizationLayer(...) for masks, poses, and OBB overlays.

🎯 Purpose & Impact

  • Easier tuning: Developers can now adjust max detections, confidence, and IoU thresholds at runtime or via UI controls for faster iteration and better results. 🎛️
  • Cleaner API: Consistent threshold methods across YOLO and YOLOView reduce boilerplate and potential errors.
  • Better performance and readability: Simplified loops and unified handlers reduce branching and duplication.
  • More robust capture: Unified visualization copying improves reliability when saving annotated photos across tasks. 📸
  • Safer setup in debug: Using assert avoids hard crashes during development if model paths are missing.

- Add setNumItemsThreshold, setConfidenceThreshold, setIouThreshold methods
- Add getter methods for current threshold values
- Add setThresholds method for batch configuration
- Update README.md with threshold configuration documentation
- Resolves issue #149: Enable programmatic threshold configuration
@john-rocky john-rocky requested a review from asabri97 August 6, 2025 09:52
@UltralyticsAssistant UltralyticsAssistant added detect Object Detection issues, PR's documentation Improvements or additions to documentation enhancement New feature or request labels Aug 6, 2025
@UltralyticsAssistant
Copy link
Member

👋 Hello @john-rocky, thank you for submitting a ultralytics/yolo-ios-app 🚀 PR! This is an automated response to help streamline our review process. An Ultralytics engineer will also review and assist you soon.

Please review the following checklist to ensure your contribution is ready for integration:

  • Define a Purpose: Make sure your PR description clearly explains the purpose of your changes and links to any relevant issues. Clear and concise commit messages are appreciated!
  • Synchronize with Source: Confirm your branch is up-to-date with the main branch of ultralytics/yolo-ios-app. If not, update by clicking the 'Update branch' button or running git pull and git merge main locally.
  • Ensure CI Checks Pass: Double-check that all Ultralytics Continuous Integration (CI) checks complete successfully. Address any failures as needed.
  • Update Documentation: Ensure relevant documentation is updated for your new or modified features.
  • Add Tests: If your changes add or modify functionality, please include or update tests and confirm they pass.
  • Sign the CLA: If this is your first Ultralytics PR, please sign our Contributor License Agreement (CLA) by commenting: "I have read the CLA Document and I sign the CLA".
  • Minimize Changes: Keep your changes focused to the minimum necessary for your fix or feature. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more info, check out our Contributing Guide.

Thank you again for contributing to Ultralytics! Your improvements for threshold configuration in the iOS app will help empower the community. 🚀🎉

Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 0% with 138 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
Sources/YOLO/YOLOView.swift 0.00% 58 Missing ⚠️
Sources/YOLO/YOLO.swift 0.00% 45 Missing ⚠️
Sources/YOLO/ObjectDetector.swift 0.00% 32 Missing ⚠️
Sources/YOLO/YOLOCamera.swift 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@emresa37 emresa37 left a comment

Choose a reason for hiding this comment

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

@john-rocky It looks great. Thanks for the real quick action.

It's also limited at ObjectDetector class to 100.
If you can check the line number 67 and 128. For loops should be like this:
for i in 0..<results.count

glenn-jocher and others added 10 commits August 7, 2025 17:49
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
- Simplified loadModel method by using a single handleResult closure
- Fixed type signature to use BasePredictor instead of Predictor protocol
- Reduced code duplication in task-specific predictor creation
- Maintained full functionality while improving code readability
- Simplified getter methods to single-line returns in YOLOView
- Used range containment check (0.0...1.0).contains() for validation
- Maintained all functionality while reducing code verbosity
@john-rocky
Copy link
Contributor Author

@glenn-jocher
I simplified the code a bit.

john-rocky and others added 2 commits August 11, 2025 15:37
…d limit

- Changed 'for i in 0..<100' to 'for i in 0..<min(results.count, self.numItemsThreshold)'
- Removed unnecessary nested conditions since min() handles the comparison
- More efficient loop that only iterates over actual results
- Addresses code review feedback from @emresa37
@john-rocky
Copy link
Contributor Author

@john-rocky It looks great. Thanks for the real quick action.

It's also limited at ObjectDetector class to 100. If you can check the line number 67 and 128. For loops should be like this: for i in 0..<results.count

@emresa37 Fixed.

@john-rocky john-rocky requested a review from asabri97 August 26, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

detect Object Detection issues, PR's documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to set numItemsThreshold

5 participants