Ultralytics Code Refactor https://ultralytics.com/actions (#13175)
* Refactor code for speed and clarity * Update export.py Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> * Update export.py Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> * Add missing Python function docstrings * Auto-format by https://ultralytics.com/actions * Update export.py Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> * Add missing Python function docstrings * Auto-format by https://ultralytics.com/actions --------- Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
1 parent
8257e0a68c
commit
ff06328498
6 files changed
+275
-250
No files matched your search
@@ -546,10 +546,10 @@ def parse_opt(known=False):
|
||||
Parses command-line arguments for YOLOv5 training, validation, and testing.
|
||||
|
||||
Args:
|
||||
known (bool, optional): If True, parses known arguments, ignoring the unknown. Defaults to False.
|
||||
known (bool, optional): If True, parses known arguments, ignoring the unknown. Defaults to False.
|
||||
|
||||
Returns:
|
||||
argparse.Namespace: Parsed command-line arguments.
|
||||
argparse.Namespace: Parsed command-line arguments.
|
||||
|
||||
Example:
|
||||
```python
|
||||
@@ -559,9 +559,9 @@ def parse_opt(known=False):
|
||||
```
|
||||
|
||||
Links:
|
||||
Models: https://github.com/ultralytics/yolov5/tree/master/models
|
||||
Datasets: https://github.com/ultralytics/yolov5/tree/master/data
|
||||
Tutorial: https://docs.ultralytics.com/yolov5/tutorials/train_custom_data
|
||||
Models: https://github.com/ultralytics/yolov5/tree/master/models
|
||||
Datasets: https://github.com/ultralytics/yolov5/tree/master/data
|
||||
Tutorial: https://docs.ultralytics.com/yolov5/tutorials/train_custom_data
|
||||
"""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--weights", type=str, default=ROOT / "yolov5s.pt", help="initial weights path")
|
||||
@@ -621,15 +621,15 @@ def main(opt, callbacks=Callbacks()):
|
||||
Runs training or hyperparameter evolution with specified options and optional callbacks.
|
||||
|
||||
Args:
|
||||
opt (argparse.Namespace): The command-line arguments parsed for YOLOv5 training and evolution.
|
||||
callbacks (ultralytics.utils.callbacks.Callbacks, optional): Callback functions for various training stages.
|
||||
Defaults to Callbacks().
|
||||
opt (argparse.Namespace): The command-line arguments parsed for YOLOv5 training and evolution.
|
||||
callbacks (ultralytics.utils.callbacks.Callbacks, optional): Callback functions for various training stages.
|
||||
Defaults to Callbacks().
|
||||
|
||||
Returns:
|
||||
None
|
||||
None
|
||||
|
||||
Note:
|
||||
For detailed usage, visit:
|
||||
For detailed usage, visit:
|
||||
https://github.com/ultralytics/yolov5/tree/master/models
|
||||
"""
|
||||
if RANK in {-1, 0}:
|
||||
@@ -918,51 +918,56 @@ def run(**kwargs):
|
||||
Executes YOLOv5 training with given options, allowing optional overrides through keyword arguments.
|
||||
|
||||
Args:
|
||||
weights (str): Path to initial weights. Defaults to ROOT / 'yolov5s.pt'.
|
||||
cfg (str): Path to model YAML configuration. Defaults to an empty string.
|
||||
data (str): Path to dataset YAML configuration. Defaults to ROOT / 'data/coco128.yaml'.
|
||||
hyp (str): Path to hyperparameters YAML configuration. Defaults to ROOT / 'data/hyps/hyp.scratch-low.yaml'.
|
||||
epochs (int): Total number of training epochs. Defaults to 100.
|
||||
batch_size (int): Total batch size for all GPUs. Use -1 for automatic batch size determination. Defaults to 16.
|
||||
imgsz (int): Image size (pixels) for training and validation. Defaults to 640.
|
||||
rect (bool): Use rectangular training. Defaults to False.
|
||||
resume (bool | str): Resume most recent training with an optional path. Defaults to False.
|
||||
nosave (bool): Only save final checkpoint. Defaults to False.
|
||||
noval (bool): Only validate at the final epoch. Defaults to False.
|
||||
noautoanchor (bool): Disable AutoAnchor. Defaults to False.
|
||||
noplots (bool): Do not save plot files. Defaults to False.
|
||||
evolve (int): Evolve hyperparameters for a specified number of generations. Use 300 if provided without a value.
|
||||
evolve_population (str): Directory for loading population during evolution. Defaults to ROOT / 'data/hyps'.
|
||||
resume_evolve (str): Resume hyperparameter evolution from the last generation. Defaults to None.
|
||||
bucket (str): gsutil bucket for saving checkpoints. Defaults to an empty string.
|
||||
cache (str): Cache image data in 'ram' or 'disk'. Defaults to None.
|
||||
image_weights (bool): Use weighted image selection for training. Defaults to False.
|
||||
device (str): CUDA device identifier, e.g., '0', '0,1,2,3', or 'cpu'. Defaults to an empty string.
|
||||
multi_scale (bool): Use multi-scale training, varying image size by ±50%. Defaults to False.
|
||||
single_cls (bool): Train with multi-class data as single-class. Defaults to False.
|
||||
optimizer (str): Optimizer type, choices are ['SGD', 'Adam', 'AdamW']. Defaults to 'SGD'.
|
||||
sync_bn (bool): Use synchronized BatchNorm, only available in DDP mode. Defaults to False.
|
||||
workers (int): Maximum dataloader workers per rank in DDP mode. Defaults to 8.
|
||||
project (str): Directory for saving training runs. Defaults to ROOT / 'runs/train'.
|
||||
name (str): Name for saving the training run. Defaults to 'exp'.
|
||||
exist_ok (bool): Allow existing project/name without incrementing. Defaults to False.
|
||||
quad (bool): Use quad dataloader. Defaults to False.
|
||||
cos_lr (bool): Use cosine learning rate scheduler. Defaults to False.
|
||||
label_smoothing (float): Label smoothing epsilon value. Defaults to 0.0.
|
||||
patience (int): Patience for early stopping, measured in epochs without improvement. Defaults to 100.
|
||||
freeze (list): Layers to freeze, e.g., backbone=10, first 3 layers = [0, 1, 2]. Defaults to [0].
|
||||
save_period (int): Frequency in epochs to save checkpoints. Disabled if < 1. Defaults to -1.
|
||||
seed (int): Global training random seed. Defaults to 0.
|
||||
local_rank (int): Automatic DDP Multi-GPU argument. Do not modify. Defaults to -1.
|
||||
weights (str, optional): Path to initial weights. Defaults to ROOT / 'yolov5s.pt'.
|
||||
cfg (str, optional): Path to model YAML configuration. Defaults to an empty string.
|
||||
data (str, optional): Path to dataset YAML configuration. Defaults to ROOT / 'data/coco128.yaml'.
|
||||
hyp (str, optional): Path to hyperparameters YAML configuration. Defaults to ROOT / 'data/hyps/hyp.scratch-low.yaml'.
|
||||
epochs (int, optional): Total number of training epochs. Defaults to 100.
|
||||
batch_size (int, optional): Total batch size for all GPUs. Use -1 for automatic batch size determination. Defaults to 16.
|
||||
imgsz (int, optional): Image size (pixels) for training and validation. Defaults to 640.
|
||||
rect (bool, optional): Use rectangular training. Defaults to False.
|
||||
resume (bool | str, optional): Resume most recent training with an optional path. Defaults to False.
|
||||
nosave (bool, optional): Only save the final checkpoint. Defaults to False.
|
||||
noval (bool, optional): Only validate at the final epoch. Defaults to False.
|
||||
noautoanchor (bool, optional): Disable AutoAnchor. Defaults to False.
|
||||
noplots (bool, optional): Do not save plot files. Defaults to False.
|
||||
evolve (int, optional): Evolve hyperparameters for a specified number of generations. Use 300 if provided without a value.
|
||||
evolve_population (str, optional): Directory for loading population during evolution. Defaults to ROOT / 'data/hyps'.
|
||||
resume_evolve (str, optional): Resume hyperparameter evolution from the last generation. Defaults to None.
|
||||
bucket (str, optional): gsutil bucket for saving checkpoints. Defaults to an empty string.
|
||||
cache (str, optional): Cache image data in 'ram' or 'disk'. Defaults to None.
|
||||
image_weights (bool, optional): Use weighted image selection for training. Defaults to False.
|
||||
device (str, optional): CUDA device identifier, e.g., '0', '0,1,2,3', or 'cpu'. Defaults to an empty string.
|
||||
multi_scale (bool, optional): Use multi-scale training, varying image size by ±50%. Defaults to False.
|
||||
single_cls (bool, optional): Train with multi-class data as single-class. Defaults to False.
|
||||
optimizer (str, optional): Optimizer type, choices are ['SGD', 'Adam', 'AdamW']. Defaults to 'SGD'.
|
||||
sync_bn (bool, optional): Use synchronized BatchNorm, only available in DDP mode. Defaults to False.
|
||||
workers (int, optional): Maximum dataloader workers per rank in DDP mode. Defaults to 8.
|
||||
project (str, optional): Directory for saving training runs. Defaults to ROOT / 'runs/train'.
|
||||
name (str, optional): Name for saving the training run. Defaults to 'exp'.
|
||||
exist_ok (bool, optional): Allow existing project/name without incrementing. Defaults to False.
|
||||
quad (bool, optional): Use quad dataloader. Defaults to False.
|
||||
cos_lr (bool, optional): Use cosine learning rate scheduler. Defaults to False.
|
||||
label_smoothing (float, optional): Label smoothing epsilon value. Defaults to 0.0.
|
||||
patience (int, optional): Patience for early stopping, measured in epochs without improvement. Defaults to 100.
|
||||
freeze (list, optional): Layers to freeze, e.g., backbone=10, first 3 layers = [0, 1, 2]. Defaults to [0].
|
||||
save_period (int, optional): Frequency in epochs to save checkpoints. Disabled if < 1. Defaults to -1.
|
||||
seed (int, optional): Global training random seed. Defaults to 0.
|
||||
local_rank (int, optional): Automatic DDP Multi-GPU argument. Do not modify. Defaults to -1.
|
||||
|
||||
Returns:
|
||||
None: The function initiates YOLOv5 training or hyperparameter evolution based on the provided options.
|
||||
None: The function initiates YOLOv5 training or hyperparameter evolution based on the provided options.
|
||||
|
||||
Examples:
|
||||
```python
|
||||
import train
|
||||
train.run(data='coco128.yaml', imgsz=320, weights='yolov5m.pt')
|
||||
```
|
||||
```python
|
||||
import train
|
||||
train.run(data='coco128.yaml', imgsz=320, weights='yolov5m.pt')
|
||||
```
|
||||
|
||||
Notes:
|
||||
- Models: https://github.com/ultralytics/yolov5/tree/master/models
|
||||
- Datasets: https://github.com/ultralytics/yolov5/tree/master/data
|
||||
- Tutorial: https://docs.ultralytics.com/yolov5/tutorials/train_custom_data
|
||||
"""
|
||||
opt = parse_opt(True)
|
||||
for k, v in kwargs.items():
|
||||
|
||||
Reference in new issue
Block a user