Team Ai
Apppublic

Shellbrady/LivePortrait5

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
storage.py53 linesDownload Raw Back to utils
1 2import os3import os.path as osp4import zipfile5from .download import download_file6 7BASE_REPO_URL = 'https://github.com/deepinsight/insightface/releases/download/v0.7'8 9def download(sub_dir, name, force=False, root='~/.insightface'):10    _root = os.path.expanduser(root)11    dir_path = os.path.join(_root, sub_dir, name)12    if osp.exists(dir_path) and not force:13        return dir_path14    print('download_path:', dir_path)15    zip_file_path = os.path.join(_root, sub_dir, name + '.zip')16    model_url = "%s/%s.zip"%(BASE_REPO_URL, name)17    download_file(model_url,18             path=zip_file_path,19             overwrite=True)20    if not os.path.exists(dir_path):21        os.makedirs(dir_path)22    with zipfile.ZipFile(zip_file_path) as zf:23        zf.extractall(dir_path)24    #os.remove(zip_file_path)25    return dir_path26 27def ensure_available(sub_dir, name, root='~/.insightface'):28    return download(sub_dir, name, force=False, root=root)29 30def download_onnx(sub_dir, model_file, force=False, root='~/.insightface', download_zip=False):31    _root = os.path.expanduser(root)32    model_root = osp.join(_root, sub_dir)33    new_model_file = osp.join(model_root, model_file)34    if osp.exists(new_model_file) and not force:35        return new_model_file36    if not osp.exists(model_root):37        os.makedirs(model_root)38    print('download_path:', new_model_file)39    if not download_zip:40        model_url = "%s/%s"%(BASE_REPO_URL, model_file)41        download_file(model_url,42                 path=new_model_file,43                 overwrite=True)44    else:45        model_url = "%s/%s.zip"%(BASE_REPO_URL, model_file)46        zip_file_path = new_model_file+".zip"47        download_file(model_url,48                 path=zip_file_path,49                 overwrite=True)50        with zipfile.ZipFile(zip_file_path) as zf:51            zf.extractall(model_root)52        return new_model_file53