Skip to content
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

Ultralytics Code Refactor https://ultralytics.com/actions #2250

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def run(
None

Notes:
This function iterates over multiple export formats, performs the export, and then validates the model's
performance using appropriate validation functions for detection and segmentation models. The results are logged,
and optionally, benchmarks can be configured to raise errors on failures using the `hard_fail` argument.
This function iterates over multiple export formats, performs the export, and then validates the model's performance
using appropriate validation functions for detection and segmentation models. The results are logged, and optionally,
benchmarks can be configured to raise errors on failures using the `hard_fail` argument.

Examples:
```python
Expand Down Expand Up @@ -173,7 +173,7 @@ def test(
hard_fail (bool): Raise an error on benchmark failure. Defaults to False.

Returns:
pd.DataFrame: A DataFrame containing the export formats and their success status. (pd.DataFrame)
pd.DataFrame: A DataFrame containing the export formats and their success status.

Examples:
```python
Expand Down Expand Up @@ -223,7 +223,7 @@ def test(

def parse_opt():
"""
Parses command line arguments for YOLOv3 inference and export configuration.
Parses command line arguments for YOLOv3 inference and export configurations.

Args:
--weights (str): Path to the weights file. Default is 'ROOT / "yolov3-tiny.pt"'.
Expand All @@ -233,10 +233,10 @@ def parse_opt():
--device (str): CUDA device identifier, e.g., '0' for single GPU, '0,1,2,3' for multiple GPUs, or 'cpu' for CPU
inference. Default is "".
--half (bool): If set, use FP16 half-precision inference. Default is False.
--test (bool): If set, only test exports without running inference. Default is False.
--test (bool): If set, test only exports without running inference. Default is False.
--pt-only (bool): If set, test only the PyTorch model without exporting to other formats. Default is False.
--hard-fail (str | bool): If set, raise an exception on benchmark failure. Can also be a string representing
the minimum metric floor for success. Default is False.
--hard-fail (str | bool): If set, raise an exception on benchmark failure. Can also be a string representing the
minimum metric floor for success. Default is False.

Returns:
argparse.Namespace: The parsed arguments as a namespace object.
Expand Down
64 changes: 33 additions & 31 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def run(
vid_stride=1, # video frame-rate stride
):
"""
Performs YOLOv3 detection on various input sources including images, videos, streams, and YouTube URLs.
Run YOLOv3 detection inference on various input sources such as images, videos, YouTube URLs, and streams.

Args:
weights (str | Path): Path to the model weights file or a Triton URL (default: 'yolov5s.pt').
Expand Down Expand Up @@ -290,33 +290,34 @@ def parse_opt():
Parses and returns command-line options for model inference configurations.

Args:
--weights (list[str]): Model path or triton URL. Default: `ROOT / "yolov3-tiny.pt"`.
--source (str): File/directory/URL/glob/screen/0(webcam) for input data. Default: `ROOT / "data/images"`.
--data (str): (Optional) Path to dataset.yaml. Default: `ROOT / "data/coco128.yaml"`.
--imgsz (list[int]): Inference size as height, width. Accepts multiple values. Default: `[640]`.
--conf-thres (float): Confidence threshold for predictions. Default: `0.25`.
--iou-thres (float): IoU threshold for Non-Maximum Suppression (NMS). Default: `0.45`.
--max-det (int): Maximum number of detections per image. Default: `1000`.
--device (str): CUDA device to run the model on, e.g., `0` or `0,1,2,3` or `cpu`. Default: `""`.
--view-img (bool): Display results on the screen. Default: `False`.
--save-txt (bool): Save results to text files. Default: `False`.
--save-conf (bool): Save confidence scores in text labels. Default: `False`.
--save-crop (bool): Save cropped prediction boxes. Default: `False`.
--nosave (bool): Do not save images/videos. Default: `False`.
--classes (list[int]): Filter results by class, e.g., `--classes 0` or `--classes 0 2 3`. Default: `None`.
--agnostic-nms (bool): Perform class-agnostic NMS. Default: `False`.
--augment (bool): Perform augmented inference. Default: `False`.
--visualize (bool): Visualize features. Default: `False`.
--update (bool): Update all models. Default: `False`.
--project (str): Directory to save results, saved as "project/name". Default: `ROOT / "runs/detect"`.
--name (str): Directory name for saving results, e.g., "exp" in "project/name". Default: `"exp"`.
--exist-ok (bool): Allow results to be saved in an existing directory without incrementing. Default: `False`.
--line-thickness (int): Thickness of bounding box lines (in pixels). Default: `3`.
--hide-labels (bool): Hide labels on detected objects. Default: `False`.
--hide-conf (bool): Hide confidence scores on labels. Default: `False`.
--half (bool): Use FP16 half-precision inference. Default: `False`.
--dnn (bool): Use OpenCV DNN backend for ONNX inference. Default: `False`.
--vid-stride (int): Frame-rate stride for video input. Default: `1`.
--weights (list[str]): Model path or Triton URL. Default: 'ROOT / "yolov3-tiny.pt"'.
--source (str | Path): Source of input data such as file, directory, URL, glob pattern, or device identifier
(default: 'ROOT / "data/images"').
--data (str | Path): Optional path to dataset.yaml. Default: 'ROOT / "data/coco128.yaml"'.
--imgsz (list[int]): Inference size as height and width. Accepts multiple values. Default: [640].
--conf-thres (float): Confidence threshold for predictions. Default: 0.25.
--iou-thres (float): IoU threshold for Non-Maximum Suppression (NMS). Default: 0.45.
--max-det (int): Maximum number of detections per image. Default: 1000.
--device (str): CUDA device to run the model on, e.g., '0', '0,1,2,3', or 'cpu'. Default: ''.
--view-img (bool): Display results on the screen. Default: False.
--save-txt (bool): Save results to text files. Default: False.
--save-conf (bool): Save confidence scores in text labels. Default: False.
--save-crop (bool): Save cropped prediction boxes. Default: False.
--nosave (bool): Prevent saving images/videos. Default: False.
--classes (list[int] | None): Filter results by class, e.g., [0], or [0, 2, 3]. Default: None.
--agnostic-nms (bool): Perform class-agnostic Non-Maximum Suppression (NMS). Default: False.
--augment (bool): Apply augmented inference. Default: False.
--visualize (bool): Visualize features. Default: False.
--update (bool): Update all models. Default: False.
--project (str | Path): Directory to save results, in the format 'project/name'. Default: 'ROOT / "runs/detect"'.
--name (str): Directory name for saving results, e.g., 'exp' in 'project/name'. Default: 'exp'.
--exist-ok (bool): Allow existing project/name directory without incrementing. Default: False.
--line-thickness (int): Thickness of bounding box lines in pixels. Default: 3.
--hide-labels (bool): Hide labels in detected objects. Default: False.
--hide-conf (bool): Hide confidence scores in labels. Default: False.
--half (bool): Use FP16 half-precision inference. Default: False.
--dnn (bool): Use OpenCV DNN backend for ONNX inference. Default: False.
--vid-stride (int): Frame-rate stride for video input. Default: 1.

Returns:
argparse.Namespace: Parsed command-line arguments for inference configurations.
Expand Down Expand Up @@ -359,7 +360,7 @@ def parse_opt():

def main(opt):
"""
Entry point for running the model; checks requirements and calls `run` with parsed options.
Entry point for running the YOLO model; checks requirements and calls `run` with parsed options.

Args:
opt (argparse.Namespace): Parsed command-line options, which include:
Expand Down Expand Up @@ -400,9 +401,10 @@ def main(opt):
opt = parse_opt()
main(opt)
```

Notes:
Run this function as the entry point for using YOLOv3 for object detection on a variety of input sources such
as images, videos, directories, webcams, streams, etc. This function ensures all requirements are checked and
Run this function as the entry point for using YOLO for object detection on a variety of input sources such as
images, videos, directories, webcams, streams, etc. This function ensures all requirements are checked and
subsequently initiates the detection process by calling the `run` function with appropriate options.
"""
check_requirements(ROOT / "requirements.txt", exclude=("tensorboard", "thop"))
Expand Down
Loading
Loading