ultralytics 8.2.41 fix HUB unzip subdirectory bug (#13913)
This commit is contained in:
parent
9362e759f7
commit
e30b7c24f2
3 changed files with 13 additions and 7 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue