ultralytics 8.3.181__py3-none-any.whl → 8.3.182__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.
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.182"
4
4
 
5
5
  import os
6
6
 
@@ -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"]):
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ultralytics
3
- Version: 8.3.181
3
+ Version: 8.3.182
4
4
  Summary: Ultralytics YOLO 🚀 for SOTA object detection, multi-object tracking, instance segmentation, pose estimation and image classification.
5
5
  Author-email: Glenn Jocher <glenn.jocher@ultralytics.com>, Jing Qiu <jing.qiu@ultralytics.com>
6
6
  Maintainer-email: Ultralytics <hello@ultralytics.com>
@@ -7,7 +7,8 @@ tests/test_exports.py,sha256=CY-4xVZlVM16vdyIC0mSR3Ix59aiZm1qjFGIhSNmB20,11007
7
7
  tests/test_integrations.py,sha256=kl_AKmE_Qs1GB0_91iVwbzNxofm_hFTt0zzU6JF-pg4,6323
8
8
  tests/test_python.py,sha256=-qvdeg-hEcKU5mWSDEU24iFZ-i8FAwQRznSXpkp6WQ4,27928
9
9
  tests/test_solutions.py,sha256=tuf6n_fsI8KvSdJrnc-cqP2qYdiYqCWuVrx0z9dOz3Q,13213
10
- ultralytics/__init__.py,sha256=OqBNN1EOKn4_vq1OWj-ax36skQmjTn4HuE7IOLGpaI0,730
10
+ ultralytics/__init__.py,sha256=NmFp8Z3Rk0s1QZu4IuBv2wLLf-Pc5DLFdycD5Y49Keg,730
11
+ ultralytics/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
11
12
  ultralytics/assets/bus.jpg,sha256=wCAZxJecGR63Od3ZRERe9Aja1Weayrb9Ug751DS_vGM,137419
12
13
  ultralytics/assets/zidane.jpg,sha256=Ftc4aeMmen1O0A3o6GCDO9FlfBslLpTAw0gnetx7bts,50427
13
14
  ultralytics/cfg/__init__.py,sha256=Uj1br3-NVFvP6VY5CL4PK63mAQAom93XFC5cqSbM6t4,39887
@@ -150,13 +151,13 @@ ultralytics/models/sam/__init__.py,sha256=iR7B06rAEni21eptg8n4rLOP0Z_qV9y9PL-L93
150
151
  ultralytics/models/sam/amg.py,sha256=IpcuIfC5KBRiF4sdrsPl1ecWEJy75axo1yG23r5BFsw,11783
151
152
  ultralytics/models/sam/build.py,sha256=J6n-_QOYLa63jldEZmhRe9D3Is_AJE8xyZLUjzfRyTY,12629
152
153
  ultralytics/models/sam/model.py,sha256=j1TwsLmtxhiXyceU31VPzGVkjRXGylphKrdPSzUJRJc,7231
153
- ultralytics/models/sam/predict.py,sha256=awE_46I-GmYRIeDDLmGIdaYwJvPeSbw316DyanrA1Ys,86453
154
+ ultralytics/models/sam/predict.py,sha256=R32JjExRBL5c2zBcDdauhX4UM8E8kMrBLoa0sZ9vk6I,86494
154
155
  ultralytics/models/sam/modules/__init__.py,sha256=lm6MckFYCPTbqIoX7w0s_daxdjNeBeKW6DXppv1-QUM,70
155
156
  ultralytics/models/sam/modules/blocks.py,sha256=lnMhnexvXejzhixWRQQyqjrpALoIhuOSwnSGW-c9kZk,46089
156
157
  ultralytics/models/sam/modules/decoders.py,sha256=U9jqFRkD0JmO3eugSmwLD0sQkiGqJJLympWNO83osGM,25638
157
158
  ultralytics/models/sam/modules/encoders.py,sha256=srtxrfy3SfUarkC41L1S8tY4GdFueUuR2qQDFZ6ZPl4,37362
158
159
  ultralytics/models/sam/modules/memory_attention.py,sha256=F1XJAxSwho2-LMlrao_ij0MoALTvhkK-OVghi0D4cU0,13651
159
- ultralytics/models/sam/modules/sam.py,sha256=ACI2wA-FiWwj5ctHMHJIi_ZMw4ujrBkHEaZ77X1De_Y,55649
160
+ ultralytics/models/sam/modules/sam.py,sha256=CjM4M2PfRltQFnHFOp2G6QAdYk9BxWlurx82FSX_TYo,55760
160
161
  ultralytics/models/sam/modules/tiny_encoder.py,sha256=lmUIeZ9-3M-C3YmJBs13W6t__dzeJloOl0qFR9Ll8ew,42241
161
162
  ultralytics/models/sam/modules/transformer.py,sha256=xc2g6gb0jvr7cJkHkzIbZOGcTrmsOn2ojvuH-MVIMVs,14953
162
163
  ultralytics/models/sam/modules/utils.py,sha256=-PYSLExtBajbotBdLan9J07aFaeXJ03WzopAv4JcYd4,16022
@@ -249,7 +250,7 @@ ultralytics/utils/loss.py,sha256=fbOWc3Iu0QOJiWbi-mXWA9-1otTYlehtmUsI7os7ydM,397
249
250
  ultralytics/utils/metrics.py,sha256=tQjYxPd0dSzjucVyI1evIISunyYRkABXMXVQo64mAUE,68756
250
251
  ultralytics/utils/ops.py,sha256=8d60fbpntrexK3gPoLUS6mWAYGrtrQaQCOYyRJsCjuI,34521
251
252
  ultralytics/utils/patches.py,sha256=PPWiKzwGbCvuawLzDKVR8tWOQAlZbJBi8g_-A6eTCYA,6536
252
- ultralytics/utils/plotting.py,sha256=IEugKlTITLxArZjbSr7i_cTaHHAqNwVVk08Ak7I_ZdM,47169
253
+ ultralytics/utils/plotting.py,sha256=4TG_J8rz9VVPrOXbdjRHPJZVgJrFYVmEYE0BcVDdolc,47745
253
254
  ultralytics/utils/tal.py,sha256=aXawOnhn8ni65tJWIW-PYqWr_TRvltbHBjrTo7o6lDQ,20924
254
255
  ultralytics/utils/torch_utils.py,sha256=D76Pvmw5OKh-vd4aJkOMO0dSLbM5WzGr7Hmds54hPEk,39233
255
256
  ultralytics/utils/triton.py,sha256=M7qe4RztiADBJQEWQKaIQsp94ERFJ_8_DUHDR6TXEOM,5410
@@ -265,9 +266,9 @@ ultralytics/utils/callbacks/neptune.py,sha256=j8pecmlcsM8FGzLKWoBw5xUsi5t8E5HuxY
265
266
  ultralytics/utils/callbacks/raytune.py,sha256=S6Bq16oQDQ8BQgnZzA0zJHGN_BBr8iAM_WtGoLiEcwg,1283
266
267
  ultralytics/utils/callbacks/tensorboard.py,sha256=MDPBW7aDes-66OE6YqKXXvqA_EocjzEMHWGM-8z9vUQ,5281
267
268
  ultralytics/utils/callbacks/wb.py,sha256=Tm_-aRr2CN32MJkY9tylpMBJkb007-MSRNSQ7rDJ5QU,7521
268
- ultralytics-8.3.181.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
269
- ultralytics-8.3.181.dist-info/METADATA,sha256=4pr1Msb_WGwP7Z6pWGFCo6q6buD2iHCVuGbj_hgNPL4,37631
270
- ultralytics-8.3.181.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
271
- ultralytics-8.3.181.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
272
- ultralytics-8.3.181.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
273
- ultralytics-8.3.181.dist-info/RECORD,,
269
+ ultralytics-8.3.182.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
270
+ ultralytics-8.3.182.dist-info/METADATA,sha256=6J19Tk3kc50OtxsKa2FTq2NrpG7hB3nrYzLCvHbkxes,37631
271
+ ultralytics-8.3.182.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
272
+ ultralytics-8.3.182.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
273
+ ultralytics-8.3.182.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
274
+ ultralytics-8.3.182.dist-info/RECORD,,