Skip to content

Conversation

@Borda
Copy link
Member

@Borda Borda commented Jan 7, 2026

This pull request refactors the command-line interface (CLI) and argument handling for all example scripts in the examples/time_in_zone directory. 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 with jsonargparse (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 argparse with a dual approach: scripts now attempt to use jsonargparse for advanced CLI parsing, and fall back to parsing positional arguments from sys.argv if jsonargparse is not installed. This makes the scripts more flexible and user-friendly. [1] [2] [3] [4] [5]

  • Updated import statements to use sys instead of argparse at the top of each script, reflecting the new argument parsing approach. [1] [2] [3] [4] [5] [6]

Function Signature and Documentation Enhancements

  • Modified all main function 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

  • Updated Ultralytics-based scripts to pass the iou threshold 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

Copilot AI review requested due to automatic review settings January 7, 2026 20:30
@Borda Borda requested a review from SkalskiP as a code owner January 7, 2026 20:30
Copy link
Contributor

Copilot AI left a 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 iou parameter 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
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52%. Comparing base (8df7aea) to head (33f0388).
⚠️ Report is 6 commits behind head on develop.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda changed the title refactor(time_in_zone): improve CLI argument handling example(time_in_zone): improve CLI argument handling Jan 12, 2026
@Borda Borda changed the title example(time_in_zone): improve CLI argument handling examples/time_in_zone: improve CLI argument handling Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants