ultralytics 8.3.206__py3-none-any.whl → 8.3.207__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.206"
3
+ __version__ = "8.3.207"
4
4
 
5
5
  import importlib
6
6
  import os
@@ -894,7 +894,7 @@ class Exporter:
894
894
  classifier_config = ct.ClassifierConfig(list(self.model.names.values()))
895
895
  model = self.model
896
896
  elif self.model.task == "detect":
897
- model = IOSDetectModel(self.model, self.im) if self.args.nms else self.model
897
+ model = IOSDetectModel(self.model, self.im, mlprogram=not mlmodel) if self.args.nms else self.model
898
898
  else:
899
899
  if self.args.nms:
900
900
  LOGGER.warning(f"{prefix} 'nms=True' is only available for Detect models like 'yolo11n.pt'.")
@@ -938,12 +938,7 @@ class Exporter:
938
938
  config = cto.OptimizationConfig(global_config=op_config)
939
939
  ct_model = cto.palettize_weights(ct_model, config=config)
940
940
  if self.args.nms and self.model.task == "detect":
941
- if mlmodel:
942
- weights_dir = None
943
- else:
944
- ct_model.save(str(f)) # save otherwise weights_dir does not exist
945
- weights_dir = str(f / "Data/com.apple.CoreML/weights")
946
- ct_model = self._pipeline_coreml(ct_model, weights_dir=weights_dir)
941
+ ct_model = self._pipeline_coreml(ct_model, weights_dir=None if mlmodel else ct_model.weights_dir)
947
942
 
948
943
  m = self.metadata # metadata dict
949
944
  ct_model.short_description = m.pop("description")
@@ -1277,7 +1272,8 @@ class Exporter:
1277
1272
  names = self.metadata["names"]
1278
1273
  nx, ny = spec.description.input[0].type.imageType.width, spec.description.input[0].type.imageType.height
1279
1274
  nc = outs[0].type.multiArrayType.shape[-1]
1280
- assert len(names) == nc, f"{len(names)} names found for nc={nc}" # check
1275
+ if len(names) != nc: # Hack fix for MLProgram NMS bug https://github.com/ultralytics/ultralytics/issues/22309
1276
+ names = {**names, **{i: str(i) for i in range(len(names), nc)}}
1281
1277
 
1282
1278
  # Model from spec
1283
1279
  model = ct.models.MLModel(spec, weights_dir=weights_dir)
@@ -1367,18 +1363,20 @@ class Exporter:
1367
1363
  class IOSDetectModel(torch.nn.Module):
1368
1364
  """Wrap an Ultralytics YOLO model for Apple iOS CoreML export."""
1369
1365
 
1370
- def __init__(self, model, im):
1366
+ def __init__(self, model, im, mlprogram=True):
1371
1367
  """
1372
1368
  Initialize the IOSDetectModel class with a YOLO model and example image.
1373
1369
 
1374
1370
  Args:
1375
1371
  model (torch.nn.Module): The YOLO model to wrap.
1376
1372
  im (torch.Tensor): Example input tensor with shape (B, C, H, W).
1373
+ mlprogram (bool): Whether exporting to MLProgram format to fix NMS bug.
1377
1374
  """
1378
1375
  super().__init__()
1379
1376
  _, _, h, w = im.shape # batch, channel, height, width
1380
1377
  self.model = model
1381
1378
  self.nc = len(model.names) # number of classes
1379
+ self.mlprogram = mlprogram
1382
1380
  if w == h:
1383
1381
  self.normalize = 1.0 / w # scalar
1384
1382
  else:
@@ -1390,7 +1388,11 @@ class IOSDetectModel(torch.nn.Module):
1390
1388
  def forward(self, x):
1391
1389
  """Normalize predictions of object detection model with input size-dependent factors."""
1392
1390
  xywh, cls = self.model(x)[0].transpose(0, 1).split((4, self.nc), 1)
1393
- return cls, xywh * self.normalize # confidence (3780, 80), coordinates (3780, 4)
1391
+ if self.mlprogram and self.nc % 80 != 0: # NMS bug https://github.com/ultralytics/ultralytics/issues/22309
1392
+ pad_length = int(((self.nc + 79) // 80) * 80) - self.nc # pad class length to multiple of 80
1393
+ cls = torch.nn.functional.pad(cls, (0, pad_length, 0, 0), "constant", 0)
1394
+
1395
+ return cls, xywh * self.normalize
1394
1396
 
1395
1397
 
1396
1398
  class NMSModel(torch.nn.Module):
@@ -376,8 +376,8 @@ def safe_download(
376
376
  if i == 0 and not is_online():
377
377
  raise ConnectionError(emojis(f"❌ Download failure for {uri}. Environment is not online.")) from e
378
378
  elif i >= retry:
379
- raise ConnectionError(emojis(f"❌ Download failure for {uri}. Retry limit reached.")) from e
380
- LOGGER.warning(f"Download failure, retrying {i + 1}/{retry} {uri}...")
379
+ raise ConnectionError(emojis(f"❌ Download failure for {uri}. Retry limit reached. {e}")) from e
380
+ LOGGER.warning(f"Download failure, retrying {i + 1}/{retry} {uri}... {e}")
381
381
 
382
382
  if unzip and f.exists() and f.suffix in {"", ".zip", ".tar", ".gz"}:
383
383
  from zipfile import is_zipfile
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ultralytics
3
- Version: 8.3.206
3
+ Version: 8.3.207
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,7 @@ tests/test_exports.py,sha256=L_Q0RRCIX80Czx-E4f4ktiAMobNXicVvrnxtv2wndBE,11093
7
7
  tests/test_integrations.py,sha256=kl_AKmE_Qs1GB0_91iVwbzNxofm_hFTt0zzU6JF-pg4,6323
8
8
  tests/test_python.py,sha256=2W1f15r9B1TQ8HEf2yXcJ3s3_Dn7S5SCBY8DIBM373k,28203
9
9
  tests/test_solutions.py,sha256=oaTz5BttPDIeHkQh9oEaw-O73L4iYDP3Lfe82V7DeKM,13416
10
- ultralytics/__init__.py,sha256=LzBGwb9vf_PfLjZnlRpleH6RPVwZwWhajdqcVIsPte8,1302
10
+ ultralytics/__init__.py,sha256=wysRg41fuY_fmhPnOqmgi2rqp4vTzb875cKgN3lDfmM,1302
11
11
  ultralytics/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
12
12
  ultralytics/assets/bus.jpg,sha256=wCAZxJecGR63Od3ZRERe9Aja1Weayrb9Ug751DS_vGM,137419
13
13
  ultralytics/assets/zidane.jpg,sha256=Ftc4aeMmen1O0A3o6GCDO9FlfBslLpTAw0gnetx7bts,50427
@@ -121,7 +121,7 @@ ultralytics/data/scripts/get_coco.sh,sha256=UuJpJeo3qQpTHVINeOpmP0NYmg8PhEFE3A8J
121
121
  ultralytics/data/scripts/get_coco128.sh,sha256=qmRQl_hOKrsdHrTrnyQuFIH01oDz3lfaz138OgGfLt8,650
122
122
  ultralytics/data/scripts/get_imagenet.sh,sha256=hr42H16bM47iT27rgS7MpEo-GeOZAYUQXgr0B2cwn48,1705
123
123
  ultralytics/engine/__init__.py,sha256=lm6MckFYCPTbqIoX7w0s_daxdjNeBeKW6DXppv1-QUM,70
124
- ultralytics/engine/exporter.py,sha256=54MtuyPJuE71pCdexjtl-rPJtHGNNHYZez7x0JDKpSQ,70867
124
+ ultralytics/engine/exporter.py,sha256=TPi9kG0X7u8RchiVu-Y9WvsEfOHJkH9SOxvKv-o_JXs,71197
125
125
  ultralytics/engine/model.py,sha256=uX6cTFdlLllGRbz8Lr90IZGb4OrtMDIHQEg7DxUqwe8,53449
126
126
  ultralytics/engine/predictor.py,sha256=4lfw2RbBDE7939011FcSCuznscrcnMuabZtc8GXaKO4,22735
127
127
  ultralytics/engine/results.py,sha256=uQ_tgvdxKAg28pRgb5WCHiqx9Ktu7wYiVbwZy_IJ5bo,71499
@@ -243,7 +243,7 @@ ultralytics/utils/benchmarks.py,sha256=wBsDrwtc6NRM9rIDmqeGQ_9yxOTetnchXXHwZSUhp
243
243
  ultralytics/utils/checks.py,sha256=EaZh6gmv8vk9dnmSLNusKBHMh-ZSD4NxA3wXVjVMa_o,35798
244
244
  ultralytics/utils/cpu.py,sha256=OPlVxROWhQp-kEa9EkeNRKRQ-jz0KwySu5a-h91JZjk,3634
245
245
  ultralytics/utils/dist.py,sha256=5xQhWK0OLORvseAL08UmG1LYdkiDVLquxmaGSnqiSqo,4151
246
- ultralytics/utils/downloads.py,sha256=JIlHfUg-qna5aOHRJupH7d5zob2qGZtRrs86Cp3zOJs,23029
246
+ ultralytics/utils/downloads.py,sha256=RrM_Uw3A62vFJBqxlYcQslGZHrCQXHnmloSuxag6MTE,23037
247
247
  ultralytics/utils/errors.py,sha256=XT9Ru7ivoBgofK6PlnyigGoa7Fmf5nEhyHtnD-8TRXI,1584
248
248
  ultralytics/utils/events.py,sha256=v2RmLlx78_K6xQfOAuUTJMOexAgNdiuiOvvnsH65oDA,4679
249
249
  ultralytics/utils/files.py,sha256=kxE2rkBuZL288nSN7jxLljmDnBgc16rekEXeRjhbUoo,8213
@@ -275,9 +275,9 @@ ultralytics/utils/callbacks/tensorboard.py,sha256=_4nfGK1dDLn6ijpvphBDhc-AS8qhS3
275
275
  ultralytics/utils/callbacks/wb.py,sha256=ngQO8EJ1kxJDF1YajScVtzBbm26jGuejA0uWeOyvf5A,7685
276
276
  ultralytics/utils/export/__init__.py,sha256=jQtf716PP0jt7bMoY9FkqmjG26KbvDzuR84jGhaBi2U,9901
277
277
  ultralytics/utils/export/imx.py,sha256=Jl5nuNxqaP_bY5yrV2NypmoJSrexHE71TxR72SDdjcg,11394
278
- ultralytics-8.3.206.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
279
- ultralytics-8.3.206.dist-info/METADATA,sha256=ZwaAICktsOQPV9MRi_rgsRzxsebAfuVaJ07pMD07cPQ,37667
280
- ultralytics-8.3.206.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
281
- ultralytics-8.3.206.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
282
- ultralytics-8.3.206.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
283
- ultralytics-8.3.206.dist-info/RECORD,,
278
+ ultralytics-8.3.207.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
279
+ ultralytics-8.3.207.dist-info/METADATA,sha256=dlpTOBive_4cYtIN0aV482aCEmTRk6QCbogW0O1Flgo,37667
280
+ ultralytics-8.3.207.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
281
+ ultralytics-8.3.207.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
282
+ ultralytics-8.3.207.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
283
+ ultralytics-8.3.207.dist-info/RECORD,,