Improved Usage example docstrings (#9075)

* Updated Usage examples

* Update detect.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

* Update predict.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Glenn Jocher authored and GitHub committed 2022-08-22 01:06:29 +02:00
1 parent 0abae780b3
commit 06831aa9e9
10 files changed
+60 -27

No files matched your search

+18 -3
View File
@@ -1,9 +1,24 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
""" """
Run classification inference on file/dir/URL/glob Run YOLOv5 classification inference on images, videos, directories, and globs.
Usage: Usage - sources:
$ python classify/predict.py --weights yolov5s-cls.pt --source data/images/bus.jpg $ python classify/predict.py --weights yolov5s.pt --source img.jpg # image
vid.mp4 # video
path/ # directory
'path/*.jpg' # glob
Usage - formats:
$ python classify/predict.py --weights yolov5s-cls.pt # PyTorch
yolov5s-cls.torchscript # TorchScript
yolov5s-cls.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s-cls.xml # OpenVINO
yolov5s-cls.engine # TensorRT
yolov5s-cls.mlmodel # CoreML (macOS-only)
yolov5s-cls_saved_model # TensorFlow SavedModel
yolov5s-cls.pb # TensorFlow GraphDef
yolov5s-cls.tflite # TensorFlow Lite
yolov5s-cls_edgetpu.tflite # TensorFlow Edge TPU
""" """
import argparse import argparse
+8 -5
View File
@@ -1,13 +1,16 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
""" """
Train a YOLOv5 classifier model on a classification dataset Train a YOLOv5 classifier model on a classification dataset
Datasets: --data mnist, fashion-mnist, cifar10, cifar100, imagenette, imagewoof, imagenet, or 'path/to/custom/dataset'
Usage - Single-GPU training:
$ python classify/train.py --model yolov5s-cls.pt --data imagenette160 --epochs 5 --img 128
Usage - Multi-GPU DDP training:
$ python -m torch.distributed.run --nproc_per_node 4 --master_port 1 classify/train.py --model yolov5s-cls.pt --data imagenet --epochs 5 --img 224 --device 0,1,2,3
Datasets: --data mnist, fashion-mnist, cifar10, cifar100, imagenette, imagewoof, imagenet, or 'path/to/data'
YOLOv5-cls models: --model yolov5n-cls.pt, yolov5s-cls.pt, yolov5m-cls.pt, yolov5l-cls.pt, yolov5x-cls.pt YOLOv5-cls models: --model yolov5n-cls.pt, yolov5s-cls.pt, yolov5m-cls.pt, yolov5l-cls.pt, yolov5x-cls.pt
Torchvision models: --model resnet50, efficientnet_b0, etc. See https://pytorch.org/vision/stable/models.html Torchvision models: --model resnet50, efficientnet_b0, etc. See https://pytorch.org/vision/stable/models.html
Usage - Single-GPU and Multi-GPU DDP
$ python classify/train.py --model yolov5s-cls.pt --data imagenette160 --epochs 5 --img 128
$ python -m torch.distributed.run --nproc_per_node 4 --master_port 1 classify/train.py --model yolov5s-cls.pt --data imagenet --epochs 5 --img 224 --device 0,1,2,3
""" """
import argparse import argparse
+14 -2
View File
@@ -1,10 +1,22 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
""" """
Validate a classification model on a dataset Validate a trained YOLOv5 classification model on a classification dataset
Usage: Usage:
$ bash data/scripts/get_imagenet.sh --val # download ImageNet val split (6.3G, 50000 images) $ bash data/scripts/get_imagenet.sh --val # download ImageNet val split (6.3G, 50000 images)
$ python classify/val.py --weights yolov5m-cls.pt --data ../datasets/imagenet --img 224 # validate $ python classify/val.py --weights yolov5m-cls.pt --data ../datasets/imagenet --img 224 # validate ImageNet
Usage - formats:
$ python classify/val.py --weights yolov5s-cls.pt # PyTorch
yolov5s-cls.torchscript # TorchScript
yolov5s-cls.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s-cls.xml # OpenVINO
yolov5s-cls.engine # TensorRT
yolov5s-cls.mlmodel # CoreML (macOS-only)
yolov5s-cls_saved_model # TensorFlow SavedModel
yolov5s-cls.pb # TensorFlow GraphDef
yolov5s-cls.tflite # TensorFlow Lite
yolov5s-cls_edgetpu.tflite # TensorFlow Edge TPU
""" """
import argparse import argparse
+3 -3
View File
@@ -1,9 +1,9 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
""" """
Run inference on images, videos, directories, streams, etc. Run YOLOv5 detection inference on images, videos, directories, streams, etc.
Usage - sources: Usage - sources:
$ python path/to/detect.py --weights yolov5s.pt --source 0 # webcam $ python detect.py --weights yolov5s.pt --source 0 # webcam
img.jpg # image img.jpg # image
vid.mp4 # video vid.mp4 # video
path/ # directory path/ # directory
@@ -12,7 +12,7 @@ Usage - sources:
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
Usage - formats: Usage - formats:
$ python path/to/detect.py --weights yolov5s.pt # PyTorch $ python detect.py --weights yolov5s.pt # PyTorch
yolov5s.torchscript # TorchScript yolov5s.torchscript # TorchScript
yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s.xml # OpenVINO yolov5s.xml # OpenVINO
+2 -2
View File
@@ -21,10 +21,10 @@ Requirements:
$ pip install -r requirements.txt coremltools onnx onnx-simplifier onnxruntime-gpu openvino-dev tensorflow # GPU $ pip install -r requirements.txt coremltools onnx onnx-simplifier onnxruntime-gpu openvino-dev tensorflow # GPU
Usage: Usage:
$ python path/to/export.py --weights yolov5s.pt --include torchscript onnx openvino engine coreml tflite ... $ python export.py --weights yolov5s.pt --include torchscript onnx openvino engine coreml tflite ...
Inference: Inference:
$ python path/to/detect.py --weights yolov5s.pt # PyTorch $ python detect.py --weights yolov5s.pt # PyTorch
yolov5s.torchscript # TorchScript yolov5s.torchscript # TorchScript
yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s.xml # OpenVINO yolov5s.xml # OpenVINO
+2 -2
View File
@@ -1,11 +1,11 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
""" """
PyTorch Hub models https://pytorch.org/hub/ultralytics_yolov5/ PyTorch Hub models https://pytorch.org/hub/ultralytics_yolov5
Usage: Usage:
import torch import torch
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
model = torch.hub.load('ultralytics/yolov5:master', 'custom', 'path/to/yolov5s.onnx') # file from branch model = torch.hub.load('ultralytics/yolov5:master', 'custom', 'path/to/yolov5s.onnx') # custom model from branch
""" """
import torch import torch
+1 -1
View File
@@ -7,7 +7,7 @@ Usage:
$ python models/tf.py --weights yolov5s.pt $ python models/tf.py --weights yolov5s.pt
Export: Export:
$ python path/to/export.py --weights yolov5s.pt --include saved_model pb tflite tfjs $ python export.py --weights yolov5s.pt --include saved_model pb tflite tfjs
""" """
import argparse import argparse
+1 -1
View File
@@ -3,7 +3,7 @@
YOLO-specific modules YOLO-specific modules
Usage: Usage:
$ python path/to/models/yolo.py --cfg yolov5s.yaml $ python models/yolo.py --cfg yolov5s.yaml
""" """
import argparse import argparse
+8 -5
View File
@@ -1,15 +1,18 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
""" """
Train a YOLOv5 model on a custom dataset. Train a YOLOv5 model on a custom dataset.
Models and datasets download automatically from the latest YOLOv5 release. Models and datasets download automatically from the latest YOLOv5 release.
Usage - Single-GPU training:
$ python train.py --data coco128.yaml --weights yolov5s.pt --img 640 # from pretrained (recommended)
$ python train.py --data coco128.yaml --weights '' --cfg yolov5s.yaml --img 640 # from scratch
Usage - Multi-GPU DDP training:
$ python -m torch.distributed.run --nproc_per_node 4 --master_port 1 train.py --data coco128.yaml --weights yolov5s.pt --img 640 --device 0,1,2,3
Models: https://github.com/ultralytics/yolov5/tree/master/models Models: https://github.com/ultralytics/yolov5/tree/master/models
Datasets: https://github.com/ultralytics/yolov5/tree/master/data Datasets: https://github.com/ultralytics/yolov5/tree/master/data
Tutorial: https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data Tutorial: https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
Usage:
$ python path/to/train.py --data coco128.yaml --weights yolov5s.pt --img 640 # from pretrained (RECOMMENDED)
$ python path/to/train.py --data coco128.yaml --weights '' --cfg yolov5s.yaml --img 640 # from scratch
""" """
import argparse import argparse
+3 -3
View File
@@ -1,12 +1,12 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
""" """
Validate a trained YOLOv5 model accuracy on a custom dataset Validate a trained YOLOv5 detection model on a detection dataset
Usage: Usage:
$ python path/to/val.py --weights yolov5s.pt --data coco128.yaml --img 640 $ python val.py --weights yolov5s.pt --data coco128.yaml --img 640
Usage - formats: Usage - formats:
$ python path/to/val.py --weights yolov5s.pt # PyTorch $ python val.py --weights yolov5s.pt # PyTorch
yolov5s.torchscript # TorchScript yolov5s.torchscript # TorchScript
yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s.xml # OpenVINO yolov5s.xml # OpenVINO