-
Notifications
You must be signed in to change notification settings - Fork 3.1k
examples/time_in_zone: improve CLI argument handling #2057
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request refactors CLI argument handling across six example scripts in the examples/time_in_zone directory. The main changes aim to replace argparse with a dual-mode approach using jsonargparse (when available) or falling back to positional sys.argv arguments. Function signatures are updated with default values and comprehensive docstrings, and the Ultralytics model inference logic is improved to pass the iou parameter directly to the model call.
Key Changes:
- Replaced argparse with a try-except pattern that attempts to use jsonargparse and falls back to parsing sys.argv positionally
- Added default values and docstrings to all main functions for better documentation
- Updated Ultralytics model calls to use the
iouparameter directly instead of applying NMS separately
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| ultralytics_stream_example.py | Refactored CLI parsing to use jsonargparse/sys.argv fallback; updated YOLO model call to pass iou directly; removed redundant NMS call |
| ultralytics_naive_stream_example.py | Refactored CLI parsing to use jsonargparse/sys.argv fallback; updated YOLO model call to pass iou directly; removed redundant NMS call |
| ultralytics_file_example.py | Refactored CLI parsing to use jsonargparse/sys.argv fallback; updated YOLO model call to pass iou directly; removed redundant NMS call |
| inference_stream_example.py | Refactored CLI parsing to use jsonargparse/sys.argv fallback; added docstrings and default values to main function |
| inference_naive_stream_example.py | Refactored CLI parsing to use jsonargparse/sys.argv fallback; added docstrings and default values to main function |
| inference_file_example.py | Refactored CLI parsing to use jsonargparse/sys.argv fallback; added docstrings and default values to main function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2057 +/- ##
=======================================
Coverage 52% 52%
=======================================
Files 61 61
Lines 7077 7076 -1
=======================================
Hits 3657 3657
+ Misses 3420 3419 -1 🚀 New features to boost your workflow:
|
This pull request refactors the command-line interface (CLI) and argument handling for all example scripts in the
examples/time_in_zonedirectory. The main goals are to improve flexibility in how arguments are parsed, provide better documentation for function arguments, and simplify the code. The scripts now support both advanced CLI parsing withjsonargparse(if available) and a fallback to positional arguments. Additionally, default values and docstrings have been added to the main functions for clarity. Some minor logic improvements are also included for consistency in model inference.Key changes include:
CLI and Argument Parsing Improvements
Replaced
argparsewith a dual approach: scripts now attempt to usejsonargparsefor advanced CLI parsing, and fall back to parsing positional arguments fromsys.argvifjsonargparseis not installed. This makes the scripts more flexible and user-friendly. [1] [2] [3] [4] [5]Updated import statements to use
sysinstead ofargparseat the top of each script, reflecting the new argument parsing approach. [1] [2] [3] [4] [5] [6]Function Signature and Documentation Enhancements
mainfunction signatures to provide default values for optional arguments and added comprehensive docstrings describing each argument and the function's purpose. This improves code readability and helps users understand how to use each script. [1] [2] [3] [4] [5]Model Inference Logic Consistency
iouthreshold directly to the model call (instead of applying non-max suppression separately), ensuring consistent and correct use of inference parameters. [1] [2]These changes make the example scripts more robust, easier to use, and better documented for both beginners and advanced users.
Part of #2090