dgenerate-ultralytics-headless 8.3.181__py3-none-any.whl → 8.3.183__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dgenerate-ultralytics-headless
3
- Version: 8.3.181
3
+ Version: 8.3.183
4
4
  Summary: Automatically built Ultralytics package with python-opencv-headless dependency instead of python-opencv
5
5
  Author-email: Glenn Jocher <glenn.jocher@ultralytics.com>, Jing Qiu <jing.qiu@ultralytics.com>
6
6
  Maintainer-email: Ultralytics <hello@ultralytics.com>
@@ -1,14 +1,15 @@
1
- dgenerate_ultralytics_headless-8.3.181.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
1
+ dgenerate_ultralytics_headless-8.3.183.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
2
2
  tests/__init__.py,sha256=b4KP5_q-2IO8Br8YHOSLYnn7IwZS81l_vfEF2YPa2lM,894
3
3
  tests/conftest.py,sha256=LXtQJcFNWPGuzauTGkiXgsvVC3llJKfg22WcmhRzuQc,2593
4
4
  tests/test_cli.py,sha256=EMf5gTAopOnIz8VvzaM-Qb044o7D0flnUHYQ-2ffOM4,5670
5
- tests/test_cuda.py,sha256=-nQsfF3lGfqLm6cIeu_BCiXqLj7HzpL7R1GzPEc6z2I,8128
5
+ tests/test_cuda.py,sha256=7RAMC1DoXpsRvH0Jfyo9cqHkaJZWcWeqniCW5BW87hY,8228
6
6
  tests/test_engine.py,sha256=Jpt2KVrltrEgh2-3Ykouz-2Z_2fza0eymL5ectRXadM,4922
7
7
  tests/test_exports.py,sha256=CY-4xVZlVM16vdyIC0mSR3Ix59aiZm1qjFGIhSNmB20,11007
8
8
  tests/test_integrations.py,sha256=kl_AKmE_Qs1GB0_91iVwbzNxofm_hFTt0zzU6JF-pg4,6323
9
- tests/test_python.py,sha256=-qvdeg-hEcKU5mWSDEU24iFZ-i8FAwQRznSXpkp6WQ4,27928
9
+ tests/test_python.py,sha256=JbOB6pbTkoQtPCjkl_idagV0_W2QLWGbsh2IvGmru0M,28274
10
10
  tests/test_solutions.py,sha256=tuf6n_fsI8KvSdJrnc-cqP2qYdiYqCWuVrx0z9dOz3Q,13213
11
- ultralytics/__init__.py,sha256=OqBNN1EOKn4_vq1OWj-ax36skQmjTn4HuE7IOLGpaI0,730
11
+ ultralytics/__init__.py,sha256=hpM4gHWSSIAjKjCF3tuvHLzoZadJLeOZVINd-nMfpm8,730
12
+ ultralytics/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
12
13
  ultralytics/assets/bus.jpg,sha256=wCAZxJecGR63Od3ZRERe9Aja1Weayrb9Ug751DS_vGM,137419
13
14
  ultralytics/assets/zidane.jpg,sha256=Ftc4aeMmen1O0A3o6GCDO9FlfBslLpTAw0gnetx7bts,50427
14
15
  ultralytics/cfg/__init__.py,sha256=Uj1br3-NVFvP6VY5CL4PK63mAQAom93XFC5cqSbM6t4,39887
@@ -109,7 +110,7 @@ ultralytics/data/annotator.py,sha256=uAgd7K-yudxiwdNqHz0ubfFg5JsfNlae4cgxdvCMyuY
109
110
  ultralytics/data/augment.py,sha256=Ps1s-ug_oXdyAz4Jyur6OmxzRlyzwP3VP-3hDalSxj8,132959
110
111
  ultralytics/data/base.py,sha256=mRcuehK1thNuuzQGL6D1AaZkod71oHRdYTod_zdQZQg,19688
111
112
  ultralytics/data/build.py,sha256=TfMLSPMbE2hGZVMLl178NTFrihC1-50jNOt1ex9elxw,11480
112
- ultralytics/data/converter.py,sha256=dExElV0vWd4EmDtZaFMC0clEmLdjRDIdFiXf01PUvQA,27134
113
+ ultralytics/data/converter.py,sha256=1YJNJcOyzdnc-LmJw4oFbeJemHOWwx9z8m0V2QA_lzc,32053
113
114
  ultralytics/data/dataset.py,sha256=GhoFzBiuGvTr_5-3pzgWu6D_3aQVwW-hcS7kCo8XscM,36752
114
115
  ultralytics/data/loaders.py,sha256=u9sExTGPy1iiqVd_p29zVoEkQ3C36g2rE0FEbYPET0A,31767
115
116
  ultralytics/data/split.py,sha256=F6O73bAbESj70FQZzqkydXQeXgPXGHGiC06b5MkLHjQ,5109
@@ -124,7 +125,7 @@ ultralytics/engine/exporter.py,sha256=Vr7K8Yf3wyf91ZvDpRosAohwa_W0oe4qW-JvqigCPf
124
125
  ultralytics/engine/model.py,sha256=877u2n0ISz2COOYtEMUqQe0E-HHB4Atb2DuH1XCE98k,53530
125
126
  ultralytics/engine/predictor.py,sha256=iXnUB-tvBHtVpKbB-5EKs1wSREBIerdUxWx39MaFYuk,22485
126
127
  ultralytics/engine/results.py,sha256=QcHcbPVlLBiy_APwABr-T5K65HR8Bl1rRzxawjjP76E,71873
127
- ultralytics/engine/trainer.py,sha256=28FeqASvQRxCaK96SXDM-BfPJjqy5KNiWhf8v6GXTug,39785
128
+ ultralytics/engine/trainer.py,sha256=rOzMFt7b5PzVJZ3cOl80wxQAKUTP7XhnMHfXSaVRbOE,40193
128
129
  ultralytics/engine/tuner.py,sha256=sfQ8_yzgLNcGlKyz9b2vAzyggGZXiQzdZ5tKstyqjHM,12825
129
130
  ultralytics/engine/validator.py,sha256=g0StH6WOn95zBN-hULDAR5Uug1pU2YkaeNH3zzq3SVg,16573
130
131
  ultralytics/hub/__init__.py,sha256=ulPtceI3hqud03mvqoXccBaa1e4nveYwC9cddyuBUlo,6599
@@ -151,13 +152,13 @@ ultralytics/models/sam/__init__.py,sha256=iR7B06rAEni21eptg8n4rLOP0Z_qV9y9PL-L93
151
152
  ultralytics/models/sam/amg.py,sha256=IpcuIfC5KBRiF4sdrsPl1ecWEJy75axo1yG23r5BFsw,11783
152
153
  ultralytics/models/sam/build.py,sha256=J6n-_QOYLa63jldEZmhRe9D3Is_AJE8xyZLUjzfRyTY,12629
153
154
  ultralytics/models/sam/model.py,sha256=j1TwsLmtxhiXyceU31VPzGVkjRXGylphKrdPSzUJRJc,7231
154
- ultralytics/models/sam/predict.py,sha256=awE_46I-GmYRIeDDLmGIdaYwJvPeSbw316DyanrA1Ys,86453
155
+ ultralytics/models/sam/predict.py,sha256=R32JjExRBL5c2zBcDdauhX4UM8E8kMrBLoa0sZ9vk6I,86494
155
156
  ultralytics/models/sam/modules/__init__.py,sha256=lm6MckFYCPTbqIoX7w0s_daxdjNeBeKW6DXppv1-QUM,70
156
157
  ultralytics/models/sam/modules/blocks.py,sha256=lnMhnexvXejzhixWRQQyqjrpALoIhuOSwnSGW-c9kZk,46089
157
158
  ultralytics/models/sam/modules/decoders.py,sha256=U9jqFRkD0JmO3eugSmwLD0sQkiGqJJLympWNO83osGM,25638
158
159
  ultralytics/models/sam/modules/encoders.py,sha256=srtxrfy3SfUarkC41L1S8tY4GdFueUuR2qQDFZ6ZPl4,37362
159
160
  ultralytics/models/sam/modules/memory_attention.py,sha256=F1XJAxSwho2-LMlrao_ij0MoALTvhkK-OVghi0D4cU0,13651
160
- ultralytics/models/sam/modules/sam.py,sha256=ACI2wA-FiWwj5ctHMHJIi_ZMw4ujrBkHEaZ77X1De_Y,55649
161
+ ultralytics/models/sam/modules/sam.py,sha256=CjM4M2PfRltQFnHFOp2G6QAdYk9BxWlurx82FSX_TYo,55760
161
162
  ultralytics/models/sam/modules/tiny_encoder.py,sha256=lmUIeZ9-3M-C3YmJBs13W6t__dzeJloOl0qFR9Ll8ew,42241
162
163
  ultralytics/models/sam/modules/transformer.py,sha256=xc2g6gb0jvr7cJkHkzIbZOGcTrmsOn2ojvuH-MVIMVs,14953
163
164
  ultralytics/models/sam/modules/utils.py,sha256=-PYSLExtBajbotBdLan9J07aFaeXJ03WzopAv4JcYd4,16022
@@ -193,7 +194,7 @@ ultralytics/models/yolo/yoloe/__init__.py,sha256=6SLytdJtwu37qewf7CobG7C7Wl1m-xt
193
194
  ultralytics/models/yolo/yoloe/predict.py,sha256=GmQxCQe7sLomAujde53jQzquzryNn6fEjS4Oalf3mPs,7124
194
195
  ultralytics/models/yolo/yoloe/train.py,sha256=XYpQYSnSD8vi_9VSj_S5oIsNUEqm3e66vPT8rNFI_HY,14086
195
196
  ultralytics/models/yolo/yoloe/train_seg.py,sha256=aCV7M8oQOvODFnU4piZdJh3tIrBJYAzZfRVRx1vRgxo,4956
196
- ultralytics/models/yolo/yoloe/val.py,sha256=yebPkxwKKt__cY05Zbh1YXg4_BKzzpcDc3Cv3FJ5SAA,9769
197
+ ultralytics/models/yolo/yoloe/val.py,sha256=2NuERI3B3WeED658Cat1xL2SVpORUHlCHCWI3L8pJJc,9784
197
198
  ultralytics/nn/__init__.py,sha256=rjociYD9lo_K-d-1s6TbdWklPLjTcEHk7OIlRDJstIE,615
198
199
  ultralytics/nn/autobackend.py,sha256=UM9ObXeLB0lgak1Q5oSi2IA-R_Owr6NdJNBAsA3mSbo,41790
199
200
  ultralytics/nn/tasks.py,sha256=vw_TNacAv-RN24rusFzKuYL6qRBD7cve8EpB7gOlU_8,72505
@@ -250,7 +251,7 @@ ultralytics/utils/loss.py,sha256=fbOWc3Iu0QOJiWbi-mXWA9-1otTYlehtmUsI7os7ydM,397
250
251
  ultralytics/utils/metrics.py,sha256=tQjYxPd0dSzjucVyI1evIISunyYRkABXMXVQo64mAUE,68756
251
252
  ultralytics/utils/ops.py,sha256=8d60fbpntrexK3gPoLUS6mWAYGrtrQaQCOYyRJsCjuI,34521
252
253
  ultralytics/utils/patches.py,sha256=PPWiKzwGbCvuawLzDKVR8tWOQAlZbJBi8g_-A6eTCYA,6536
253
- ultralytics/utils/plotting.py,sha256=IEugKlTITLxArZjbSr7i_cTaHHAqNwVVk08Ak7I_ZdM,47169
254
+ ultralytics/utils/plotting.py,sha256=4TG_J8rz9VVPrOXbdjRHPJZVgJrFYVmEYE0BcVDdolc,47745
254
255
  ultralytics/utils/tal.py,sha256=aXawOnhn8ni65tJWIW-PYqWr_TRvltbHBjrTo7o6lDQ,20924
255
256
  ultralytics/utils/torch_utils.py,sha256=D76Pvmw5OKh-vd4aJkOMO0dSLbM5WzGr7Hmds54hPEk,39233
256
257
  ultralytics/utils/triton.py,sha256=M7qe4RztiADBJQEWQKaIQsp94ERFJ_8_DUHDR6TXEOM,5410
@@ -266,8 +267,8 @@ ultralytics/utils/callbacks/neptune.py,sha256=j8pecmlcsM8FGzLKWoBw5xUsi5t8E5HuxY
266
267
  ultralytics/utils/callbacks/raytune.py,sha256=S6Bq16oQDQ8BQgnZzA0zJHGN_BBr8iAM_WtGoLiEcwg,1283
267
268
  ultralytics/utils/callbacks/tensorboard.py,sha256=MDPBW7aDes-66OE6YqKXXvqA_EocjzEMHWGM-8z9vUQ,5281
268
269
  ultralytics/utils/callbacks/wb.py,sha256=Tm_-aRr2CN32MJkY9tylpMBJkb007-MSRNSQ7rDJ5QU,7521
269
- dgenerate_ultralytics_headless-8.3.181.dist-info/METADATA,sha256=6a7UOAonIPqJS7OoY1QQ6pBR1hIhPk4Tu5Rb-RSlINU,38727
270
- dgenerate_ultralytics_headless-8.3.181.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
271
- dgenerate_ultralytics_headless-8.3.181.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
272
- dgenerate_ultralytics_headless-8.3.181.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
273
- dgenerate_ultralytics_headless-8.3.181.dist-info/RECORD,,
270
+ dgenerate_ultralytics_headless-8.3.183.dist-info/METADATA,sha256=u9Pxkr9kFuSZDzhiV3hvbkFV8Br-rfRoWSABCSUcQ1E,38727
271
+ dgenerate_ultralytics_headless-8.3.183.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
272
+ dgenerate_ultralytics_headless-8.3.183.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
273
+ dgenerate_ultralytics_headless-8.3.183.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
274
+ dgenerate_ultralytics_headless-8.3.183.dist-info/RECORD,,
tests/test_cuda.py CHANGED
@@ -67,7 +67,7 @@ def test_export_onnx_matrix(task, dynamic, int8, half, batch, simplify, nms):
67
67
  half=half,
68
68
  batch=batch,
69
69
  simplify=simplify,
70
- nms=nms,
70
+ nms=nms and task != "obb", # disable NMS for OBB task for now on T4 instance
71
71
  device=DEVICES[0],
72
72
  )
73
73
  YOLO(file)([SOURCE] * batch, imgsz=64 if dynamic else 32, device=DEVICES[0]) # exported model inference
@@ -163,7 +163,7 @@ def test_autobatch():
163
163
 
164
164
 
165
165
  @pytest.mark.slow
166
- @pytest.mark.skipif(not DEVICES, reason="No CUDA devices available")
166
+ @pytest.mark.skipif(True, reason="Skip for now since T4 instance does not support TensorRT > 10.0")
167
167
  def test_utils_benchmarks():
168
168
  """Profile YOLO models for performance benchmarks."""
169
169
  from ultralytics.utils.benchmarks import ProfileModels
tests/test_python.py CHANGED
@@ -228,6 +228,15 @@ def test_train_scratch():
228
228
  model(SOURCE)
229
229
 
230
230
 
231
+ @pytest.mark.skipif(not ONLINE, reason="environment is offline")
232
+ def test_train_ndjson():
233
+ """Test training the YOLO model using NDJSON format dataset."""
234
+ model = YOLO(WEIGHTS_DIR / "yolo11n.pt")
235
+ model.train(
236
+ data="https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8-ndjson.ndjson", epochs=1, imgsz=32
237
+ )
238
+
239
+
231
240
  @pytest.mark.parametrize("scls", [False, True])
232
241
  def test_train_pretrained(scls):
233
242
  """Test training of the YOLO model starting from a pre-trained checkpoint."""
ultralytics/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
- __version__ = "8.3.181"
3
+ __version__ = "8.3.183"
4
4
 
5
5
  import os
6
6
 
@@ -1,5 +1,6 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
+ import asyncio
3
4
  import json
4
5
  import random
5
6
  import shutil
@@ -12,7 +13,8 @@ import cv2
12
13
  import numpy as np
13
14
  from PIL import Image
14
15
 
15
- from ultralytics.utils import DATASETS_DIR, LOGGER, NUM_THREADS, TQDM
16
+ from ultralytics.utils import DATASETS_DIR, LOGGER, NUM_THREADS, TQDM, YAML
17
+ from ultralytics.utils.checks import check_file, check_requirements
16
18
  from ultralytics.utils.downloads import download, zip_directory
17
19
  from ultralytics.utils.files import increment_path
18
20
 
@@ -754,3 +756,112 @@ def convert_to_multispectral(path: Union[str, Path], n_channels: int = 10, repla
754
756
  multispectral = f(target_wavelengths)
755
757
  cv2.imwritemulti(str(output_path), np.clip(multispectral, 0, 255).astype(np.uint8).transpose(2, 0, 1))
756
758
  LOGGER.info(f"Converted {output_path}")
759
+
760
+
761
+ async def convert_ndjson_to_yolo(ndjson_path: Union[str, Path], output_path: Optional[Union[str, Path]] = None) -> Path:
762
+ """
763
+ Convert NDJSON dataset format to Ultralytics YOLO11 dataset structure.
764
+
765
+ This function converts datasets stored in NDJSON (Newline Delimited JSON) format to the standard YOLO
766
+ format with separate directories for images and labels. It supports parallel processing for efficient
767
+ conversion of large datasets and can download images from URLs if they don't exist locally.
768
+
769
+ The NDJSON format consists of:
770
+ - First line: Dataset metadata with class names and configuration
771
+ - Subsequent lines: Individual image records with annotations and optional URLs
772
+
773
+ Args:
774
+ ndjson_path (Union[str, Path]): Path to the input NDJSON file containing dataset information.
775
+ output_path (Optional[Union[str, Path]], optional): Directory where the converted YOLO dataset
776
+ will be saved. If None, uses the parent directory of the NDJSON file. Defaults to None.
777
+
778
+ Returns:
779
+ (Path): Path to the generated data.yaml file that can be used for YOLO training.
780
+
781
+ Examples:
782
+ Convert a local NDJSON file:
783
+ >>> yaml_path = convert_ndjson_to_yolo("dataset.ndjson")
784
+ >>> print(f"Dataset converted to: {yaml_path}")
785
+
786
+ Convert with custom output directory:
787
+ >>> yaml_path = convert_ndjson_to_yolo("dataset.ndjson", output_path="./converted_datasets")
788
+
789
+ # Use with YOLO training
790
+ >>> from ultralytics import YOLO
791
+ >>> model = YOLO("yolo11n.pt")
792
+ >>> model.train(data="https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8-ndjson.ndjson")
793
+ """
794
+ check_requirements("aiohttp")
795
+ import aiohttp
796
+
797
+ ndjson_path = Path(check_file(ndjson_path))
798
+ output_path = Path(output_path or DATASETS_DIR)
799
+ with open(ndjson_path) as f:
800
+ lines = [json.loads(line.strip()) for line in f if line.strip()]
801
+
802
+ dataset_record, image_records = lines[0], lines[1:]
803
+ dataset_dir = output_path / ndjson_path.stem
804
+ splits = {record["split"] for record in image_records}
805
+
806
+ # Create directories and prepare YAML structure
807
+ dataset_dir.mkdir(parents=True, exist_ok=True)
808
+ data_yaml = dict(dataset_record)
809
+ data_yaml["names"] = {int(k): v for k, v in dataset_record.get("class_names", {}).items()}
810
+
811
+ for split in sorted(splits):
812
+ (dataset_dir / "images" / split).mkdir(parents=True, exist_ok=True)
813
+ (dataset_dir / "labels" / split).mkdir(parents=True, exist_ok=True)
814
+ data_yaml[split] = f"images/{split}"
815
+
816
+ async def process_record(session, semaphore, record):
817
+ """Process single image record with async session."""
818
+ async with semaphore:
819
+ split, original_name = record["split"], record["file"]
820
+ label_path = dataset_dir / "labels" / split / f"{Path(original_name).stem}.txt"
821
+ image_path = dataset_dir / "images" / split / original_name
822
+
823
+ annotations = record.get("annotations", {})
824
+ lines_to_write = []
825
+ for key in annotations.keys():
826
+ lines_to_write = [" ".join(map(str, item)) for item in annotations[key]]
827
+ break
828
+ if "classification" in annotations:
829
+ lines_to_write = [str(cls) for cls in annotations["classification"]]
830
+
831
+ label_path.write_text("\n".join(lines_to_write) + "\n" if lines_to_write else "")
832
+
833
+ if http_url := record.get("url"):
834
+ if not image_path.exists():
835
+ try:
836
+ async with session.get(http_url, timeout=aiohttp.ClientTimeout(total=30)) as response:
837
+ response.raise_for_status()
838
+ with open(image_path, "wb") as f:
839
+ async for chunk in response.content.iter_chunked(8192):
840
+ f.write(chunk)
841
+ return True
842
+ except Exception as e:
843
+ LOGGER.warning(f"Failed to download {http_url}: {e}")
844
+ return False
845
+ return True
846
+
847
+ # Process all images with async downloads
848
+ semaphore = asyncio.Semaphore(64)
849
+ async with aiohttp.ClientSession() as session:
850
+ pbar = TQDM(
851
+ total=len(image_records),
852
+ desc=f"Converting {ndjson_path.name} → {dataset_dir} ({len(image_records)} images)",
853
+ )
854
+
855
+ async def tracked_process(record):
856
+ result = await process_record(session, semaphore, record)
857
+ pbar.update(1)
858
+ return result
859
+
860
+ await asyncio.gather(*[tracked_process(record) for record in image_records])
861
+ pbar.close()
862
+
863
+ # Write data.yaml
864
+ yaml_path = dataset_dir / "data.yaml"
865
+ YAML.save(yaml_path, data_yaml)
866
+
867
+ return yaml_path
@@ -598,6 +598,15 @@ class BaseTrainer:
598
598
  try:
599
599
  if self.args.task == "classify":
600
600
  data = check_cls_dataset(self.args.data)
601
+ elif self.args.data.rsplit(".", 1)[-1] == "ndjson":
602
+ # Convert NDJSON to YOLO format
603
+ import asyncio
604
+
605
+ from ultralytics.data.converter import convert_ndjson_to_yolo
606
+
607
+ yaml_path = asyncio.run(convert_ndjson_to_yolo(self.args.data))
608
+ self.args.data = str(yaml_path)
609
+ data = check_det_dataset(self.args.data)
601
610
  elif self.args.data.rsplit(".", 1)[-1] in {"yaml", "yml"} or self.args.task in {
602
611
  "detect",
603
612
  "segment",
@@ -1032,3 +1032,4 @@ class SAM2Model(torch.nn.Module):
1032
1032
  self.image_size = imgsz[0]
1033
1033
  self.sam_prompt_encoder.input_image_size = imgsz
1034
1034
  self.sam_prompt_encoder.image_embedding_size = [x // 16 for x in imgsz] # fixed ViT patch size of 16
1035
+ self.sam_image_embedding_size = self.image_size // self.backbone_stride # update image embedding size
@@ -1283,6 +1283,7 @@ class SAM2VideoPredictor(SAM2Predictor):
1283
1283
  - If `batch` is greater than 1, the features are expanded to fit the batch size.
1284
1284
  - The method leverages the model's `_prepare_backbone_features` method to prepare the backbone features.
1285
1285
  """
1286
+ self.model.set_imgsz(self.imgsz)
1286
1287
  backbone_out = self.model.forward_image(im)
1287
1288
  if batch > 1: # expand features if there's more than one prompt
1288
1289
  for i, feat in enumerate(backbone_out["backbone_fpn"]):
@@ -181,7 +181,7 @@ class YOLOEDetectValidator(DetectionValidator):
181
181
  else:
182
182
  if refer_data is not None:
183
183
  assert load_vp, "Refer data is only used for visual prompt validation."
184
- self.device = select_device(self.args.device)
184
+ self.device = select_device(self.args.device, verbose=False)
185
185
 
186
186
  if isinstance(model, (str, Path)):
187
187
  from ultralytics.nn.tasks import attempt_load_weights
ultralytics/py.typed ADDED
@@ -0,0 +1 @@
1
+ partial
@@ -361,38 +361,46 @@ class Annotator:
361
361
  lineType=cv2.LINE_AA,
362
362
  )
363
363
 
364
- def masks(self, masks, colors, im_gpu, alpha: float = 0.5, retina_masks: bool = False):
364
+ def masks(self, masks, colors, im_gpu: torch.Tensor = None, alpha: float = 0.5, retina_masks: bool = False):
365
365
  """
366
366
  Plot masks on image.
367
367
 
368
368
  Args:
369
- masks (torch.Tensor): Predicted masks on cuda, shape: [n, h, w]
369
+ masks (torch.Tensor | np.ndarray): Predicted masks with shape: [n, h, w]
370
370
  colors (List[List[int]]): Colors for predicted masks, [[r, g, b] * n]
371
- im_gpu (torch.Tensor): Image is in cuda, shape: [3, h, w], range: [0, 1]
371
+ im_gpu (torch.Tensor | None): Image is in cuda, shape: [3, h, w], range: [0, 1]
372
372
  alpha (float, optional): Mask transparency: 0.0 fully transparent, 1.0 opaque.
373
373
  retina_masks (bool, optional): Whether to use high resolution masks or not.
374
374
  """
375
375
  if self.pil:
376
376
  # Convert to numpy first
377
377
  self.im = np.asarray(self.im).copy()
378
- if len(masks) == 0:
379
- self.im[:] = im_gpu.permute(1, 2, 0).contiguous().cpu().numpy() * 255
380
- if im_gpu.device != masks.device:
381
- im_gpu = im_gpu.to(masks.device)
382
- colors = torch.tensor(colors, device=masks.device, dtype=torch.float32) / 255.0 # shape(n,3)
383
- colors = colors[:, None, None] # shape(n,1,1,3)
384
- masks = masks.unsqueeze(3) # shape(n,h,w,1)
385
- masks_color = masks * (colors * alpha) # shape(n,h,w,3)
386
-
387
- inv_alpha_masks = (1 - masks * alpha).cumprod(0) # shape(n,h,w,1)
388
- mcs = masks_color.max(dim=0).values # shape(n,h,w,3)
389
-
390
- im_gpu = im_gpu.flip(dims=[0]) # flip channel
391
- im_gpu = im_gpu.permute(1, 2, 0).contiguous() # shape(h,w,3)
392
- im_gpu = im_gpu * inv_alpha_masks[-1] + mcs
393
- im_mask = im_gpu * 255
394
- im_mask_np = im_mask.byte().cpu().numpy()
395
- self.im[:] = im_mask_np if retina_masks else ops.scale_image(im_mask_np, self.im.shape)
378
+ if im_gpu is None:
379
+ assert isinstance(masks, np.ndarray), "`masks` must be a np.ndarray if `im_gpu` is not provided."
380
+ overlay = self.im.copy()
381
+ for i, mask in enumerate(masks):
382
+ overlay[mask.astype(bool)] = colors[i]
383
+ self.im = cv2.addWeighted(self.im, 1 - alpha, overlay, alpha, 0)
384
+ else:
385
+ assert isinstance(masks, torch.Tensor), "`masks` must be a torch.Tensor if `im_gpu` is provided."
386
+ if len(masks) == 0:
387
+ self.im[:] = im_gpu.permute(1, 2, 0).contiguous().cpu().numpy() * 255
388
+ if im_gpu.device != masks.device:
389
+ im_gpu = im_gpu.to(masks.device)
390
+ colors = torch.tensor(colors, device=masks.device, dtype=torch.float32) / 255.0 # shape(n,3)
391
+ colors = colors[:, None, None] # shape(n,1,1,3)
392
+ masks = masks.unsqueeze(3) # shape(n,h,w,1)
393
+ masks_color = masks * (colors * alpha) # shape(n,h,w,3)
394
+
395
+ inv_alpha_masks = (1 - masks * alpha).cumprod(0) # shape(n,h,w,1)
396
+ mcs = masks_color.max(dim=0).values # shape(n,h,w,3)
397
+
398
+ im_gpu = im_gpu.flip(dims=[0]) # flip channel
399
+ im_gpu = im_gpu.permute(1, 2, 0).contiguous() # shape(h,w,3)
400
+ im_gpu = im_gpu * inv_alpha_masks[-1] + mcs
401
+ im_mask = im_gpu * 255
402
+ im_mask_np = im_mask.byte().cpu().numpy()
403
+ self.im[:] = im_mask_np if retina_masks else ops.scale_image(im_mask_np, self.im.shape)
396
404
  if self.pil:
397
405
  # Convert im back to PIL and update draw
398
406
  self.fromarray(self.im)