From ab712288f7c6fea6819bc27da07e8ab5d70cdbaa Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 16 Mar 2024 01:54:45 +0100 Subject: [PATCH] `ultralytics 8.1.29` improved disk space checking on correct path (#8977) Signed-off-by: Glenn Jocher Co-authored-by: Kayzwer <68285002+Kayzwer@users.noreply.github.com> --- ultralytics/__init__.py | 2 +- ultralytics/nn/modules/block.py | 2 +- ultralytics/utils/downloads.py | 9 +++++---- ultralytics/utils/loss.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index e79ad3ed..f15d0d6d 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.1.28" +__version__ = "8.1.29" from ultralytics.data.explorer.explorer import Explorer from ultralytics.models import RTDETR, SAM, YOLO, YOLOWorld diff --git a/ultralytics/nn/modules/block.py b/ultralytics/nn/modules/block.py index c772f812..a263b603 100644 --- a/ultralytics/nn/modules/block.py +++ b/ultralytics/nn/modules/block.py @@ -57,7 +57,7 @@ class DFL(nn.Module): def forward(self, x): """Applies a transformer layer on input tensor 'x' and returns a tensor.""" - b, c, a = x.shape # batch, channels, anchors + b, _, a = x.shape # batch, channels, anchors return self.conv(x.view(b, 4, self.c1, a).transpose(2, 1).softmax(1)).view(b, 4, a) # return self.conv(x.view(b, self.c1, 4, a).softmax(1)).view(b, 4, a) diff --git a/ultralytics/utils/downloads.py b/ultralytics/utils/downloads.py index f55d8af7..c9c33a85 100644 --- a/ultralytics/utils/downloads.py +++ b/ultralytics/utils/downloads.py @@ -43,7 +43,7 @@ def is_url(url, check=True): Defaults to True. Returns: - (bool): Returns True if the string is a valid URL. If 'check' is True, also returns True if the URL exists online. + (bool): Returns True for a valid URL. If 'check' is True, also returns True if the URL exists online. Returns False otherwise. Example: @@ -191,12 +191,13 @@ def unzip_file(file, path=None, exclude=(".DS_Store", "__MACOSX"), exist_ok=Fals return path # return unzip dir -def check_disk_space(url="https://ultralytics.com/assets/coco128.zip", sf=1.5, hard=True): +def check_disk_space(url="https://ultralytics.com/assets/coco128.zip", path=Path.cwd(), sf=1.5, hard=True): """ Check if there is sufficient disk space to download and store a file. Args: url (str, optional): The URL to the file. Defaults to 'https://ultralytics.com/assets/coco128.zip'. + path (str | Path, optional): The path or drive to check the available free space on. sf (float, optional): Safety factor, the multiplier for the required free space. Defaults to 2.0. hard (bool, optional): Whether to throw an error or not on insufficient disk space. Defaults to True. @@ -212,7 +213,7 @@ def check_disk_space(url="https://ultralytics.com/assets/coco128.zip", sf=1.5, h # Check file size gib = 1 << 30 # bytes per GiB data = int(r.headers.get("Content-Length", 0)) / gib # file size (GB) - total, used, free = (x / gib for x in shutil.disk_usage(Path.cwd())) # bytes + total, used, free = (x / gib for x in shutil.disk_usage(path)) # bytes if data * sf < free: return True # sufficient space @@ -319,7 +320,7 @@ def safe_download( desc = f"Downloading {url if gdrive else clean_url(url)} to '{f}'" LOGGER.info(f"{desc}...") f.parent.mkdir(parents=True, exist_ok=True) # make directory if missing - check_disk_space(url) + check_disk_space(url, path=f.parent) for i in range(retry + 1): try: if curl or i > 0: # curl download with retry, continue diff --git a/ultralytics/utils/loss.py b/ultralytics/utils/loss.py index 5c991990..360a292a 100644 --- a/ultralytics/utils/loss.py +++ b/ultralytics/utils/loss.py @@ -140,7 +140,7 @@ class KeypointLoss(nn.Module): d = (pred_kpts[..., 0] - gt_kpts[..., 0]).pow(2) + (pred_kpts[..., 1] - gt_kpts[..., 1]).pow(2) kpt_loss_factor = kpt_mask.shape[1] / (torch.sum(kpt_mask != 0, dim=1) + 1e-9) # e = d / (2 * (area * self.sigmas) ** 2 + 1e-9) # from formula - e = d / (2 * self.sigmas).pow(2) / (area + 1e-9) / 2 # from cocoeval + e = d / ((2 * self.sigmas).pow(2) * (area + 1e-9) * 2) # from cocoeval return (kpt_loss_factor.view(-1, 1) * ((1 - torch.exp(-e)) * kpt_mask)).mean()