dgenerate-ultralytics-headless 8.3.214__py3-none-any.whl → 8.3.248__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.214.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/METADATA +13 -14
- dgenerate_ultralytics_headless-8.3.248.dist-info/RECORD +298 -0
- tests/__init__.py +5 -7
- tests/conftest.py +8 -15
- tests/test_cli.py +1 -1
- tests/test_cuda.py +5 -8
- tests/test_engine.py +1 -1
- tests/test_exports.py +57 -12
- tests/test_integrations.py +4 -4
- tests/test_python.py +84 -53
- tests/test_solutions.py +160 -151
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +56 -62
- ultralytics/cfg/datasets/Argoverse.yaml +7 -6
- ultralytics/cfg/datasets/DOTAv1.5.yaml +1 -1
- ultralytics/cfg/datasets/DOTAv1.yaml +1 -1
- ultralytics/cfg/datasets/ImageNet.yaml +1 -1
- ultralytics/cfg/datasets/VOC.yaml +15 -16
- ultralytics/cfg/datasets/african-wildlife.yaml +1 -1
- ultralytics/cfg/datasets/coco-pose.yaml +21 -0
- ultralytics/cfg/datasets/coco128-seg.yaml +1 -1
- ultralytics/cfg/datasets/coco8-pose.yaml +21 -0
- ultralytics/cfg/datasets/dog-pose.yaml +28 -0
- ultralytics/cfg/datasets/dota8-multispectral.yaml +1 -1
- ultralytics/cfg/datasets/dota8.yaml +2 -2
- ultralytics/cfg/datasets/hand-keypoints.yaml +26 -2
- ultralytics/cfg/datasets/kitti.yaml +27 -0
- ultralytics/cfg/datasets/lvis.yaml +5 -5
- ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
- ultralytics/cfg/datasets/tiger-pose.yaml +16 -0
- ultralytics/cfg/datasets/xView.yaml +16 -16
- ultralytics/cfg/default.yaml +1 -1
- ultralytics/cfg/models/11/yolo11-pose.yaml +1 -1
- ultralytics/cfg/models/11/yoloe-11-seg.yaml +2 -2
- ultralytics/cfg/models/11/yoloe-11.yaml +2 -2
- ultralytics/cfg/models/rt-detr/rtdetr-l.yaml +1 -1
- ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml +1 -1
- ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml +1 -1
- ultralytics/cfg/models/rt-detr/rtdetr-x.yaml +1 -1
- ultralytics/cfg/models/v10/yolov10b.yaml +2 -2
- ultralytics/cfg/models/v10/yolov10l.yaml +2 -2
- ultralytics/cfg/models/v10/yolov10m.yaml +2 -2
- ultralytics/cfg/models/v10/yolov10n.yaml +2 -2
- ultralytics/cfg/models/v10/yolov10s.yaml +2 -2
- ultralytics/cfg/models/v10/yolov10x.yaml +2 -2
- ultralytics/cfg/models/v3/yolov3-tiny.yaml +1 -1
- ultralytics/cfg/models/v6/yolov6.yaml +1 -1
- ultralytics/cfg/models/v8/yoloe-v8-seg.yaml +9 -6
- ultralytics/cfg/models/v8/yoloe-v8.yaml +9 -6
- ultralytics/cfg/models/v8/yolov8-cls-resnet101.yaml +1 -1
- ultralytics/cfg/models/v8/yolov8-cls-resnet50.yaml +1 -1
- ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +2 -2
- ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +2 -2
- ultralytics/cfg/models/v8/yolov8-ghost.yaml +2 -2
- ultralytics/cfg/models/v8/yolov8-obb.yaml +1 -1
- ultralytics/cfg/models/v8/yolov8-p2.yaml +1 -1
- ultralytics/cfg/models/v8/yolov8-pose-p6.yaml +1 -1
- ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +1 -1
- ultralytics/cfg/models/v8/yolov8-seg-p6.yaml +1 -1
- ultralytics/cfg/models/v8/yolov8-world.yaml +1 -1
- ultralytics/cfg/models/v8/yolov8-worldv2.yaml +6 -6
- ultralytics/cfg/models/v9/yolov9s.yaml +1 -1
- ultralytics/data/__init__.py +4 -4
- ultralytics/data/annotator.py +3 -4
- ultralytics/data/augment.py +285 -475
- ultralytics/data/base.py +18 -26
- ultralytics/data/build.py +147 -25
- ultralytics/data/converter.py +36 -46
- ultralytics/data/dataset.py +46 -74
- ultralytics/data/loaders.py +42 -49
- ultralytics/data/split.py +5 -6
- ultralytics/data/split_dota.py +8 -15
- ultralytics/data/utils.py +34 -43
- ultralytics/engine/exporter.py +319 -237
- ultralytics/engine/model.py +148 -188
- ultralytics/engine/predictor.py +29 -38
- ultralytics/engine/results.py +177 -311
- ultralytics/engine/trainer.py +83 -59
- ultralytics/engine/tuner.py +23 -34
- ultralytics/engine/validator.py +39 -22
- ultralytics/hub/__init__.py +16 -19
- ultralytics/hub/auth.py +6 -12
- ultralytics/hub/google/__init__.py +7 -10
- ultralytics/hub/session.py +15 -25
- ultralytics/hub/utils.py +5 -8
- ultralytics/models/__init__.py +1 -1
- ultralytics/models/fastsam/__init__.py +1 -1
- ultralytics/models/fastsam/model.py +8 -10
- ultralytics/models/fastsam/predict.py +17 -29
- ultralytics/models/fastsam/utils.py +1 -2
- ultralytics/models/fastsam/val.py +5 -7
- ultralytics/models/nas/__init__.py +1 -1
- ultralytics/models/nas/model.py +5 -8
- ultralytics/models/nas/predict.py +7 -9
- ultralytics/models/nas/val.py +1 -2
- ultralytics/models/rtdetr/__init__.py +1 -1
- ultralytics/models/rtdetr/model.py +5 -8
- ultralytics/models/rtdetr/predict.py +15 -19
- ultralytics/models/rtdetr/train.py +10 -13
- ultralytics/models/rtdetr/val.py +21 -23
- ultralytics/models/sam/__init__.py +15 -2
- ultralytics/models/sam/amg.py +14 -20
- ultralytics/models/sam/build.py +26 -19
- ultralytics/models/sam/build_sam3.py +377 -0
- ultralytics/models/sam/model.py +29 -32
- ultralytics/models/sam/modules/blocks.py +83 -144
- ultralytics/models/sam/modules/decoders.py +19 -37
- ultralytics/models/sam/modules/encoders.py +44 -101
- ultralytics/models/sam/modules/memory_attention.py +16 -30
- ultralytics/models/sam/modules/sam.py +200 -73
- ultralytics/models/sam/modules/tiny_encoder.py +64 -83
- ultralytics/models/sam/modules/transformer.py +18 -28
- ultralytics/models/sam/modules/utils.py +174 -50
- ultralytics/models/sam/predict.py +2248 -350
- ultralytics/models/sam/sam3/__init__.py +3 -0
- ultralytics/models/sam/sam3/decoder.py +546 -0
- ultralytics/models/sam/sam3/encoder.py +529 -0
- ultralytics/models/sam/sam3/geometry_encoders.py +415 -0
- ultralytics/models/sam/sam3/maskformer_segmentation.py +286 -0
- ultralytics/models/sam/sam3/model_misc.py +199 -0
- ultralytics/models/sam/sam3/necks.py +129 -0
- ultralytics/models/sam/sam3/sam3_image.py +339 -0
- ultralytics/models/sam/sam3/text_encoder_ve.py +307 -0
- ultralytics/models/sam/sam3/vitdet.py +547 -0
- ultralytics/models/sam/sam3/vl_combiner.py +160 -0
- ultralytics/models/utils/loss.py +14 -26
- ultralytics/models/utils/ops.py +13 -17
- ultralytics/models/yolo/__init__.py +1 -1
- ultralytics/models/yolo/classify/predict.py +9 -12
- ultralytics/models/yolo/classify/train.py +11 -32
- ultralytics/models/yolo/classify/val.py +29 -28
- ultralytics/models/yolo/detect/predict.py +7 -10
- ultralytics/models/yolo/detect/train.py +11 -20
- ultralytics/models/yolo/detect/val.py +70 -58
- ultralytics/models/yolo/model.py +36 -53
- ultralytics/models/yolo/obb/predict.py +5 -14
- ultralytics/models/yolo/obb/train.py +11 -14
- ultralytics/models/yolo/obb/val.py +39 -36
- ultralytics/models/yolo/pose/__init__.py +1 -1
- ultralytics/models/yolo/pose/predict.py +6 -21
- ultralytics/models/yolo/pose/train.py +10 -15
- ultralytics/models/yolo/pose/val.py +38 -57
- ultralytics/models/yolo/segment/predict.py +14 -18
- ultralytics/models/yolo/segment/train.py +3 -6
- ultralytics/models/yolo/segment/val.py +93 -45
- ultralytics/models/yolo/world/train.py +8 -14
- ultralytics/models/yolo/world/train_world.py +11 -34
- ultralytics/models/yolo/yoloe/__init__.py +7 -7
- ultralytics/models/yolo/yoloe/predict.py +16 -23
- ultralytics/models/yolo/yoloe/train.py +30 -43
- ultralytics/models/yolo/yoloe/train_seg.py +5 -10
- ultralytics/models/yolo/yoloe/val.py +15 -20
- ultralytics/nn/__init__.py +7 -7
- ultralytics/nn/autobackend.py +145 -77
- ultralytics/nn/modules/__init__.py +60 -60
- ultralytics/nn/modules/activation.py +4 -6
- ultralytics/nn/modules/block.py +132 -216
- ultralytics/nn/modules/conv.py +52 -97
- ultralytics/nn/modules/head.py +50 -103
- ultralytics/nn/modules/transformer.py +76 -88
- ultralytics/nn/modules/utils.py +16 -21
- ultralytics/nn/tasks.py +94 -154
- ultralytics/nn/text_model.py +40 -67
- ultralytics/solutions/__init__.py +12 -12
- ultralytics/solutions/ai_gym.py +11 -17
- ultralytics/solutions/analytics.py +15 -16
- ultralytics/solutions/config.py +5 -6
- ultralytics/solutions/distance_calculation.py +10 -13
- ultralytics/solutions/heatmap.py +7 -13
- ultralytics/solutions/instance_segmentation.py +5 -8
- ultralytics/solutions/object_blurrer.py +7 -10
- ultralytics/solutions/object_counter.py +12 -19
- ultralytics/solutions/object_cropper.py +8 -14
- ultralytics/solutions/parking_management.py +33 -31
- ultralytics/solutions/queue_management.py +10 -12
- ultralytics/solutions/region_counter.py +9 -12
- ultralytics/solutions/security_alarm.py +15 -20
- ultralytics/solutions/similarity_search.py +10 -15
- ultralytics/solutions/solutions.py +75 -74
- ultralytics/solutions/speed_estimation.py +7 -10
- ultralytics/solutions/streamlit_inference.py +2 -4
- ultralytics/solutions/templates/similarity-search.html +7 -18
- ultralytics/solutions/trackzone.py +7 -10
- ultralytics/solutions/vision_eye.py +5 -8
- ultralytics/trackers/__init__.py +1 -1
- ultralytics/trackers/basetrack.py +3 -5
- ultralytics/trackers/bot_sort.py +10 -27
- ultralytics/trackers/byte_tracker.py +14 -30
- ultralytics/trackers/track.py +3 -6
- ultralytics/trackers/utils/gmc.py +11 -22
- ultralytics/trackers/utils/kalman_filter.py +37 -48
- ultralytics/trackers/utils/matching.py +12 -15
- ultralytics/utils/__init__.py +116 -116
- ultralytics/utils/autobatch.py +2 -4
- ultralytics/utils/autodevice.py +17 -18
- ultralytics/utils/benchmarks.py +32 -46
- ultralytics/utils/callbacks/base.py +8 -10
- ultralytics/utils/callbacks/clearml.py +5 -13
- ultralytics/utils/callbacks/comet.py +32 -46
- ultralytics/utils/callbacks/dvc.py +13 -18
- ultralytics/utils/callbacks/mlflow.py +4 -5
- ultralytics/utils/callbacks/neptune.py +7 -15
- ultralytics/utils/callbacks/platform.py +314 -38
- ultralytics/utils/callbacks/raytune.py +3 -4
- ultralytics/utils/callbacks/tensorboard.py +23 -31
- ultralytics/utils/callbacks/wb.py +10 -13
- ultralytics/utils/checks.py +99 -76
- ultralytics/utils/cpu.py +3 -8
- ultralytics/utils/dist.py +8 -12
- ultralytics/utils/downloads.py +20 -30
- ultralytics/utils/errors.py +6 -14
- ultralytics/utils/events.py +2 -4
- ultralytics/utils/export/__init__.py +4 -236
- ultralytics/utils/export/engine.py +237 -0
- ultralytics/utils/export/imx.py +91 -55
- ultralytics/utils/export/tensorflow.py +231 -0
- ultralytics/utils/files.py +24 -28
- ultralytics/utils/git.py +9 -11
- ultralytics/utils/instance.py +30 -51
- ultralytics/utils/logger.py +212 -114
- ultralytics/utils/loss.py +14 -22
- ultralytics/utils/metrics.py +126 -155
- ultralytics/utils/nms.py +13 -16
- ultralytics/utils/ops.py +107 -165
- ultralytics/utils/patches.py +33 -21
- ultralytics/utils/plotting.py +72 -80
- ultralytics/utils/tal.py +25 -39
- ultralytics/utils/torch_utils.py +52 -78
- ultralytics/utils/tqdm.py +20 -20
- ultralytics/utils/triton.py +13 -19
- ultralytics/utils/tuner.py +17 -5
- dgenerate_ultralytics_headless-8.3.214.dist-info/RECORD +0 -283
- {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.3.248.dist-info}/top_level.txt +0 -0
ultralytics/hub/__init__.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
3
5
|
from ultralytics.data.utils import HUBDatasetStats
|
|
4
6
|
from ultralytics.hub.auth import Auth
|
|
5
7
|
from ultralytics.hub.session import HUBTrainingSession
|
|
@@ -7,29 +9,28 @@ from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX
|
|
|
7
9
|
from ultralytics.utils import LOGGER, SETTINGS, checks
|
|
8
10
|
|
|
9
11
|
__all__ = (
|
|
10
|
-
"PREFIX",
|
|
11
12
|
"HUB_WEB_ROOT",
|
|
13
|
+
"PREFIX",
|
|
12
14
|
"HUBTrainingSession",
|
|
13
|
-
"
|
|
14
|
-
"logout",
|
|
15
|
-
"reset_model",
|
|
15
|
+
"check_dataset",
|
|
16
16
|
"export_fmts_hub",
|
|
17
17
|
"export_model",
|
|
18
18
|
"get_export",
|
|
19
|
-
"
|
|
19
|
+
"login",
|
|
20
|
+
"logout",
|
|
21
|
+
"reset_model",
|
|
20
22
|
)
|
|
21
23
|
|
|
22
24
|
|
|
23
|
-
def login(api_key: str = None, save: bool = True) -> bool:
|
|
24
|
-
"""
|
|
25
|
-
Log in to the Ultralytics HUB API using the provided API key.
|
|
25
|
+
def login(api_key: str | None = None, save: bool = True) -> bool:
|
|
26
|
+
"""Log in to the Ultralytics HUB API using the provided API key.
|
|
26
27
|
|
|
27
28
|
The session is not stored; a new session is created when needed using the saved SETTINGS or the HUB_API_KEY
|
|
28
29
|
environment variable if successfully authenticated.
|
|
29
30
|
|
|
30
31
|
Args:
|
|
31
|
-
api_key (str, optional): API key to use for authentication. If not provided, it will be retrieved from
|
|
32
|
-
|
|
32
|
+
api_key (str, optional): API key to use for authentication. If not provided, it will be retrieved from SETTINGS
|
|
33
|
+
or HUB_API_KEY environment variable.
|
|
33
34
|
save (bool, optional): Whether to save the API key to SETTINGS if authentication is successful.
|
|
34
35
|
|
|
35
36
|
Returns:
|
|
@@ -85,12 +86,11 @@ def export_fmts_hub():
|
|
|
85
86
|
"""Return a list of HUB-supported export formats."""
|
|
86
87
|
from ultralytics.engine.exporter import export_formats
|
|
87
88
|
|
|
88
|
-
return list(export_formats()["Argument"][1:])
|
|
89
|
+
return [*list(export_formats()["Argument"][1:]), "ultralytics_tflite", "ultralytics_coreml"]
|
|
89
90
|
|
|
90
91
|
|
|
91
92
|
def export_model(model_id: str = "", format: str = "torchscript"):
|
|
92
|
-
"""
|
|
93
|
-
Export a model to a specified format for deployment via the Ultralytics HUB API.
|
|
93
|
+
"""Export a model to a specified format for deployment via the Ultralytics HUB API.
|
|
94
94
|
|
|
95
95
|
Args:
|
|
96
96
|
model_id (str): The ID of the model to export. An empty string will use the default model.
|
|
@@ -115,13 +115,11 @@ def export_model(model_id: str = "", format: str = "torchscript"):
|
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
def get_export(model_id: str = "", format: str = "torchscript"):
|
|
118
|
-
"""
|
|
119
|
-
Retrieve an exported model in the specified format from Ultralytics HUB using the model ID.
|
|
118
|
+
"""Retrieve an exported model in the specified format from Ultralytics HUB using the model ID.
|
|
120
119
|
|
|
121
120
|
Args:
|
|
122
121
|
model_id (str): The ID of the model to retrieve from Ultralytics HUB.
|
|
123
|
-
format (str): The export format to retrieve. Must be one of the supported formats returned by
|
|
124
|
-
export_fmts_hub().
|
|
122
|
+
format (str): The export format to retrieve. Must be one of the supported formats returned by export_fmts_hub().
|
|
125
123
|
|
|
126
124
|
Returns:
|
|
127
125
|
(dict): JSON response containing the exported model information.
|
|
@@ -146,8 +144,7 @@ def get_export(model_id: str = "", format: str = "torchscript"):
|
|
|
146
144
|
|
|
147
145
|
|
|
148
146
|
def check_dataset(path: str, task: str) -> None:
|
|
149
|
-
"""
|
|
150
|
-
Check HUB dataset Zip file for errors before upload.
|
|
147
|
+
"""Check HUB dataset Zip file for errors before upload.
|
|
151
148
|
|
|
152
149
|
Args:
|
|
153
150
|
path (str): Path to data.zip (with data.yaml inside data.zip).
|
ultralytics/hub/auth.py
CHANGED
|
@@ -7,8 +7,7 @@ API_KEY_URL = f"{HUB_WEB_ROOT}/settings?tab=api+keys"
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class Auth:
|
|
10
|
-
"""
|
|
11
|
-
Manages authentication processes including API key handling, cookie-based authentication, and header generation.
|
|
10
|
+
"""Manages authentication processes including API key handling, cookie-based authentication, and header generation.
|
|
12
11
|
|
|
13
12
|
The class supports different methods of authentication:
|
|
14
13
|
1. Directly using an API key.
|
|
@@ -37,8 +36,7 @@ class Auth:
|
|
|
37
36
|
id_token = api_key = model_key = False
|
|
38
37
|
|
|
39
38
|
def __init__(self, api_key: str = "", verbose: bool = False):
|
|
40
|
-
"""
|
|
41
|
-
Initialize Auth class and authenticate user.
|
|
39
|
+
"""Initialize Auth class and authenticate user.
|
|
42
40
|
|
|
43
41
|
Handles API key validation, Google Colab authentication, and new key requests. Updates SETTINGS upon successful
|
|
44
42
|
authentication.
|
|
@@ -82,8 +80,7 @@ class Auth:
|
|
|
82
80
|
LOGGER.info(f"{PREFIX}Get API key from {API_KEY_URL} and then run 'yolo login API_KEY'")
|
|
83
81
|
|
|
84
82
|
def request_api_key(self, max_attempts: int = 3) -> bool:
|
|
85
|
-
"""
|
|
86
|
-
Prompt the user to input their API key.
|
|
83
|
+
"""Prompt the user to input their API key.
|
|
87
84
|
|
|
88
85
|
Args:
|
|
89
86
|
max_attempts (int): Maximum number of authentication attempts.
|
|
@@ -102,8 +99,7 @@ class Auth:
|
|
|
102
99
|
raise ConnectionError(emojis(f"{PREFIX}Failed to authenticate ❌"))
|
|
103
100
|
|
|
104
101
|
def authenticate(self) -> bool:
|
|
105
|
-
"""
|
|
106
|
-
Attempt to authenticate with the server using either id_token or API key.
|
|
102
|
+
"""Attempt to authenticate with the server using either id_token or API key.
|
|
107
103
|
|
|
108
104
|
Returns:
|
|
109
105
|
(bool): True if authentication is successful, False otherwise.
|
|
@@ -123,8 +119,7 @@ class Auth:
|
|
|
123
119
|
return False
|
|
124
120
|
|
|
125
121
|
def auth_with_cookies(self) -> bool:
|
|
126
|
-
"""
|
|
127
|
-
Attempt to fetch authentication via cookies and set id_token.
|
|
122
|
+
"""Attempt to fetch authentication via cookies and set id_token.
|
|
128
123
|
|
|
129
124
|
User must be logged in to HUB and running in a supported browser.
|
|
130
125
|
|
|
@@ -145,8 +140,7 @@ class Auth:
|
|
|
145
140
|
return False
|
|
146
141
|
|
|
147
142
|
def get_auth_header(self):
|
|
148
|
-
"""
|
|
149
|
-
Get the authentication header for making API requests.
|
|
143
|
+
"""Get the authentication header for making API requests.
|
|
150
144
|
|
|
151
145
|
Returns:
|
|
152
146
|
(dict | None): The authentication header if id_token or API key is set, None otherwise.
|
|
@@ -8,11 +8,10 @@ import time
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class GCPRegions:
|
|
11
|
-
"""
|
|
12
|
-
A class for managing and analyzing Google Cloud Platform (GCP) regions.
|
|
11
|
+
"""A class for managing and analyzing Google Cloud Platform (GCP) regions.
|
|
13
12
|
|
|
14
|
-
This class provides functionality to initialize, categorize, and analyze GCP regions based on their
|
|
15
|
-
|
|
13
|
+
This class provides functionality to initialize, categorize, and analyze GCP regions based on their geographical
|
|
14
|
+
location, tier classification, and network latency.
|
|
16
15
|
|
|
17
16
|
Attributes:
|
|
18
17
|
regions (dict[str, tuple[int, str, str]]): A dictionary of GCP regions with their tier, city, and country.
|
|
@@ -82,8 +81,7 @@ class GCPRegions:
|
|
|
82
81
|
|
|
83
82
|
@staticmethod
|
|
84
83
|
def _ping_region(region: str, attempts: int = 1) -> tuple[str, float, float, float, float]:
|
|
85
|
-
"""
|
|
86
|
-
Ping a specified GCP region and measure network latency statistics.
|
|
84
|
+
"""Ping a specified GCP region and measure network latency statistics.
|
|
87
85
|
|
|
88
86
|
Args:
|
|
89
87
|
region (str): The GCP region identifier to ping (e.g., 'us-central1').
|
|
@@ -126,8 +124,7 @@ class GCPRegions:
|
|
|
126
124
|
tier: int | None = None,
|
|
127
125
|
attempts: int = 1,
|
|
128
126
|
) -> list[tuple[str, float, float, float, float]]:
|
|
129
|
-
"""
|
|
130
|
-
Determine the GCP regions with the lowest latency based on ping tests.
|
|
127
|
+
"""Determine the GCP regions with the lowest latency based on ping tests.
|
|
131
128
|
|
|
132
129
|
Args:
|
|
133
130
|
top (int, optional): Number of top regions to return.
|
|
@@ -136,8 +133,8 @@ class GCPRegions:
|
|
|
136
133
|
attempts (int, optional): Number of ping attempts per region.
|
|
137
134
|
|
|
138
135
|
Returns:
|
|
139
|
-
(list[tuple[str, float, float, float, float]]): List of tuples containing region information and
|
|
140
|
-
|
|
136
|
+
(list[tuple[str, float, float, float, float]]): List of tuples containing region information and latency
|
|
137
|
+
statistics. Each tuple contains (region, mean_latency, std_dev, min_latency, max_latency).
|
|
141
138
|
|
|
142
139
|
Examples:
|
|
143
140
|
>>> regions = GCPRegions()
|
ultralytics/hub/session.py
CHANGED
|
@@ -19,8 +19,7 @@ AGENT_NAME = f"python-{__version__}-colab" if IS_COLAB else f"python-{__version_
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class HUBTrainingSession:
|
|
22
|
-
"""
|
|
23
|
-
HUB training session for Ultralytics HUB YOLO models.
|
|
22
|
+
"""HUB training session for Ultralytics HUB YOLO models.
|
|
24
23
|
|
|
25
24
|
This class encapsulates the functionality for interacting with Ultralytics HUB during model training, including
|
|
26
25
|
model creation, metrics tracking, and checkpoint uploading.
|
|
@@ -45,12 +44,11 @@ class HUBTrainingSession:
|
|
|
45
44
|
"""
|
|
46
45
|
|
|
47
46
|
def __init__(self, identifier: str):
|
|
48
|
-
"""
|
|
49
|
-
Initialize the HUBTrainingSession with the provided model identifier.
|
|
47
|
+
"""Initialize the HUBTrainingSession with the provided model identifier.
|
|
50
48
|
|
|
51
49
|
Args:
|
|
52
|
-
identifier (str): Model identifier used to initialize the HUB training session. It can be a URL string
|
|
53
|
-
|
|
50
|
+
identifier (str): Model identifier used to initialize the HUB training session. It can be a URL string or a
|
|
51
|
+
model key with specific format.
|
|
54
52
|
|
|
55
53
|
Raises:
|
|
56
54
|
ValueError: If the provided model identifier is invalid.
|
|
@@ -93,8 +91,7 @@ class HUBTrainingSession:
|
|
|
93
91
|
|
|
94
92
|
@classmethod
|
|
95
93
|
def create_session(cls, identifier: str, args: dict[str, Any] | None = None):
|
|
96
|
-
"""
|
|
97
|
-
Create an authenticated HUBTrainingSession or return None.
|
|
94
|
+
"""Create an authenticated HUBTrainingSession or return None.
|
|
98
95
|
|
|
99
96
|
Args:
|
|
100
97
|
identifier (str): Model identifier used to initialize the HUB training session.
|
|
@@ -114,8 +111,7 @@ class HUBTrainingSession:
|
|
|
114
111
|
return None
|
|
115
112
|
|
|
116
113
|
def load_model(self, model_id: str):
|
|
117
|
-
"""
|
|
118
|
-
Load an existing model from Ultralytics HUB using the provided model identifier.
|
|
114
|
+
"""Load an existing model from Ultralytics HUB using the provided model identifier.
|
|
119
115
|
|
|
120
116
|
Args:
|
|
121
117
|
model_id (str): The identifier of the model to load.
|
|
@@ -140,8 +136,7 @@ class HUBTrainingSession:
|
|
|
140
136
|
LOGGER.info(f"{PREFIX}View model at {self.model_url} 🚀")
|
|
141
137
|
|
|
142
138
|
def create_model(self, model_args: dict[str, Any]):
|
|
143
|
-
"""
|
|
144
|
-
Initialize a HUB training session with the specified model arguments.
|
|
139
|
+
"""Initialize a HUB training session with the specified model arguments.
|
|
145
140
|
|
|
146
141
|
Args:
|
|
147
142
|
model_args (dict[str, Any]): Arguments for creating the model, including batch size, epochs, image size,
|
|
@@ -186,8 +181,7 @@ class HUBTrainingSession:
|
|
|
186
181
|
|
|
187
182
|
@staticmethod
|
|
188
183
|
def _parse_identifier(identifier: str):
|
|
189
|
-
"""
|
|
190
|
-
Parse the given identifier to determine the type and extract relevant components.
|
|
184
|
+
"""Parse the given identifier to determine the type and extract relevant components.
|
|
191
185
|
|
|
192
186
|
The method supports different identifier formats:
|
|
193
187
|
- A HUB model URL https://hub.ultralytics.com/models/MODEL
|
|
@@ -218,12 +212,11 @@ class HUBTrainingSession:
|
|
|
218
212
|
return api_key, model_id, filename
|
|
219
213
|
|
|
220
214
|
def _set_train_args(self):
|
|
221
|
-
"""
|
|
222
|
-
Initialize training arguments and create a model entry on the Ultralytics HUB.
|
|
215
|
+
"""Initialize training arguments and create a model entry on the Ultralytics HUB.
|
|
223
216
|
|
|
224
|
-
This method sets up training arguments based on the model's state and updates them with any additional
|
|
225
|
-
|
|
226
|
-
|
|
217
|
+
This method sets up training arguments based on the model's state and updates them with any additional arguments
|
|
218
|
+
provided. It handles different states of the model, such as whether it's resumable, pretrained, or requires
|
|
219
|
+
specific file setup.
|
|
227
220
|
|
|
228
221
|
Raises:
|
|
229
222
|
ValueError: If the model is already trained, if required dataset information is missing, or if there are
|
|
@@ -261,8 +254,7 @@ class HUBTrainingSession:
|
|
|
261
254
|
*args,
|
|
262
255
|
**kwargs,
|
|
263
256
|
):
|
|
264
|
-
"""
|
|
265
|
-
Execute request_func with retries, timeout handling, optional threading, and progress tracking.
|
|
257
|
+
"""Execute request_func with retries, timeout handling, optional threading, and progress tracking.
|
|
266
258
|
|
|
267
259
|
Args:
|
|
268
260
|
request_func (callable): The function to execute.
|
|
@@ -342,8 +334,7 @@ class HUBTrainingSession:
|
|
|
342
334
|
return status_code in retry_codes
|
|
343
335
|
|
|
344
336
|
def _get_failure_message(self, response, retry: int, timeout: int) -> str:
|
|
345
|
-
"""
|
|
346
|
-
Generate a retry message based on the response status code.
|
|
337
|
+
"""Generate a retry message based on the response status code.
|
|
347
338
|
|
|
348
339
|
Args:
|
|
349
340
|
response (requests.Response): The HTTP response object.
|
|
@@ -379,8 +370,7 @@ class HUBTrainingSession:
|
|
|
379
370
|
map: float = 0.0,
|
|
380
371
|
final: bool = False,
|
|
381
372
|
) -> None:
|
|
382
|
-
"""
|
|
383
|
-
Upload a model checkpoint to Ultralytics HUB.
|
|
373
|
+
"""Upload a model checkpoint to Ultralytics HUB.
|
|
384
374
|
|
|
385
375
|
Args:
|
|
386
376
|
epoch (int): The current training epoch.
|
ultralytics/hub/utils.py
CHANGED
|
@@ -21,8 +21,7 @@ HELP_MSG = "If this issue persists please visit https://github.com/ultralytics/h
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def request_with_credentials(url: str) -> Any:
|
|
24
|
-
"""
|
|
25
|
-
Make an AJAX request with cookies attached in a Google Colab environment.
|
|
24
|
+
"""Make an AJAX request with cookies attached in a Google Colab environment.
|
|
26
25
|
|
|
27
26
|
Args:
|
|
28
27
|
url (str): The URL to make the request to.
|
|
@@ -35,8 +34,8 @@ def request_with_credentials(url: str) -> Any:
|
|
|
35
34
|
"""
|
|
36
35
|
if not IS_COLAB:
|
|
37
36
|
raise OSError("request_with_credentials() must run in a Colab environment")
|
|
38
|
-
from google.colab import output
|
|
39
|
-
from IPython import display
|
|
37
|
+
from google.colab import output
|
|
38
|
+
from IPython import display
|
|
40
39
|
|
|
41
40
|
display.display(
|
|
42
41
|
display.Javascript(
|
|
@@ -62,8 +61,7 @@ def request_with_credentials(url: str) -> Any:
|
|
|
62
61
|
|
|
63
62
|
|
|
64
63
|
def requests_with_progress(method: str, url: str, **kwargs):
|
|
65
|
-
"""
|
|
66
|
-
Make an HTTP request using the specified method and URL, with an optional progress bar.
|
|
64
|
+
"""Make an HTTP request using the specified method and URL, with an optional progress bar.
|
|
67
65
|
|
|
68
66
|
Args:
|
|
69
67
|
method (str): The HTTP method to use (e.g. 'GET', 'POST').
|
|
@@ -106,8 +104,7 @@ def smart_request(
|
|
|
106
104
|
progress: bool = False,
|
|
107
105
|
**kwargs,
|
|
108
106
|
):
|
|
109
|
-
"""
|
|
110
|
-
Make an HTTP request using the 'requests' library, with exponential backoff retries up to a specified timeout.
|
|
107
|
+
"""Make an HTTP request using the 'requests' library, with exponential backoff retries up to a specified timeout.
|
|
111
108
|
|
|
112
109
|
Args:
|
|
113
110
|
method (str): The HTTP method to use for the request. Choices are 'post' and 'get'.
|
ultralytics/models/__init__.py
CHANGED
|
@@ -6,4 +6,4 @@ from .rtdetr import RTDETR
|
|
|
6
6
|
from .sam import SAM
|
|
7
7
|
from .yolo import YOLO, YOLOE, YOLOWorld
|
|
8
8
|
|
|
9
|
-
__all__ = "
|
|
9
|
+
__all__ = "NAS", "RTDETR", "SAM", "YOLO", "YOLOE", "FastSAM", "YOLOWorld" # allow simpler import
|
|
@@ -12,8 +12,7 @@ from .val import FastSAMValidator
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class FastSAM(Model):
|
|
15
|
-
"""
|
|
16
|
-
FastSAM model interface for segment anything tasks.
|
|
15
|
+
"""FastSAM model interface for Segment Anything tasks.
|
|
17
16
|
|
|
18
17
|
This class extends the base Model class to provide specific functionality for the FastSAM (Fast Segment Anything
|
|
19
18
|
Model) implementation, allowing for efficient and accurate image segmentation with optional prompting support.
|
|
@@ -36,11 +35,11 @@ class FastSAM(Model):
|
|
|
36
35
|
>>> results = model.predict("image.jpg", bboxes=[[100, 100, 200, 200]])
|
|
37
36
|
"""
|
|
38
37
|
|
|
39
|
-
def __init__(self, model: str = "FastSAM-x.pt"):
|
|
38
|
+
def __init__(self, model: str | Path = "FastSAM-x.pt"):
|
|
40
39
|
"""Initialize the FastSAM model with the specified pre-trained weights."""
|
|
41
40
|
if str(model) == "FastSAM.pt":
|
|
42
41
|
model = "FastSAM-x.pt"
|
|
43
|
-
assert Path(model).suffix not in {".yaml", ".yml"}, "FastSAM
|
|
42
|
+
assert Path(model).suffix not in {".yaml", ".yml"}, "FastSAM only supports pre-trained weights."
|
|
44
43
|
super().__init__(model=model, task="segment")
|
|
45
44
|
|
|
46
45
|
def predict(
|
|
@@ -53,15 +52,14 @@ class FastSAM(Model):
|
|
|
53
52
|
texts: list | None = None,
|
|
54
53
|
**kwargs: Any,
|
|
55
54
|
):
|
|
56
|
-
"""
|
|
57
|
-
Perform segmentation prediction on image or video source.
|
|
55
|
+
"""Perform segmentation prediction on image or video source.
|
|
58
56
|
|
|
59
|
-
Supports prompted segmentation with bounding boxes, points, labels, and texts. The method packages these
|
|
60
|
-
|
|
57
|
+
Supports prompted segmentation with bounding boxes, points, labels, and texts. The method packages these prompts
|
|
58
|
+
and passes them to the parent class predict method for processing.
|
|
61
59
|
|
|
62
60
|
Args:
|
|
63
|
-
source (str | PIL.Image | np.ndarray): Input source for prediction, can be a file path, URL, PIL image,
|
|
64
|
-
|
|
61
|
+
source (str | PIL.Image | np.ndarray): Input source for prediction, can be a file path, URL, PIL image, or
|
|
62
|
+
numpy array.
|
|
65
63
|
stream (bool): Whether to enable real-time streaming mode for video inputs.
|
|
66
64
|
bboxes (list, optional): Bounding box coordinates for prompted segmentation in format [[x1, y1, x2, y2]].
|
|
67
65
|
points (list, optional): Point coordinates for prompted segmentation in format [[x, y]].
|
|
@@ -4,7 +4,7 @@ import torch
|
|
|
4
4
|
from PIL import Image
|
|
5
5
|
|
|
6
6
|
from ultralytics.models.yolo.segment import SegmentationPredictor
|
|
7
|
-
from ultralytics.utils import DEFAULT_CFG
|
|
7
|
+
from ultralytics.utils import DEFAULT_CFG
|
|
8
8
|
from ultralytics.utils.metrics import box_iou
|
|
9
9
|
from ultralytics.utils.ops import scale_masks
|
|
10
10
|
from ultralytics.utils.torch_utils import TORCH_1_10
|
|
@@ -13,8 +13,7 @@ from .utils import adjust_bboxes_to_image_border
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class FastSAMPredictor(SegmentationPredictor):
|
|
16
|
-
"""
|
|
17
|
-
FastSAMPredictor is specialized for fast SAM (Segment Anything Model) segmentation prediction tasks.
|
|
16
|
+
"""FastSAMPredictor is specialized for fast SAM (Segment Anything Model) segmentation prediction tasks.
|
|
18
17
|
|
|
19
18
|
This class extends the SegmentationPredictor, customizing the prediction pipeline specifically for fast SAM. It
|
|
20
19
|
adjusts post-processing steps to incorporate mask prediction and non-maximum suppression while optimizing for
|
|
@@ -23,8 +22,7 @@ class FastSAMPredictor(SegmentationPredictor):
|
|
|
23
22
|
Attributes:
|
|
24
23
|
prompts (dict): Dictionary containing prompt information for segmentation (bboxes, points, labels, texts).
|
|
25
24
|
device (torch.device): Device on which model and tensors are processed.
|
|
26
|
-
|
|
27
|
-
clip_preprocess (Any, optional): CLIP preprocessing function for images, loaded on demand.
|
|
25
|
+
clip (Any, optional): CLIP model used for text-based prompting, loaded on demand.
|
|
28
26
|
|
|
29
27
|
Methods:
|
|
30
28
|
postprocess: Apply postprocessing to FastSAM predictions and handle prompts.
|
|
@@ -33,8 +31,7 @@ class FastSAMPredictor(SegmentationPredictor):
|
|
|
33
31
|
"""
|
|
34
32
|
|
|
35
33
|
def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
|
|
36
|
-
"""
|
|
37
|
-
Initialize the FastSAMPredictor with configuration and callbacks.
|
|
34
|
+
"""Initialize the FastSAMPredictor with configuration and callbacks.
|
|
38
35
|
|
|
39
36
|
This initializes a predictor specialized for Fast SAM (Segment Anything Model) segmentation tasks. The predictor
|
|
40
37
|
extends SegmentationPredictor with custom post-processing for mask prediction and non-maximum suppression
|
|
@@ -49,8 +46,7 @@ class FastSAMPredictor(SegmentationPredictor):
|
|
|
49
46
|
self.prompts = {}
|
|
50
47
|
|
|
51
48
|
def postprocess(self, preds, img, orig_imgs):
|
|
52
|
-
"""
|
|
53
|
-
Apply postprocessing to FastSAM predictions and handle prompts.
|
|
49
|
+
"""Apply postprocessing to FastSAM predictions and handle prompts.
|
|
54
50
|
|
|
55
51
|
Args:
|
|
56
52
|
preds (list[torch.Tensor]): Raw predictions from the model.
|
|
@@ -77,8 +73,7 @@ class FastSAMPredictor(SegmentationPredictor):
|
|
|
77
73
|
return self.prompt(results, bboxes=bboxes, points=points, labels=labels, texts=texts)
|
|
78
74
|
|
|
79
75
|
def prompt(self, results, bboxes=None, points=None, labels=None, texts=None):
|
|
80
|
-
"""
|
|
81
|
-
Perform image segmentation inference based on cues like bounding boxes, points, and text prompts.
|
|
76
|
+
"""Perform image segmentation inference based on cues like bounding boxes, points, and text prompts.
|
|
82
77
|
|
|
83
78
|
Args:
|
|
84
79
|
results (Results | list[Results]): Original inference results from FastSAM models without any prompts.
|
|
@@ -101,7 +96,7 @@ class FastSAMPredictor(SegmentationPredictor):
|
|
|
101
96
|
continue
|
|
102
97
|
masks = result.masks.data
|
|
103
98
|
if masks.shape[1:] != result.orig_shape:
|
|
104
|
-
masks = scale_masks(masks[None], result.orig_shape)[0]
|
|
99
|
+
masks = (scale_masks(masks[None].float(), result.orig_shape)[0] > 0.5).byte()
|
|
105
100
|
# bboxes prompt
|
|
106
101
|
idx = torch.zeros(len(result), dtype=torch.bool, device=self.device)
|
|
107
102
|
if bboxes is not None:
|
|
@@ -120,7 +115,7 @@ class FastSAMPredictor(SegmentationPredictor):
|
|
|
120
115
|
labels = torch.ones(points.shape[0])
|
|
121
116
|
labels = torch.as_tensor(labels, dtype=torch.int32, device=self.device)
|
|
122
117
|
assert len(labels) == len(points), (
|
|
123
|
-
f"Expected `labels`
|
|
118
|
+
f"Expected `labels` to have the same length as `points`, but got {len(labels)} and {len(points)}."
|
|
124
119
|
)
|
|
125
120
|
point_idx = (
|
|
126
121
|
torch.ones(len(result), dtype=torch.bool, device=self.device)
|
|
@@ -151,8 +146,7 @@ class FastSAMPredictor(SegmentationPredictor):
|
|
|
151
146
|
return prompt_results
|
|
152
147
|
|
|
153
148
|
def _clip_inference(self, images, texts):
|
|
154
|
-
"""
|
|
155
|
-
Perform CLIP inference to calculate similarity between images and text prompts.
|
|
149
|
+
"""Perform CLIP inference to calculate similarity between images and text prompts.
|
|
156
150
|
|
|
157
151
|
Args:
|
|
158
152
|
images (list[PIL.Image]): List of source images, each should be PIL.Image with RGB channel order.
|
|
@@ -161,20 +155,14 @@ class FastSAMPredictor(SegmentationPredictor):
|
|
|
161
155
|
Returns:
|
|
162
156
|
(torch.Tensor): Similarity matrix between given images and texts with shape (M, N).
|
|
163
157
|
"""
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
tokenized_text = clip.tokenize(texts).to(self.device)
|
|
173
|
-
image_features = self.clip_model.encode_image(images)
|
|
174
|
-
text_features = self.clip_model.encode_text(tokenized_text)
|
|
175
|
-
image_features /= image_features.norm(dim=-1, keepdim=True) # (N, 512)
|
|
176
|
-
text_features /= text_features.norm(dim=-1, keepdim=True) # (M, 512)
|
|
177
|
-
return (image_features * text_features[:, None]).sum(-1) # (M, N)
|
|
158
|
+
from ultralytics.nn.text_model import CLIP
|
|
159
|
+
|
|
160
|
+
if not hasattr(self, "clip"):
|
|
161
|
+
self.clip = CLIP("ViT-B/32", device=self.device)
|
|
162
|
+
images = torch.stack([self.clip.image_preprocess(image).to(self.device) for image in images])
|
|
163
|
+
image_features = self.clip.encode_image(images)
|
|
164
|
+
text_features = self.clip.encode_text(self.clip.tokenize(texts))
|
|
165
|
+
return text_features @ image_features.T # (M, N)
|
|
178
166
|
|
|
179
167
|
def set_prompts(self, prompts):
|
|
180
168
|
"""Set prompts to be used during inference."""
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
def adjust_bboxes_to_image_border(boxes, image_shape, threshold=20):
|
|
5
|
-
"""
|
|
6
|
-
Adjust bounding boxes to stick to image border if they are within a certain threshold.
|
|
5
|
+
"""Adjust bounding boxes to stick to image border if they are within a certain threshold.
|
|
7
6
|
|
|
8
7
|
Args:
|
|
9
8
|
boxes (torch.Tensor): Bounding boxes with shape (N, 4) in xyxy format.
|
|
@@ -4,10 +4,9 @@ from ultralytics.models.yolo.segment import SegmentationValidator
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class FastSAMValidator(SegmentationValidator):
|
|
7
|
-
"""
|
|
8
|
-
Custom validation class for Fast SAM (Segment Anything Model) segmentation in Ultralytics YOLO framework.
|
|
7
|
+
"""Custom validation class for FastSAM (Segment Anything Model) segmentation in the Ultralytics YOLO framework.
|
|
9
8
|
|
|
10
|
-
Extends the SegmentationValidator class, customizing the validation process specifically for
|
|
9
|
+
Extends the SegmentationValidator class, customizing the validation process specifically for FastSAM. This class
|
|
11
10
|
sets the task to 'segment' and uses the SegmentMetrics for evaluation. Additionally, plotting features are disabled
|
|
12
11
|
to avoid errors during validation.
|
|
13
12
|
|
|
@@ -19,15 +18,14 @@ class FastSAMValidator(SegmentationValidator):
|
|
|
19
18
|
metrics (SegmentMetrics): Segmentation metrics calculator for evaluation.
|
|
20
19
|
|
|
21
20
|
Methods:
|
|
22
|
-
__init__: Initialize the FastSAMValidator with custom settings for
|
|
21
|
+
__init__: Initialize the FastSAMValidator with custom settings for FastSAM.
|
|
23
22
|
"""
|
|
24
23
|
|
|
25
24
|
def __init__(self, dataloader=None, save_dir=None, args=None, _callbacks=None):
|
|
26
|
-
"""
|
|
27
|
-
Initialize the FastSAMValidator class, setting the task to 'segment' and metrics to SegmentMetrics.
|
|
25
|
+
"""Initialize the FastSAMValidator class, setting the task to 'segment' and metrics to SegmentMetrics.
|
|
28
26
|
|
|
29
27
|
Args:
|
|
30
|
-
dataloader (torch.utils.data.DataLoader, optional):
|
|
28
|
+
dataloader (torch.utils.data.DataLoader, optional): DataLoader to be used for validation.
|
|
31
29
|
save_dir (Path, optional): Directory to save results.
|
|
32
30
|
args (SimpleNamespace, optional): Configuration for the validator.
|
|
33
31
|
_callbacks (list, optional): List of callback functions to be invoked during validation.
|
ultralytics/models/nas/model.py
CHANGED
|
@@ -18,11 +18,10 @@ from .val import NASValidator
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class NAS(Model):
|
|
21
|
-
"""
|
|
22
|
-
YOLO-NAS model for object detection.
|
|
21
|
+
"""YOLO-NAS model for object detection.
|
|
23
22
|
|
|
24
|
-
This class provides an interface for the YOLO-NAS models and extends the `Model` class from Ultralytics engine.
|
|
25
|
-
|
|
23
|
+
This class provides an interface for the YOLO-NAS models and extends the `Model` class from Ultralytics engine. It
|
|
24
|
+
is designed to facilitate the task of object detection using pre-trained or custom-trained YOLO-NAS models.
|
|
26
25
|
|
|
27
26
|
Attributes:
|
|
28
27
|
model (torch.nn.Module): The loaded YOLO-NAS model.
|
|
@@ -48,8 +47,7 @@ class NAS(Model):
|
|
|
48
47
|
super().__init__(model, task="detect")
|
|
49
48
|
|
|
50
49
|
def _load(self, weights: str, task=None) -> None:
|
|
51
|
-
"""
|
|
52
|
-
Load an existing NAS model weights or create a new NAS model with pretrained weights.
|
|
50
|
+
"""Load an existing NAS model weights or create a new NAS model with pretrained weights.
|
|
53
51
|
|
|
54
52
|
Args:
|
|
55
53
|
weights (str): Path to the model weights file or model name.
|
|
@@ -83,8 +81,7 @@ class NAS(Model):
|
|
|
83
81
|
self.model.eval()
|
|
84
82
|
|
|
85
83
|
def info(self, detailed: bool = False, verbose: bool = True) -> dict[str, Any]:
|
|
86
|
-
"""
|
|
87
|
-
Log model information.
|
|
84
|
+
"""Log model information.
|
|
88
85
|
|
|
89
86
|
Args:
|
|
90
87
|
detailed (bool): Show detailed information about model.
|
|
@@ -7,12 +7,11 @@ from ultralytics.utils import ops
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class NASPredictor(DetectionPredictor):
|
|
10
|
-
"""
|
|
11
|
-
Ultralytics YOLO NAS Predictor for object detection.
|
|
10
|
+
"""Ultralytics YOLO NAS Predictor for object detection.
|
|
12
11
|
|
|
13
|
-
This class extends the DetectionPredictor from Ultralytics engine and is responsible for post-processing the
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
This class extends the DetectionPredictor from Ultralytics engine and is responsible for post-processing the raw
|
|
13
|
+
predictions generated by the YOLO NAS models. It applies operations like non-maximum suppression and scaling the
|
|
14
|
+
bounding boxes to fit the original image dimensions.
|
|
16
15
|
|
|
17
16
|
Attributes:
|
|
18
17
|
args (Namespace): Namespace containing various configurations for post-processing including confidence
|
|
@@ -33,12 +32,11 @@ class NASPredictor(DetectionPredictor):
|
|
|
33
32
|
"""
|
|
34
33
|
|
|
35
34
|
def postprocess(self, preds_in, img, orig_imgs):
|
|
36
|
-
"""
|
|
37
|
-
Postprocess NAS model predictions to generate final detection results.
|
|
35
|
+
"""Postprocess NAS model predictions to generate final detection results.
|
|
38
36
|
|
|
39
37
|
This method takes raw predictions from a YOLO NAS model, converts bounding box formats, and applies
|
|
40
|
-
post-processing operations to generate the final detection results compatible with Ultralytics
|
|
41
|
-
|
|
38
|
+
post-processing operations to generate the final detection results compatible with Ultralytics result
|
|
39
|
+
visualization and analysis tools.
|
|
42
40
|
|
|
43
41
|
Args:
|
|
44
42
|
preds_in (list): Raw predictions from the NAS model, typically containing bounding boxes and class scores.
|
ultralytics/models/nas/val.py
CHANGED
|
@@ -9,8 +9,7 @@ __all__ = ["NASValidator"]
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class NASValidator(DetectionValidator):
|
|
12
|
-
"""
|
|
13
|
-
Ultralytics YOLO NAS Validator for object detection.
|
|
12
|
+
"""Ultralytics YOLO NAS Validator for object detection.
|
|
14
13
|
|
|
15
14
|
Extends DetectionValidator from the Ultralytics models package and is designed to post-process the raw predictions
|
|
16
15
|
generated by YOLO NAS models. It performs non-maximum suppression to remove overlapping and low-confidence boxes,
|