Skip to content

Commit b61ab4e

Browse files
Update Google-style docstrings (#2359)
* Update Google-style docstrings Signed-off-by: Glenn Jocher <[email protected]> * Auto-format by https://ultralytics.com/actions * Auto-format by https://ultralytics.com/actions --------- Signed-off-by: Glenn Jocher <[email protected]> Co-authored-by: UltralyticsAssistant <[email protected]>
1 parent 2dac637 commit b61ab4e

32 files changed

+449
-625
lines changed

benchmarks.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def run(
6060
pt_only=False, # test PyTorch only
6161
hard_fail=False, # throw error on benchmark failure
6262
):
63-
"""
64-
Run YOLOv3 benchmarks on multiple export formats and validate performance metrics.
63+
"""Run YOLOv3 benchmarks on multiple export formats and validate performance metrics.
6564
6665
Args:
6766
weights (str | Path): Path to the weights file. Defaults to 'yolov5s.pt'.
@@ -77,11 +76,6 @@ def run(
7776
Returns:
7877
None
7978
80-
Notes:
81-
This function iterates over multiple export formats, performs the export, and then validates the model's performance
82-
using appropriate validation functions for detection and segmentation models. The results are logged, and optionally,
83-
benchmarks can be configured to raise errors on failures using the `hard_fail` argument.
84-
8579
Examples:
8680
```python
8781
# Run benchmarks on the default 'yolov5s.pt' model with an image size of 640 pixels
@@ -93,6 +87,11 @@ def run(
9387
# Test only PyTorch export
9488
run(pt_only=True)
9589
```
90+
91+
Notes:
92+
This function iterates over multiple export formats, performs the export, and then validates the model's performance
93+
using appropriate validation functions for detection and segmentation models. The results are logged, and optionally,
94+
benchmarks can be configured to raise errors on failures using the `hard_fail` argument.
9695
"""
9796
y, t = [], time.time()
9897
device = select_device(device)
@@ -158,8 +157,7 @@ def test(
158157
pt_only=False, # test PyTorch only
159158
hard_fail=False, # throw error on benchmark failure
160159
):
161-
"""
162-
Run YOLOv3 export tests for various formats and log the results, including export success status.
160+
"""Run YOLOv3 export tests for various formats and log the results, including export success status.
163161
164162
Args:
165163
weights (str | Path): Path to the weights file. Defaults to ROOT / "yolov5s.pt".
@@ -222,8 +220,7 @@ def test(
222220

223221

224222
def parse_opt():
225-
"""
226-
Parses command line arguments for YOLOv3 inference and export configurations.
223+
"""Parses command line arguments for YOLOv3 inference and export configurations.
227224
228225
Args:
229226
--weights (str): Path to the weights file. Default is 'ROOT / "yolov3-tiny.pt"'.
@@ -241,7 +238,7 @@ def parse_opt():
241238
Returns:
242239
argparse.Namespace: The parsed arguments as a namespace object.
243240
244-
Example:
241+
Examples:
245242
To run inference on the YOLOv3-tiny model with a different image size:
246243
247244
```python
@@ -272,8 +269,7 @@ def parse_opt():
272269

273270

274271
def main(opt):
275-
"""
276-
Executes the export and benchmarking pipeline for YOLOv3 models, testing multiple export formats and validating
272+
"""Executes the export and benchmarking pipeline for YOLOv3 models, testing multiple export formats and validating
277273
performance metrics.
278274
279275
Args:
@@ -287,18 +283,18 @@ def main(opt):
287283
- mAP50-95: Mean Average Precision for the model
288284
- Inference time (ms): Time taken for inference
289285
290-
Notes:
291-
The function runs the main pipeline by exporting the YOLOv3 model to various formats and running benchmarks to
292-
evaluate performance. If `opt.test` is set to True, it only tests the export process and logs the results.
293-
294-
Example:
286+
Examples:
295287
Running the function from command line with required arguments:
296288
297289
```python
298290
$ python benchmarks.py --weights yolov5s.pt --img 640
299291
```
300292
301293
For more details, visit the Ultralytics YOLOv3 repository on [GitHub](https://github.com/ultralytics/ultralytics).
294+
295+
Notes:
296+
The function runs the main pipeline by exporting the YOLOv3 model to various formats and running benchmarks to
297+
evaluate performance. If `opt.test` is set to True, it only tests the export process and logs the results.
302298
"""
303299
test(**vars(opt)) if opt.test else run(**vars(opt))
304300

detect.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ def run(
9595
dnn=False, # use OpenCV DNN for ONNX inference
9696
vid_stride=1, # video frame-rate stride
9797
):
98-
"""
99-
Run YOLOv3 detection inference on various input sources such as images, videos, streams, and YouTube URLs.
98+
"""Run YOLOv3 detection inference on various input sources such as images, videos, streams, and YouTube URLs.
10099
101100
Args:
102101
weights (str | Path): Path to the model weights file or a Triton URL (default: 'yolov5s.pt').
103102
source (str | Path): Source of input data such as a file, directory, URL, glob pattern, or device identifier
104-
(default: 'data/images').
103+
(default: 'data/images').
105104
data (str | Path): Path to the dataset YAML file (default: 'data/coco128.yaml').
106105
imgsz (tuple[int, int]): Inference size as a tuple (height, width) (default: (640, 640)).
107106
conf_thres (float): Confidence threshold for detection (default: 0.25).
@@ -120,7 +119,8 @@ def run(
120119
update (bool): Whether to update all models (default: False).
121120
project (str | Path): Path to the project directory where results will be saved (default: 'runs/detect').
122121
name (str): Name for the specific run within the project directory (default: 'exp').
123-
exist_ok (bool): Whether to allow existing project/name directory without incrementing run index (default: False).
122+
exist_ok (bool): Whether to allow existing project/name directory without incrementing run index (default:
123+
False).
124124
line_thickness (int): Thickness of bounding box lines in pixels (default: 3).
125125
hide_labels (bool): Whether to hide labels in the results (default: False).
126126
hide_conf (bool): Whether to hide confidences in the results (default: False).
@@ -131,12 +131,6 @@ def run(
131131
Returns:
132132
None
133133
134-
Notes:
135-
This function supports a variety of input sources such as image files, video files, directories, URL patterns,
136-
webcam streams, and YouTube links. It also supports multiple model formats including PyTorch, ONNX, OpenVINO,
137-
TensorRT, CoreML, TensorFlow, PaddlePaddle, and others. The results can be visualized in real-time or saved to
138-
specified directories. Use command-line arguments to modify the behavior of the function.
139-
140134
Examples:
141135
```python
142136
# Run YOLOv3 inference on an image
@@ -148,6 +142,12 @@ def run(
148142
# Run YOLOv3 inference on a webcam
149143
run(weights='yolov5s.pt', source='0', view_img=True)
150144
```
145+
146+
Notes:
147+
This function supports a variety of input sources such as image files, video files, directories, URL patterns,
148+
webcam streams, and YouTube links. It also supports multiple model formats including PyTorch, ONNX, OpenVINO,
149+
TensorRT, CoreML, TensorFlow, PaddlePaddle, and others. The results can be visualized in real-time or saved to
150+
specified directories. Use command-line arguments to modify the behavior of the function.
151151
"""
152152
source = str(source)
153153
save_img = not nosave and not source.endswith(".txt") # save inference images
@@ -286,8 +286,7 @@ def run(
286286

287287

288288
def parse_opt():
289-
"""
290-
Parses and returns command-line options for running YOLOv3 model detection.
289+
"""Parses and returns command-line options for running YOLOv3 model detection.
291290
292291
Args:
293292
--weights (list[str]): Model path or Triton URL. Default: ROOT / "yolov3-tiny.pt".
@@ -321,7 +320,7 @@ def parse_opt():
321320
Returns:
322321
argparse.Namespace: Parsed command-line arguments for YOLOv3 inference configurations.
323322
324-
Example:
323+
Examples:
325324
```python
326325
options = parse_opt()
327326
run(**vars(options))
@@ -364,8 +363,7 @@ def parse_opt():
364363

365364

366365
def main(opt):
367-
"""
368-
Entry point for running the YOLO model; checks requirements and calls `run` with parsed options.
366+
"""Entry point for running the YOLO model; checks requirements and calls `run` with parsed options.
369367
370368
Args:
371369
opt (argparse.Namespace): Parsed command-line options, which include:
@@ -400,7 +398,7 @@ def main(opt):
400398
Returns:
401399
None
402400
403-
Example:
401+
Examples:
404402
```python
405403
if __name__ == "__main__":
406404
opt = parse_opt()

0 commit comments

Comments
 (0)