`ultralytics 8.2.41` fix HUB unzip subdirectory bug (#13913)

pull/13839/head^2 v8.2.41
Glenn Jocher 5 months ago committed by GitHub
parent 9362e759f7
commit e30b7c24f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      ultralytics/__init__.py
  2. 6
      ultralytics/hub/session.py
  3. 12
      ultralytics/utils/downloads.py

@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
__version__ = "8.2.40"
__version__ = "8.2.41"
import os

@ -71,7 +71,11 @@ class HUBTrainingSession:
"""Class method to create an authenticated HUBTrainingSession or return None."""
try:
session = cls(identifier)
assert session.client.authenticated, "HUB not authenticated"
if not session.client.authenticated:
if identifier.startswith(f"{HUB_WEB_ROOT}/models/"):
LOGGER.warning(f"{PREFIX}WARNING ⚠ Login to Ultralytics HUB with 'yolo hub login API_KEY'.")
exit()
return None
if args and not identifier.startswith(f"{HUB_WEB_ROOT}/models/"): # not a HUB model URL
session.create_model(args)
assert session.model.id, "HUB model not loaded correctly"

@ -168,13 +168,15 @@ def unzip_file(file, path=None, exclude=(".DS_Store", "__MACOSX"), exist_ok=Fals
files = [f for f in zipObj.namelist() if all(x not in f for x in exclude)]
top_level_dirs = {Path(f).parts[0] for f in files}
if len(top_level_dirs) > 1 or (len(files) > 1 and not files[0].endswith("/")):
# Zip has multiple files at top level
path = extract_path = Path(path) / Path(file).stem # i.e. ../datasets/coco8
else:
# Decide to unzip directly or unzip into a directory
unzip_as_dir = len(top_level_dirs) == 1 # (len(files) > 1 and not files[0].endswith("/"))
if unzip_as_dir:
# Zip has 1 top-level directory
extract_path = path # i.e. ../datasets
path = Path(path) / list(top_level_dirs)[0] # i.e. ../datasets/coco8
path = Path(path) / list(top_level_dirs)[0] # i.e. extract coco8/ dir to ../datasets/
else:
# Zip has multiple files at top level
path = extract_path = Path(path) / Path(file).stem # i.e. extract multiple files to ../datasets/coco8/
# Check if destination directory already exists and contains files
if path.exists() and any(path.iterdir()) and not exist_ok:

Loading…
Cancel
Save