-
Notifications
You must be signed in to change notification settings - Fork 3.1k
refactor(speed_estimation): improve CLI argument parsing #2056
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 the CLI argument parsing for three speed estimation example scripts, replacing argparse with a hybrid approach that uses jsonargparse when available and falls back to positional argument parsing otherwise. The main logic in each script has been encapsulated into a main() function with explicit parameters for better code organization and reusability.
Key Changes:
- Introduced a flexible CLI parsing mechanism that tries
jsonargparsefirst and falls back to manual positional argument parsing - Encapsulated script logic into
main()functions with explicit parameter definitions and docstrings - Streamlined detection filtering by passing confidence and IoU thresholds directly to model inference methods instead of post-processing
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| examples/speed_estimation/yolo_nas_example.py | Refactored CLI parsing, encapsulated main logic, and updated YOLO-NAS model inference to pass thresholds as parameters |
| examples/speed_estimation/ultralytics_example.py | Refactored CLI parsing, encapsulated main logic, and streamlined Ultralytics model inference with threshold parameters |
| examples/speed_estimation/inference_example.py | Refactored CLI parsing, encapsulated main logic with additional Roboflow parameters, and updated inference API calls with thresholds |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
This pull request refactors the command-line interface (CLI) logic for all three speed estimation example scripts (
inference_example.py,ultralytics_example.py, andyolo_nas_example.py) to improve usability and maintainability. The main changes involve replacing the previousargparse-based CLI with a new approach that usesjsonargparsewhen available, and falls back to parsing positional arguments otherwise. Additionally, the main logic in each script is now encapsulated in amainfunction with explicit arguments, and argument passing throughout the code is updated for clarity and consistency.CLI refactoring and usability improvements:
Replaced the
argparse-based CLI in all three example scripts with logic that tries to usejsonargparsefor automatic CLI argument parsing, and falls back to manual positional argument parsing ifjsonargparseis not installed. This makes the scripts more flexible and easier to use from the command line. [1] [2] [3] [4] [5] [6]Encapsulated the main script logic in a
mainfunction with explicit parameters in each file, improving code readability and enabling easier reuse and testing. [1] [2] [3]Argument handling and code consistency:
Updated all usages of CLI arguments throughout the scripts to reference the new function parameters instead of the previous
argsobject, ensuring consistency and correctness. [1] [2] [3]Improved handling of optional arguments and default values for model configuration, API keys, and thresholds, making it clearer and more robust for users to provide or omit arguments. [1] [2] [3] [4] [5] [6]
Minor import adjustments:
argparseimports and addedsysimports in all three scripts, reflecting the change in argument parsing approach. [1] [2] [3]