dgenerate-ultralytics-headless 8.3.134__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dgenerate_ultralytics_headless-8.3.134.dist-info/METADATA +400 -0
- dgenerate_ultralytics_headless-8.3.134.dist-info/RECORD +272 -0
- dgenerate_ultralytics_headless-8.3.134.dist-info/WHEEL +5 -0
- dgenerate_ultralytics_headless-8.3.134.dist-info/entry_points.txt +3 -0
- dgenerate_ultralytics_headless-8.3.134.dist-info/licenses/LICENSE +661 -0
- dgenerate_ultralytics_headless-8.3.134.dist-info/top_level.txt +1 -0
- tests/__init__.py +22 -0
- tests/conftest.py +83 -0
- tests/test_cli.py +138 -0
- tests/test_cuda.py +215 -0
- tests/test_engine.py +131 -0
- tests/test_exports.py +236 -0
- tests/test_integrations.py +154 -0
- tests/test_python.py +694 -0
- tests/test_solutions.py +187 -0
- ultralytics/__init__.py +30 -0
- ultralytics/assets/bus.jpg +0 -0
- ultralytics/assets/zidane.jpg +0 -0
- ultralytics/cfg/__init__.py +1023 -0
- ultralytics/cfg/datasets/Argoverse.yaml +77 -0
- ultralytics/cfg/datasets/DOTAv1.5.yaml +37 -0
- ultralytics/cfg/datasets/DOTAv1.yaml +36 -0
- ultralytics/cfg/datasets/GlobalWheat2020.yaml +68 -0
- ultralytics/cfg/datasets/HomeObjects-3K.yaml +33 -0
- ultralytics/cfg/datasets/ImageNet.yaml +2025 -0
- ultralytics/cfg/datasets/Objects365.yaml +443 -0
- ultralytics/cfg/datasets/SKU-110K.yaml +58 -0
- ultralytics/cfg/datasets/VOC.yaml +106 -0
- ultralytics/cfg/datasets/VisDrone.yaml +77 -0
- ultralytics/cfg/datasets/african-wildlife.yaml +25 -0
- ultralytics/cfg/datasets/brain-tumor.yaml +23 -0
- ultralytics/cfg/datasets/carparts-seg.yaml +44 -0
- ultralytics/cfg/datasets/coco-pose.yaml +42 -0
- ultralytics/cfg/datasets/coco.yaml +118 -0
- ultralytics/cfg/datasets/coco128-seg.yaml +101 -0
- ultralytics/cfg/datasets/coco128.yaml +101 -0
- ultralytics/cfg/datasets/coco8-multispectral.yaml +104 -0
- ultralytics/cfg/datasets/coco8-pose.yaml +26 -0
- ultralytics/cfg/datasets/coco8-seg.yaml +101 -0
- ultralytics/cfg/datasets/coco8.yaml +101 -0
- ultralytics/cfg/datasets/crack-seg.yaml +22 -0
- ultralytics/cfg/datasets/dog-pose.yaml +24 -0
- ultralytics/cfg/datasets/dota8-multispectral.yaml +38 -0
- ultralytics/cfg/datasets/dota8.yaml +35 -0
- ultralytics/cfg/datasets/hand-keypoints.yaml +26 -0
- ultralytics/cfg/datasets/lvis.yaml +1240 -0
- ultralytics/cfg/datasets/medical-pills.yaml +22 -0
- ultralytics/cfg/datasets/open-images-v7.yaml +666 -0
- ultralytics/cfg/datasets/package-seg.yaml +22 -0
- ultralytics/cfg/datasets/signature.yaml +21 -0
- ultralytics/cfg/datasets/tiger-pose.yaml +25 -0
- ultralytics/cfg/datasets/xView.yaml +155 -0
- ultralytics/cfg/default.yaml +127 -0
- ultralytics/cfg/models/11/yolo11-cls-resnet18.yaml +17 -0
- ultralytics/cfg/models/11/yolo11-cls.yaml +33 -0
- ultralytics/cfg/models/11/yolo11-obb.yaml +50 -0
- ultralytics/cfg/models/11/yolo11-pose.yaml +51 -0
- ultralytics/cfg/models/11/yolo11-seg.yaml +50 -0
- ultralytics/cfg/models/11/yolo11.yaml +50 -0
- ultralytics/cfg/models/11/yoloe-11-seg.yaml +48 -0
- ultralytics/cfg/models/11/yoloe-11.yaml +48 -0
- ultralytics/cfg/models/12/yolo12-cls.yaml +32 -0
- ultralytics/cfg/models/12/yolo12-obb.yaml +48 -0
- ultralytics/cfg/models/12/yolo12-pose.yaml +49 -0
- ultralytics/cfg/models/12/yolo12-seg.yaml +48 -0
- ultralytics/cfg/models/12/yolo12.yaml +48 -0
- ultralytics/cfg/models/rt-detr/rtdetr-l.yaml +53 -0
- ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml +45 -0
- ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml +45 -0
- ultralytics/cfg/models/rt-detr/rtdetr-x.yaml +57 -0
- ultralytics/cfg/models/v10/yolov10b.yaml +45 -0
- ultralytics/cfg/models/v10/yolov10l.yaml +45 -0
- ultralytics/cfg/models/v10/yolov10m.yaml +45 -0
- ultralytics/cfg/models/v10/yolov10n.yaml +45 -0
- ultralytics/cfg/models/v10/yolov10s.yaml +45 -0
- ultralytics/cfg/models/v10/yolov10x.yaml +45 -0
- ultralytics/cfg/models/v3/yolov3-spp.yaml +49 -0
- ultralytics/cfg/models/v3/yolov3-tiny.yaml +40 -0
- ultralytics/cfg/models/v3/yolov3.yaml +49 -0
- ultralytics/cfg/models/v5/yolov5-p6.yaml +62 -0
- ultralytics/cfg/models/v5/yolov5.yaml +51 -0
- ultralytics/cfg/models/v6/yolov6.yaml +56 -0
- ultralytics/cfg/models/v8/yoloe-v8-seg.yaml +45 -0
- ultralytics/cfg/models/v8/yoloe-v8.yaml +45 -0
- ultralytics/cfg/models/v8/yolov8-cls-resnet101.yaml +28 -0
- ultralytics/cfg/models/v8/yolov8-cls-resnet50.yaml +28 -0
- ultralytics/cfg/models/v8/yolov8-cls.yaml +32 -0
- ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +58 -0
- ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +60 -0
- ultralytics/cfg/models/v8/yolov8-ghost.yaml +50 -0
- ultralytics/cfg/models/v8/yolov8-obb.yaml +49 -0
- ultralytics/cfg/models/v8/yolov8-p2.yaml +57 -0
- ultralytics/cfg/models/v8/yolov8-p6.yaml +59 -0
- ultralytics/cfg/models/v8/yolov8-pose-p6.yaml +60 -0
- ultralytics/cfg/models/v8/yolov8-pose.yaml +50 -0
- ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +49 -0
- ultralytics/cfg/models/v8/yolov8-seg-p6.yaml +59 -0
- ultralytics/cfg/models/v8/yolov8-seg.yaml +49 -0
- ultralytics/cfg/models/v8/yolov8-world.yaml +51 -0
- ultralytics/cfg/models/v8/yolov8-worldv2.yaml +49 -0
- ultralytics/cfg/models/v8/yolov8.yaml +49 -0
- ultralytics/cfg/models/v9/yolov9c-seg.yaml +41 -0
- ultralytics/cfg/models/v9/yolov9c.yaml +41 -0
- ultralytics/cfg/models/v9/yolov9e-seg.yaml +64 -0
- ultralytics/cfg/models/v9/yolov9e.yaml +64 -0
- ultralytics/cfg/models/v9/yolov9m.yaml +41 -0
- ultralytics/cfg/models/v9/yolov9s.yaml +41 -0
- ultralytics/cfg/models/v9/yolov9t.yaml +41 -0
- ultralytics/cfg/trackers/botsort.yaml +22 -0
- ultralytics/cfg/trackers/bytetrack.yaml +14 -0
- ultralytics/data/__init__.py +26 -0
- ultralytics/data/annotator.py +66 -0
- ultralytics/data/augment.py +2945 -0
- ultralytics/data/base.py +438 -0
- ultralytics/data/build.py +258 -0
- ultralytics/data/converter.py +754 -0
- ultralytics/data/dataset.py +834 -0
- ultralytics/data/loaders.py +676 -0
- ultralytics/data/scripts/download_weights.sh +18 -0
- ultralytics/data/scripts/get_coco.sh +61 -0
- ultralytics/data/scripts/get_coco128.sh +18 -0
- ultralytics/data/scripts/get_imagenet.sh +52 -0
- ultralytics/data/split.py +125 -0
- ultralytics/data/split_dota.py +325 -0
- ultralytics/data/utils.py +777 -0
- ultralytics/engine/__init__.py +1 -0
- ultralytics/engine/exporter.py +1519 -0
- ultralytics/engine/model.py +1156 -0
- ultralytics/engine/predictor.py +502 -0
- ultralytics/engine/results.py +1840 -0
- ultralytics/engine/trainer.py +853 -0
- ultralytics/engine/tuner.py +243 -0
- ultralytics/engine/validator.py +377 -0
- ultralytics/hub/__init__.py +168 -0
- ultralytics/hub/auth.py +137 -0
- ultralytics/hub/google/__init__.py +176 -0
- ultralytics/hub/session.py +446 -0
- ultralytics/hub/utils.py +248 -0
- ultralytics/models/__init__.py +9 -0
- ultralytics/models/fastsam/__init__.py +7 -0
- ultralytics/models/fastsam/model.py +61 -0
- ultralytics/models/fastsam/predict.py +181 -0
- ultralytics/models/fastsam/utils.py +24 -0
- ultralytics/models/fastsam/val.py +40 -0
- ultralytics/models/nas/__init__.py +7 -0
- ultralytics/models/nas/model.py +102 -0
- ultralytics/models/nas/predict.py +58 -0
- ultralytics/models/nas/val.py +39 -0
- ultralytics/models/rtdetr/__init__.py +7 -0
- ultralytics/models/rtdetr/model.py +63 -0
- ultralytics/models/rtdetr/predict.py +84 -0
- ultralytics/models/rtdetr/train.py +85 -0
- ultralytics/models/rtdetr/val.py +191 -0
- ultralytics/models/sam/__init__.py +6 -0
- ultralytics/models/sam/amg.py +260 -0
- ultralytics/models/sam/build.py +358 -0
- ultralytics/models/sam/model.py +170 -0
- ultralytics/models/sam/modules/__init__.py +1 -0
- ultralytics/models/sam/modules/blocks.py +1129 -0
- ultralytics/models/sam/modules/decoders.py +515 -0
- ultralytics/models/sam/modules/encoders.py +854 -0
- ultralytics/models/sam/modules/memory_attention.py +299 -0
- ultralytics/models/sam/modules/sam.py +1006 -0
- ultralytics/models/sam/modules/tiny_encoder.py +1002 -0
- ultralytics/models/sam/modules/transformer.py +351 -0
- ultralytics/models/sam/modules/utils.py +394 -0
- ultralytics/models/sam/predict.py +1605 -0
- ultralytics/models/utils/__init__.py +1 -0
- ultralytics/models/utils/loss.py +455 -0
- ultralytics/models/utils/ops.py +268 -0
- ultralytics/models/yolo/__init__.py +7 -0
- ultralytics/models/yolo/classify/__init__.py +7 -0
- ultralytics/models/yolo/classify/predict.py +88 -0
- ultralytics/models/yolo/classify/train.py +233 -0
- ultralytics/models/yolo/classify/val.py +215 -0
- ultralytics/models/yolo/detect/__init__.py +7 -0
- ultralytics/models/yolo/detect/predict.py +124 -0
- ultralytics/models/yolo/detect/train.py +217 -0
- ultralytics/models/yolo/detect/val.py +451 -0
- ultralytics/models/yolo/model.py +354 -0
- ultralytics/models/yolo/obb/__init__.py +7 -0
- ultralytics/models/yolo/obb/predict.py +66 -0
- ultralytics/models/yolo/obb/train.py +81 -0
- ultralytics/models/yolo/obb/val.py +283 -0
- ultralytics/models/yolo/pose/__init__.py +7 -0
- ultralytics/models/yolo/pose/predict.py +79 -0
- ultralytics/models/yolo/pose/train.py +154 -0
- ultralytics/models/yolo/pose/val.py +394 -0
- ultralytics/models/yolo/segment/__init__.py +7 -0
- ultralytics/models/yolo/segment/predict.py +113 -0
- ultralytics/models/yolo/segment/train.py +123 -0
- ultralytics/models/yolo/segment/val.py +428 -0
- ultralytics/models/yolo/world/__init__.py +5 -0
- ultralytics/models/yolo/world/train.py +119 -0
- ultralytics/models/yolo/world/train_world.py +176 -0
- ultralytics/models/yolo/yoloe/__init__.py +22 -0
- ultralytics/models/yolo/yoloe/predict.py +169 -0
- ultralytics/models/yolo/yoloe/train.py +298 -0
- ultralytics/models/yolo/yoloe/train_seg.py +124 -0
- ultralytics/models/yolo/yoloe/val.py +191 -0
- ultralytics/nn/__init__.py +29 -0
- ultralytics/nn/autobackend.py +842 -0
- ultralytics/nn/modules/__init__.py +182 -0
- ultralytics/nn/modules/activation.py +53 -0
- ultralytics/nn/modules/block.py +1966 -0
- ultralytics/nn/modules/conv.py +712 -0
- ultralytics/nn/modules/head.py +880 -0
- ultralytics/nn/modules/transformer.py +713 -0
- ultralytics/nn/modules/utils.py +164 -0
- ultralytics/nn/tasks.py +1627 -0
- ultralytics/nn/text_model.py +351 -0
- ultralytics/solutions/__init__.py +41 -0
- ultralytics/solutions/ai_gym.py +116 -0
- ultralytics/solutions/analytics.py +252 -0
- ultralytics/solutions/config.py +106 -0
- ultralytics/solutions/distance_calculation.py +124 -0
- ultralytics/solutions/heatmap.py +127 -0
- ultralytics/solutions/instance_segmentation.py +84 -0
- ultralytics/solutions/object_blurrer.py +90 -0
- ultralytics/solutions/object_counter.py +195 -0
- ultralytics/solutions/object_cropper.py +84 -0
- ultralytics/solutions/parking_management.py +273 -0
- ultralytics/solutions/queue_management.py +93 -0
- ultralytics/solutions/region_counter.py +120 -0
- ultralytics/solutions/security_alarm.py +154 -0
- ultralytics/solutions/similarity_search.py +172 -0
- ultralytics/solutions/solutions.py +724 -0
- ultralytics/solutions/speed_estimation.py +110 -0
- ultralytics/solutions/streamlit_inference.py +196 -0
- ultralytics/solutions/templates/similarity-search.html +160 -0
- ultralytics/solutions/trackzone.py +88 -0
- ultralytics/solutions/vision_eye.py +68 -0
- ultralytics/trackers/__init__.py +7 -0
- ultralytics/trackers/basetrack.py +124 -0
- ultralytics/trackers/bot_sort.py +260 -0
- ultralytics/trackers/byte_tracker.py +480 -0
- ultralytics/trackers/track.py +125 -0
- ultralytics/trackers/utils/__init__.py +1 -0
- ultralytics/trackers/utils/gmc.py +376 -0
- ultralytics/trackers/utils/kalman_filter.py +493 -0
- ultralytics/trackers/utils/matching.py +157 -0
- ultralytics/utils/__init__.py +1435 -0
- ultralytics/utils/autobatch.py +106 -0
- ultralytics/utils/autodevice.py +174 -0
- ultralytics/utils/benchmarks.py +695 -0
- ultralytics/utils/callbacks/__init__.py +5 -0
- ultralytics/utils/callbacks/base.py +234 -0
- ultralytics/utils/callbacks/clearml.py +153 -0
- ultralytics/utils/callbacks/comet.py +552 -0
- ultralytics/utils/callbacks/dvc.py +205 -0
- ultralytics/utils/callbacks/hub.py +108 -0
- ultralytics/utils/callbacks/mlflow.py +138 -0
- ultralytics/utils/callbacks/neptune.py +140 -0
- ultralytics/utils/callbacks/raytune.py +43 -0
- ultralytics/utils/callbacks/tensorboard.py +132 -0
- ultralytics/utils/callbacks/wb.py +185 -0
- ultralytics/utils/checks.py +897 -0
- ultralytics/utils/dist.py +119 -0
- ultralytics/utils/downloads.py +499 -0
- ultralytics/utils/errors.py +43 -0
- ultralytics/utils/export.py +219 -0
- ultralytics/utils/files.py +221 -0
- ultralytics/utils/instance.py +499 -0
- ultralytics/utils/loss.py +813 -0
- ultralytics/utils/metrics.py +1356 -0
- ultralytics/utils/ops.py +885 -0
- ultralytics/utils/patches.py +143 -0
- ultralytics/utils/plotting.py +1011 -0
- ultralytics/utils/tal.py +416 -0
- ultralytics/utils/torch_utils.py +990 -0
- ultralytics/utils/triton.py +116 -0
- ultralytics/utils/tuner.py +159 -0
@@ -0,0 +1,234 @@
|
|
1
|
+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
2
|
+
"""Base callbacks for Ultralytics training, validation, prediction, and export processes."""
|
3
|
+
|
4
|
+
from collections import defaultdict
|
5
|
+
from copy import deepcopy
|
6
|
+
|
7
|
+
# Trainer callbacks ----------------------------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
|
10
|
+
def on_pretrain_routine_start(trainer):
|
11
|
+
"""Called before the pretraining routine starts."""
|
12
|
+
pass
|
13
|
+
|
14
|
+
|
15
|
+
def on_pretrain_routine_end(trainer):
|
16
|
+
"""Called after the pretraining routine ends."""
|
17
|
+
pass
|
18
|
+
|
19
|
+
|
20
|
+
def on_train_start(trainer):
|
21
|
+
"""Called when the training starts."""
|
22
|
+
pass
|
23
|
+
|
24
|
+
|
25
|
+
def on_train_epoch_start(trainer):
|
26
|
+
"""Called at the start of each training epoch."""
|
27
|
+
pass
|
28
|
+
|
29
|
+
|
30
|
+
def on_train_batch_start(trainer):
|
31
|
+
"""Called at the start of each training batch."""
|
32
|
+
pass
|
33
|
+
|
34
|
+
|
35
|
+
def optimizer_step(trainer):
|
36
|
+
"""Called when the optimizer takes a step."""
|
37
|
+
pass
|
38
|
+
|
39
|
+
|
40
|
+
def on_before_zero_grad(trainer):
|
41
|
+
"""Called before the gradients are set to zero."""
|
42
|
+
pass
|
43
|
+
|
44
|
+
|
45
|
+
def on_train_batch_end(trainer):
|
46
|
+
"""Called at the end of each training batch."""
|
47
|
+
pass
|
48
|
+
|
49
|
+
|
50
|
+
def on_train_epoch_end(trainer):
|
51
|
+
"""Called at the end of each training epoch."""
|
52
|
+
pass
|
53
|
+
|
54
|
+
|
55
|
+
def on_fit_epoch_end(trainer):
|
56
|
+
"""Called at the end of each fit epoch (train + val)."""
|
57
|
+
pass
|
58
|
+
|
59
|
+
|
60
|
+
def on_model_save(trainer):
|
61
|
+
"""Called when the model is saved."""
|
62
|
+
pass
|
63
|
+
|
64
|
+
|
65
|
+
def on_train_end(trainer):
|
66
|
+
"""Called when the training ends."""
|
67
|
+
pass
|
68
|
+
|
69
|
+
|
70
|
+
def on_params_update(trainer):
|
71
|
+
"""Called when the model parameters are updated."""
|
72
|
+
pass
|
73
|
+
|
74
|
+
|
75
|
+
def teardown(trainer):
|
76
|
+
"""Called during the teardown of the training process."""
|
77
|
+
pass
|
78
|
+
|
79
|
+
|
80
|
+
# Validator callbacks --------------------------------------------------------------------------------------------------
|
81
|
+
|
82
|
+
|
83
|
+
def on_val_start(validator):
|
84
|
+
"""Called when the validation starts."""
|
85
|
+
pass
|
86
|
+
|
87
|
+
|
88
|
+
def on_val_batch_start(validator):
|
89
|
+
"""Called at the start of each validation batch."""
|
90
|
+
pass
|
91
|
+
|
92
|
+
|
93
|
+
def on_val_batch_end(validator):
|
94
|
+
"""Called at the end of each validation batch."""
|
95
|
+
pass
|
96
|
+
|
97
|
+
|
98
|
+
def on_val_end(validator):
|
99
|
+
"""Called when the validation ends."""
|
100
|
+
pass
|
101
|
+
|
102
|
+
|
103
|
+
# Predictor callbacks --------------------------------------------------------------------------------------------------
|
104
|
+
|
105
|
+
|
106
|
+
def on_predict_start(predictor):
|
107
|
+
"""Called when the prediction starts."""
|
108
|
+
pass
|
109
|
+
|
110
|
+
|
111
|
+
def on_predict_batch_start(predictor):
|
112
|
+
"""Called at the start of each prediction batch."""
|
113
|
+
pass
|
114
|
+
|
115
|
+
|
116
|
+
def on_predict_batch_end(predictor):
|
117
|
+
"""Called at the end of each prediction batch."""
|
118
|
+
pass
|
119
|
+
|
120
|
+
|
121
|
+
def on_predict_postprocess_end(predictor):
|
122
|
+
"""Called after the post-processing of the prediction ends."""
|
123
|
+
pass
|
124
|
+
|
125
|
+
|
126
|
+
def on_predict_end(predictor):
|
127
|
+
"""Called when the prediction ends."""
|
128
|
+
pass
|
129
|
+
|
130
|
+
|
131
|
+
# Exporter callbacks ---------------------------------------------------------------------------------------------------
|
132
|
+
|
133
|
+
|
134
|
+
def on_export_start(exporter):
|
135
|
+
"""Called when the model export starts."""
|
136
|
+
pass
|
137
|
+
|
138
|
+
|
139
|
+
def on_export_end(exporter):
|
140
|
+
"""Called when the model export ends."""
|
141
|
+
pass
|
142
|
+
|
143
|
+
|
144
|
+
default_callbacks = {
|
145
|
+
# Run in trainer
|
146
|
+
"on_pretrain_routine_start": [on_pretrain_routine_start],
|
147
|
+
"on_pretrain_routine_end": [on_pretrain_routine_end],
|
148
|
+
"on_train_start": [on_train_start],
|
149
|
+
"on_train_epoch_start": [on_train_epoch_start],
|
150
|
+
"on_train_batch_start": [on_train_batch_start],
|
151
|
+
"optimizer_step": [optimizer_step],
|
152
|
+
"on_before_zero_grad": [on_before_zero_grad],
|
153
|
+
"on_train_batch_end": [on_train_batch_end],
|
154
|
+
"on_train_epoch_end": [on_train_epoch_end],
|
155
|
+
"on_fit_epoch_end": [on_fit_epoch_end], # fit = train + val
|
156
|
+
"on_model_save": [on_model_save],
|
157
|
+
"on_train_end": [on_train_end],
|
158
|
+
"on_params_update": [on_params_update],
|
159
|
+
"teardown": [teardown],
|
160
|
+
# Run in validator
|
161
|
+
"on_val_start": [on_val_start],
|
162
|
+
"on_val_batch_start": [on_val_batch_start],
|
163
|
+
"on_val_batch_end": [on_val_batch_end],
|
164
|
+
"on_val_end": [on_val_end],
|
165
|
+
# Run in predictor
|
166
|
+
"on_predict_start": [on_predict_start],
|
167
|
+
"on_predict_batch_start": [on_predict_batch_start],
|
168
|
+
"on_predict_postprocess_end": [on_predict_postprocess_end],
|
169
|
+
"on_predict_batch_end": [on_predict_batch_end],
|
170
|
+
"on_predict_end": [on_predict_end],
|
171
|
+
# Run in exporter
|
172
|
+
"on_export_start": [on_export_start],
|
173
|
+
"on_export_end": [on_export_end],
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
def get_default_callbacks():
|
178
|
+
"""
|
179
|
+
Get the default callbacks for Ultralytics training, validation, prediction, and export processes.
|
180
|
+
|
181
|
+
Returns:
|
182
|
+
(dict): Dictionary of default callbacks for various training events. Each key in the dictionary represents an
|
183
|
+
event during the training process, and the corresponding value is a list of callback functions that are
|
184
|
+
executed when that event occurs.
|
185
|
+
|
186
|
+
Examples:
|
187
|
+
>>> callbacks = get_default_callbacks()
|
188
|
+
>>> print(list(callbacks.keys())) # show all available callback events
|
189
|
+
['on_pretrain_routine_start', 'on_pretrain_routine_end', ...]
|
190
|
+
"""
|
191
|
+
return defaultdict(list, deepcopy(default_callbacks))
|
192
|
+
|
193
|
+
|
194
|
+
def add_integration_callbacks(instance):
|
195
|
+
"""
|
196
|
+
Add integration callbacks to the instance's callbacks dictionary.
|
197
|
+
|
198
|
+
This function loads and adds various integration callbacks to the provided instance. The specific callbacks added
|
199
|
+
depend on the type of instance provided. All instances receive HUB callbacks, while Trainer instances also receive
|
200
|
+
additional callbacks for various integrations like ClearML, Comet, DVC, MLflow, Neptune, Ray Tune, TensorBoard,
|
201
|
+
and Weights & Biases.
|
202
|
+
|
203
|
+
Args:
|
204
|
+
instance (Trainer | Predictor | Validator | Exporter): The object instance to which callbacks will be added.
|
205
|
+
The type of instance determines which callbacks are loaded.
|
206
|
+
|
207
|
+
Examples:
|
208
|
+
>>> from ultralytics.engine.trainer import BaseTrainer
|
209
|
+
>>> trainer = BaseTrainer()
|
210
|
+
>>> add_integration_callbacks(trainer)
|
211
|
+
"""
|
212
|
+
# Load HUB callbacks
|
213
|
+
from .hub import callbacks as hub_cb
|
214
|
+
|
215
|
+
callbacks_list = [hub_cb]
|
216
|
+
|
217
|
+
# Load training callbacks
|
218
|
+
if "Trainer" in instance.__class__.__name__:
|
219
|
+
from .clearml import callbacks as clear_cb
|
220
|
+
from .comet import callbacks as comet_cb
|
221
|
+
from .dvc import callbacks as dvc_cb
|
222
|
+
from .mlflow import callbacks as mlflow_cb
|
223
|
+
from .neptune import callbacks as neptune_cb
|
224
|
+
from .raytune import callbacks as tune_cb
|
225
|
+
from .tensorboard import callbacks as tb_cb
|
226
|
+
from .wb import callbacks as wb_cb
|
227
|
+
|
228
|
+
callbacks_list.extend([clear_cb, comet_cb, dvc_cb, mlflow_cb, neptune_cb, tune_cb, tb_cb, wb_cb])
|
229
|
+
|
230
|
+
# Add the callbacks to the callbacks dictionary
|
231
|
+
for callbacks in callbacks_list:
|
232
|
+
for k, v in callbacks.items():
|
233
|
+
if v not in instance.callbacks[k]:
|
234
|
+
instance.callbacks[k].append(v)
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
2
|
+
|
3
|
+
from ultralytics.utils import LOGGER, SETTINGS, TESTS_RUNNING
|
4
|
+
|
5
|
+
try:
|
6
|
+
assert not TESTS_RUNNING # do not log pytest
|
7
|
+
assert SETTINGS["clearml"] is True # verify integration is enabled
|
8
|
+
import clearml
|
9
|
+
from clearml import Task
|
10
|
+
|
11
|
+
assert hasattr(clearml, "__version__") # verify package is not directory
|
12
|
+
|
13
|
+
except (ImportError, AssertionError):
|
14
|
+
clearml = None
|
15
|
+
|
16
|
+
|
17
|
+
def _log_debug_samples(files, title: str = "Debug Samples") -> None:
|
18
|
+
"""
|
19
|
+
Log files (images) as debug samples in the ClearML task.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
files (List[Path]): A list of file paths in PosixPath format.
|
23
|
+
title (str): A title that groups together images with the same values.
|
24
|
+
"""
|
25
|
+
import re
|
26
|
+
|
27
|
+
if task := Task.current_task():
|
28
|
+
for f in files:
|
29
|
+
if f.exists():
|
30
|
+
it = re.search(r"_batch(\d+)", f.name)
|
31
|
+
iteration = int(it.groups()[0]) if it else 0
|
32
|
+
task.get_logger().report_image(
|
33
|
+
title=title, series=f.name.replace(it.group(), ""), local_path=str(f), iteration=iteration
|
34
|
+
)
|
35
|
+
|
36
|
+
|
37
|
+
def _log_plot(title: str, plot_path: str) -> None:
|
38
|
+
"""
|
39
|
+
Log an image as a plot in the plot section of ClearML.
|
40
|
+
|
41
|
+
Args:
|
42
|
+
title (str): The title of the plot.
|
43
|
+
plot_path (str): The path to the saved image file.
|
44
|
+
"""
|
45
|
+
import matplotlib.image as mpimg
|
46
|
+
import matplotlib.pyplot as plt
|
47
|
+
|
48
|
+
img = mpimg.imread(plot_path)
|
49
|
+
fig = plt.figure()
|
50
|
+
ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect="auto", xticks=[], yticks=[]) # no ticks
|
51
|
+
ax.imshow(img)
|
52
|
+
|
53
|
+
Task.current_task().get_logger().report_matplotlib_figure(
|
54
|
+
title=title, series="", figure=fig, report_interactive=False
|
55
|
+
)
|
56
|
+
|
57
|
+
|
58
|
+
def on_pretrain_routine_start(trainer) -> None:
|
59
|
+
"""Runs at start of pretraining routine; initializes and connects/logs task to ClearML."""
|
60
|
+
try:
|
61
|
+
if task := Task.current_task():
|
62
|
+
# WARNING: make sure the automatic pytorch and matplotlib bindings are disabled!
|
63
|
+
# We are logging these plots and model files manually in the integration
|
64
|
+
from clearml.binding.frameworks.pytorch_bind import PatchPyTorchModelIO
|
65
|
+
from clearml.binding.matplotlib_bind import PatchedMatplotlib
|
66
|
+
|
67
|
+
PatchPyTorchModelIO.update_current_task(None)
|
68
|
+
PatchedMatplotlib.update_current_task(None)
|
69
|
+
else:
|
70
|
+
task = Task.init(
|
71
|
+
project_name=trainer.args.project or "Ultralytics",
|
72
|
+
task_name=trainer.args.name,
|
73
|
+
tags=["Ultralytics"],
|
74
|
+
output_uri=True,
|
75
|
+
reuse_last_task_id=False,
|
76
|
+
auto_connect_frameworks={"pytorch": False, "matplotlib": False},
|
77
|
+
)
|
78
|
+
LOGGER.warning(
|
79
|
+
"ClearML Initialized a new task. If you want to run remotely, "
|
80
|
+
"please add clearml-init and connect your arguments before initializing YOLO."
|
81
|
+
)
|
82
|
+
task.connect(vars(trainer.args), name="General")
|
83
|
+
except Exception as e:
|
84
|
+
LOGGER.warning(f"ClearML installed but not initialized correctly, not logging this run. {e}")
|
85
|
+
|
86
|
+
|
87
|
+
def on_train_epoch_end(trainer) -> None:
|
88
|
+
"""Logs debug samples for the first epoch of YOLO training and reports current training progress."""
|
89
|
+
if task := Task.current_task():
|
90
|
+
# Log debug samples
|
91
|
+
if trainer.epoch == 1:
|
92
|
+
_log_debug_samples(sorted(trainer.save_dir.glob("train_batch*.jpg")), "Mosaic")
|
93
|
+
# Report the current training progress
|
94
|
+
for k, v in trainer.label_loss_items(trainer.tloss, prefix="train").items():
|
95
|
+
task.get_logger().report_scalar("train", k, v, iteration=trainer.epoch)
|
96
|
+
for k, v in trainer.lr.items():
|
97
|
+
task.get_logger().report_scalar("lr", k, v, iteration=trainer.epoch)
|
98
|
+
|
99
|
+
|
100
|
+
def on_fit_epoch_end(trainer) -> None:
|
101
|
+
"""Reports model information to logger at the end of an epoch."""
|
102
|
+
if task := Task.current_task():
|
103
|
+
# Report epoch time and validation metrics
|
104
|
+
task.get_logger().report_scalar(
|
105
|
+
title="Epoch Time", series="Epoch Time", value=trainer.epoch_time, iteration=trainer.epoch
|
106
|
+
)
|
107
|
+
for k, v in trainer.metrics.items():
|
108
|
+
task.get_logger().report_scalar("val", k, v, iteration=trainer.epoch)
|
109
|
+
if trainer.epoch == 0:
|
110
|
+
from ultralytics.utils.torch_utils import model_info_for_loggers
|
111
|
+
|
112
|
+
for k, v in model_info_for_loggers(trainer).items():
|
113
|
+
task.get_logger().report_single_value(k, v)
|
114
|
+
|
115
|
+
|
116
|
+
def on_val_end(validator) -> None:
|
117
|
+
"""Logs validation results including labels and predictions."""
|
118
|
+
if Task.current_task():
|
119
|
+
# Log val_labels and val_pred
|
120
|
+
_log_debug_samples(sorted(validator.save_dir.glob("val*.jpg")), "Validation")
|
121
|
+
|
122
|
+
|
123
|
+
def on_train_end(trainer) -> None:
|
124
|
+
"""Logs final model and its name on training completion."""
|
125
|
+
if task := Task.current_task():
|
126
|
+
# Log final results, CM matrix + PR plots
|
127
|
+
files = [
|
128
|
+
"results.png",
|
129
|
+
"confusion_matrix.png",
|
130
|
+
"confusion_matrix_normalized.png",
|
131
|
+
*(f"{x}_curve.png" for x in ("F1", "PR", "P", "R")),
|
132
|
+
]
|
133
|
+
files = [(trainer.save_dir / f) for f in files if (trainer.save_dir / f).exists()] # filter
|
134
|
+
for f in files:
|
135
|
+
_log_plot(title=f.stem, plot_path=f)
|
136
|
+
# Report final metrics
|
137
|
+
for k, v in trainer.validator.metrics.results_dict.items():
|
138
|
+
task.get_logger().report_single_value(k, v)
|
139
|
+
# Log the final model
|
140
|
+
task.update_output_model(model_path=str(trainer.best), model_name=trainer.args.name, auto_delete_file=False)
|
141
|
+
|
142
|
+
|
143
|
+
callbacks = (
|
144
|
+
{
|
145
|
+
"on_pretrain_routine_start": on_pretrain_routine_start,
|
146
|
+
"on_train_epoch_end": on_train_epoch_end,
|
147
|
+
"on_fit_epoch_end": on_fit_epoch_end,
|
148
|
+
"on_val_end": on_val_end,
|
149
|
+
"on_train_end": on_train_end,
|
150
|
+
}
|
151
|
+
if clearml
|
152
|
+
else {}
|
153
|
+
)
|