Fix `unzip_file()` to directory issue (#6666)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
pull/6670/head
Glenn Jocher 1 year ago committed by GitHub
parent f89bfd7e01
commit 7c0e853237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      docs/en/integrations/clearml.md
  2. 13
      ultralytics/utils/checks.py
  3. 10
      ultralytics/utils/downloads.py

@ -171,8 +171,8 @@ This setup is applicable to cloud VMs, local GPUs, or laptops. ClearML Autoscale
ClearML's user-friendly interface allows easy cloning, editing, and enqueuing of tasks. Users can clone an existing experiment, adjust parameters or other details through the UI, and enqueue the task for execution. This streamlined process ensures that the ClearML Agent executing the task uses updated configurations, making it ideal for iterative experimentation and model fine-tuning.
<p align="center">
<img width="640" src="https://clear.ml/docs/latest/assets/images/integrations_yolov5-2483adea91df4d41bfdf1a37d28864d4.gif" alt="Cloning, Editing, and Enqueuing with ClearML">
<p align="center"><br>
<img width="100%" src="https://clear.ml/docs/latest/assets/images/integrations_yolov5-2483adea91df4d41bfdf1a37d28864d4.gif" alt="Cloning, Editing, and Enqueuing with ClearML">
</p>
## Summary

@ -196,11 +196,13 @@ def check_version(current: str = '0.0.0',
if not required: # if required is '' or None
return True
op = ''
version = ''
result = True
c = parse_version(current) # '1.2.3' -> (1, 2, 3)
for r in required.strip(',').split(','):
op, v = re.match(r'([^0-9]*)([\d.]+)', r).groups() # split '>=22.04' -> ('>=', '22.04')
v = parse_version(v) # '1.2.3' -> (1, 2, 3)
op, version = re.match(r'([^0-9]*)([\d.]+)', r).groups() # split '>=22.04' -> ('>=', '22.04')
v = parse_version(version) # '1.2.3' -> (1, 2, 3)
if op == '==' and c != v:
result = False
elif op == '!=' and c == v:
@ -214,12 +216,11 @@ def check_version(current: str = '0.0.0',
elif op == '<' and not (c < v):
result = False
if not result:
warning_message = \
f'WARNING ⚠ {name}{op}{required} is required, but {name}=={current} is currently installed {msg}'
warning = f'WARNING ⚠ {name}{op}{version} is required, but {name}=={current} is currently installed {msg}'
if hard:
raise ModuleNotFoundError(emojis(warning_message)) # assert version requirements met
raise ModuleNotFoundError(emojis(warning)) # assert version requirements met
if verbose:
LOGGER.warning(warning_message)
LOGGER.warning(warning)
return result

@ -161,9 +161,11 @@ 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 not files[0].endswith('/'): # zip has multiple files at top level
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: # zip has 1 top-level directory
else:
# Zip has 1 top-level directory
extract_path = path # i.e. ../datasets
path = Path(path) / list(top_level_dirs)[0] # i.e. ../datasets/coco8
@ -338,11 +340,11 @@ def safe_download(url,
if unzip and f.exists() and f.suffix in ('', '.zip', '.tar', '.gz'):
from zipfile import is_zipfile
unzip_dir = dir or f.parent # unzip to dir if provided else unzip in place
unzip_dir = (dir or f.parent).resolve() # unzip to dir if provided else unzip in place
if is_zipfile(f):
unzip_dir = unzip_file(file=f, path=unzip_dir, progress=progress) # unzip
elif f.suffix in ('.tar', '.gz'):
LOGGER.info(f'Unzipping {f} to {unzip_dir.resolve()}...')
LOGGER.info(f'Unzipping {f} to {unzip_dir}...')
subprocess.run(['tar', 'xf' if f.suffix == '.tar' else 'xfz', f, '--directory', unzip_dir], check=True)
if delete:
f.unlink() # remove zip

Loading…
Cancel
Save