Spaces:
Build error
Build error
Upload 3 files
Browse files
ultralytics/yolo/configs/__init__.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Ultralytics YOLO 🚀, GPL-3.0 license
|
2 |
+
|
3 |
+
from pathlib import Path
|
4 |
+
from typing import Dict, Union
|
5 |
+
|
6 |
+
from omegaconf import DictConfig, OmegaConf
|
7 |
+
|
8 |
+
from ultralytics.yolo.configs.hydra_patch import check_config_mismatch
|
9 |
+
|
10 |
+
|
11 |
+
def get_config(config: Union[str, DictConfig], overrides: Union[str, Dict] = None):
|
12 |
+
"""
|
13 |
+
Load and merge configuration data from a file or dictionary.
|
14 |
+
|
15 |
+
Args:
|
16 |
+
config (Union[str, DictConfig]): Configuration data in the form of a file name or a DictConfig object.
|
17 |
+
overrides (Union[str, Dict], optional): Overrides in the form of a file name or a dictionary. Default is None.
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
OmegaConf.Namespace: Training arguments namespace.
|
21 |
+
"""
|
22 |
+
if overrides is None:
|
23 |
+
overrides = {}
|
24 |
+
if isinstance(config, (str, Path)):
|
25 |
+
config = OmegaConf.load(config)
|
26 |
+
elif isinstance(config, Dict):
|
27 |
+
config = OmegaConf.create(config)
|
28 |
+
# override
|
29 |
+
if isinstance(overrides, str):
|
30 |
+
overrides = OmegaConf.load(overrides)
|
31 |
+
elif isinstance(overrides, Dict):
|
32 |
+
overrides = OmegaConf.create(overrides)
|
33 |
+
|
34 |
+
check_config_mismatch(dict(overrides).keys(), dict(config).keys())
|
35 |
+
|
36 |
+
return OmegaConf.merge(config, overrides)
|
ultralytics/yolo/configs/default.yaml
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Ultralytics YOLO 🚀, GPL-3.0 license
|
2 |
+
# Default training settings and hyperparameters for medium-augmentation COCO training
|
3 |
+
|
4 |
+
task: "detect" # choices=['detect', 'segment', 'classify', 'init'] # init is a special case. Specify task to run.
|
5 |
+
mode: "train" # choices=['train', 'val', 'predict'] # mode to run task in.
|
6 |
+
|
7 |
+
# Train settings -------------------------------------------------------------------------------------------------------
|
8 |
+
model: null # i.e. yolov8n.pt, yolov8n.yaml. Path to model file
|
9 |
+
data: null # i.e. coco128.yaml. Path to data file
|
10 |
+
epochs: 100 # number of epochs to train for
|
11 |
+
patience: 50 # TODO: epochs to wait for no observable improvement for early stopping of training
|
12 |
+
batch: 16 # number of images per batch
|
13 |
+
imgsz: 640 # size of input images
|
14 |
+
save: True # save checkpoints
|
15 |
+
cache: False # True/ram, disk or False. Use cache for data loading
|
16 |
+
device: null # cuda device, i.e. 0 or 0,1,2,3 or cpu. Device to run on
|
17 |
+
workers: 8 # number of worker threads for data loading
|
18 |
+
project: null # project name
|
19 |
+
name: null # experiment name
|
20 |
+
exist_ok: False # whether to overwrite existing experiment
|
21 |
+
pretrained: False # whether to use a pretrained model
|
22 |
+
optimizer: 'SGD' # optimizer to use, choices=['SGD', 'Adam', 'AdamW', 'RMSProp']
|
23 |
+
verbose: False # whether to print verbose output
|
24 |
+
seed: 0 # random seed for reproducibility
|
25 |
+
deterministic: True # whether to enable deterministic mode
|
26 |
+
single_cls: False # train multi-class data as single-class
|
27 |
+
image_weights: False # use weighted image selection for training
|
28 |
+
rect: False # support rectangular training
|
29 |
+
cos_lr: False # use cosine learning rate scheduler
|
30 |
+
close_mosaic: 10 # disable mosaic augmentation for final 10 epochs
|
31 |
+
resume: False # resume training from last checkpoint
|
32 |
+
# Segmentation
|
33 |
+
overlap_mask: True # masks should overlap during training
|
34 |
+
mask_ratio: 4 # mask downsample ratio
|
35 |
+
# Classification
|
36 |
+
dropout: 0.0 # use dropout regularization
|
37 |
+
|
38 |
+
# Val/Test settings ----------------------------------------------------------------------------------------------------
|
39 |
+
val: True # validate/test during training
|
40 |
+
save_json: False # save results to JSON file
|
41 |
+
save_hybrid: False # save hybrid version of labels (labels + additional predictions)
|
42 |
+
conf: null # object confidence threshold for detection (default 0.25 predict, 0.001 val)
|
43 |
+
iou: 0.7 # intersection over union (IoU) threshold for NMS
|
44 |
+
max_det: 300 # maximum number of detections per image
|
45 |
+
half: False # use half precision (FP16)
|
46 |
+
dnn: False # use OpenCV DNN for ONNX inference
|
47 |
+
plots: True # show plots during training
|
48 |
+
|
49 |
+
# Prediction settings --------------------------------------------------------------------------------------------------
|
50 |
+
source: null # source directory for images or videos
|
51 |
+
show: False # show results if possible
|
52 |
+
save_txt: False # save results as .txt file
|
53 |
+
save_conf: False # save results with confidence scores
|
54 |
+
save_crop: False # save cropped images with results
|
55 |
+
hide_labels: False # hide labels
|
56 |
+
hide_conf: False # hide confidence scores
|
57 |
+
vid_stride: 1 # video frame-rate stride
|
58 |
+
line_thickness: 3 # bounding box thickness (pixels)
|
59 |
+
visualize: False # visualize results
|
60 |
+
augment: False # apply data augmentation to images
|
61 |
+
agnostic_nms: False # class-agnostic NMS
|
62 |
+
retina_masks: False # use retina masks for object detection
|
63 |
+
|
64 |
+
# Export settings ------------------------------------------------------------------------------------------------------
|
65 |
+
format: torchscript # format to export to
|
66 |
+
keras: False # use Keras
|
67 |
+
optimize: False # TorchScript: optimize for mobile
|
68 |
+
int8: False # CoreML/TF INT8 quantization
|
69 |
+
dynamic: False # ONNX/TF/TensorRT: dynamic axes
|
70 |
+
simplify: False # ONNX: simplify model
|
71 |
+
opset: 17 # ONNX: opset version
|
72 |
+
workspace: 4 # TensorRT: workspace size (GB)
|
73 |
+
nms: False # CoreML: add NMS
|
74 |
+
|
75 |
+
# Hyperparameters ------------------------------------------------------------------------------------------------------
|
76 |
+
lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3)
|
77 |
+
lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf)
|
78 |
+
momentum: 0.937 # SGD momentum/Adam beta1
|
79 |
+
weight_decay: 0.0005 # optimizer weight decay 5e-4
|
80 |
+
warmup_epochs: 3.0 # warmup epochs (fractions ok)
|
81 |
+
warmup_momentum: 0.8 # warmup initial momentum
|
82 |
+
warmup_bias_lr: 0.1 # warmup initial bias lr
|
83 |
+
box: 7.5 # box loss gain
|
84 |
+
cls: 0.5 # cls loss gain (scale with pixels)
|
85 |
+
dfl: 1.5 # dfl loss gain
|
86 |
+
fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
|
87 |
+
label_smoothing: 0.0
|
88 |
+
nbs: 64 # nominal batch size
|
89 |
+
hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
|
90 |
+
hsv_s: 0.7 # image HSV-Saturation augmentation (fraction)
|
91 |
+
hsv_v: 0.4 # image HSV-Value augmentation (fraction)
|
92 |
+
degrees: 0.0 # image rotation (+/- deg)
|
93 |
+
translate: 0.1 # image translation (+/- fraction)
|
94 |
+
scale: 0.5 # image scale (+/- gain)
|
95 |
+
shear: 0.0 # image shear (+/- deg)
|
96 |
+
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
|
97 |
+
flipud: 0.0 # image flip up-down (probability)
|
98 |
+
fliplr: 0.5 # image flip left-right (probability)
|
99 |
+
mosaic: 1.0 # image mosaic (probability)
|
100 |
+
mixup: 0.0 # image mixup (probability)
|
101 |
+
copy_paste: 0.0 # segment copy-paste (probability)
|
102 |
+
|
103 |
+
# Hydra configs --------------------------------------------------------------------------------------------------------
|
104 |
+
hydra:
|
105 |
+
output_subdir: null # disable hydra directory creation
|
106 |
+
run:
|
107 |
+
dir: .
|
108 |
+
|
109 |
+
# Debug, do not modify -------------------------------------------------------------------------------------------------
|
110 |
+
v5loader: False # use legacy YOLOv5 dataloader
|
ultralytics/yolo/configs/hydra_patch.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Ultralytics YOLO 🚀, GPL-3.0 license
|
2 |
+
|
3 |
+
import sys
|
4 |
+
from difflib import get_close_matches
|
5 |
+
from textwrap import dedent
|
6 |
+
|
7 |
+
import hydra
|
8 |
+
from hydra.errors import ConfigCompositionException
|
9 |
+
from omegaconf import OmegaConf, open_dict # noqa
|
10 |
+
from omegaconf.errors import ConfigAttributeError, ConfigKeyError, OmegaConfBaseException # noqa
|
11 |
+
|
12 |
+
from ultralytics.yolo.utils import LOGGER, colorstr
|
13 |
+
|
14 |
+
|
15 |
+
def override_config(overrides, cfg):
|
16 |
+
override_keys = [override.key_or_group for override in overrides]
|
17 |
+
check_config_mismatch(override_keys, cfg.keys())
|
18 |
+
for override in overrides:
|
19 |
+
if override.package is not None:
|
20 |
+
raise ConfigCompositionException(f"Override {override.input_line} looks like a config group"
|
21 |
+
f" override, but config group '{override.key_or_group}' does not exist.")
|
22 |
+
|
23 |
+
key = override.key_or_group
|
24 |
+
value = override.value()
|
25 |
+
try:
|
26 |
+
if override.is_delete():
|
27 |
+
config_val = OmegaConf.select(cfg, key, throw_on_missing=False)
|
28 |
+
if config_val is None:
|
29 |
+
raise ConfigCompositionException(f"Could not delete from config. '{override.key_or_group}'"
|
30 |
+
" does not exist.")
|
31 |
+
elif value is not None and value != config_val:
|
32 |
+
raise ConfigCompositionException("Could not delete from config. The value of"
|
33 |
+
f" '{override.key_or_group}' is {config_val} and not"
|
34 |
+
f" {value}.")
|
35 |
+
|
36 |
+
last_dot = key.rfind(".")
|
37 |
+
with open_dict(cfg):
|
38 |
+
if last_dot == -1:
|
39 |
+
del cfg[key]
|
40 |
+
else:
|
41 |
+
node = OmegaConf.select(cfg, key[:last_dot])
|
42 |
+
del node[key[last_dot + 1:]]
|
43 |
+
|
44 |
+
elif override.is_add():
|
45 |
+
if OmegaConf.select(cfg, key, throw_on_missing=False) is None or isinstance(value, (dict, list)):
|
46 |
+
OmegaConf.update(cfg, key, value, merge=True, force_add=True)
|
47 |
+
else:
|
48 |
+
assert override.input_line is not None
|
49 |
+
raise ConfigCompositionException(
|
50 |
+
dedent(f"""\
|
51 |
+
Could not append to config. An item is already at '{override.key_or_group}'.
|
52 |
+
Either remove + prefix: '{override.input_line[1:]}'
|
53 |
+
Or add a second + to add or override '{override.key_or_group}': '+{override.input_line}'
|
54 |
+
"""))
|
55 |
+
elif override.is_force_add():
|
56 |
+
OmegaConf.update(cfg, key, value, merge=True, force_add=True)
|
57 |
+
else:
|
58 |
+
try:
|
59 |
+
OmegaConf.update(cfg, key, value, merge=True)
|
60 |
+
except (ConfigAttributeError, ConfigKeyError) as ex:
|
61 |
+
raise ConfigCompositionException(f"Could not override '{override.key_or_group}'."
|
62 |
+
f"\nTo append to your config use +{override.input_line}") from ex
|
63 |
+
except OmegaConfBaseException as ex:
|
64 |
+
raise ConfigCompositionException(f"Error merging override {override.input_line}").with_traceback(
|
65 |
+
sys.exc_info()[2]) from ex
|
66 |
+
|
67 |
+
|
68 |
+
def check_config_mismatch(overrides, cfg):
|
69 |
+
mismatched = [option for option in overrides if option not in cfg and 'hydra.' not in option]
|
70 |
+
|
71 |
+
for option in mismatched:
|
72 |
+
LOGGER.info(f"{colorstr(option)} is not a valid key. Similar keys: {get_close_matches(option, cfg, 3, 0.6)}")
|
73 |
+
if mismatched:
|
74 |
+
exit()
|
75 |
+
|
76 |
+
|
77 |
+
hydra._internal.config_loader_impl.ConfigLoaderImpl._apply_overrides_to_config = override_config
|