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>
This commit is contained in:
Glenn Jocher 2023-11-30 00:32:51 +01:00 committed by GitHub
parent f89bfd7e01
commit 7c0e853237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 12 deletions

View File

@ -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. 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"> <p align="center"><br>
<img width="640" src="https://clear.ml/docs/latest/assets/images/integrations_yolov5-2483adea91df4d41bfdf1a37d28864d4.gif" alt="Cloning, Editing, and Enqueuing with ClearML"> <img width="100%" src="https://clear.ml/docs/latest/assets/images/integrations_yolov5-2483adea91df4d41bfdf1a37d28864d4.gif" alt="Cloning, Editing, and Enqueuing with ClearML">
</p> </p>
## Summary ## Summary

View File

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

View File

@ -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)] 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} 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 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 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. ../datasets/coco8
@ -338,11 +340,11 @@ def safe_download(url,
if unzip and f.exists() and f.suffix in ('', '.zip', '.tar', '.gz'): if unzip and f.exists() and f.suffix in ('', '.zip', '.tar', '.gz'):
from zipfile import is_zipfile 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): if is_zipfile(f):
unzip_dir = unzip_file(file=f, path=unzip_dir, progress=progress) # unzip unzip_dir = unzip_file(file=f, path=unzip_dir, progress=progress) # unzip
elif f.suffix in ('.tar', '.gz'): 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) subprocess.run(['tar', 'xf' if f.suffix == '.tar' else 'xfz', f, '--directory', unzip_dir], check=True)
if delete: if delete:
f.unlink() # remove zip f.unlink() # remove zip