create dir after model downloaded

This commit is contained in:
Jia Guo
2021-06-19 22:37:11 +08:00
parent 7afb4c44c8
commit 5ca3f995d5

View File

@@ -11,23 +11,19 @@ def download(sub_dir, name, force=False, root='~/.insightface'):
dir_path = os.path.join(_root, sub_dir, name) dir_path = os.path.join(_root, sub_dir, name)
if osp.exists(dir_path) and not force: if osp.exists(dir_path) and not force:
return dir_path return dir_path
if not os.path.exists(dir_path):
os.makedirs(dir_path)
print('download_path:', dir_path) print('download_path:', dir_path)
zip_file_path = os.path.join(_root, sub_dir, name + '.zip') zip_file_path = os.path.join(_root, sub_dir, name + '.zip')
model_url = "%s/%s/%s.zip"%(BASE_REPO_URL, sub_dir, name) model_url = "%s/%s/%s.zip"%(BASE_REPO_URL, sub_dir, name)
download_file(model_url, download_file(model_url,
path=zip_file_path, path=zip_file_path,
overwrite=True) overwrite=True)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
with zipfile.ZipFile(zip_file_path) as zf: with zipfile.ZipFile(zip_file_path) as zf:
zf.extractall(dir_path) zf.extractall(dir_path)
os.remove(zip_file_path) os.remove(zip_file_path)
return dir_path return dir_path
def ensure_available(sub_dir, name, root='~/.insightface'): def ensure_available(sub_dir, name, root='~/.insightface'):
_root = os.path.expanduser(root)
dir_path = os.path.join(_root, sub_dir, name)
if osp.exists(dir_path):
return dir_path
return download(sub_dir, name, force=False, root=root) return download(sub_dir, name, force=False, root=root)