mirror of
https://github.com/deepinsight/insightface.git
synced 2026-05-14 04:12:35 +00:00
0.3.3, supports model auto download
This commit is contained in:
@@ -5,7 +5,8 @@ For insightface pip-package <= 0.1.5, we use MXNet as inference backend, please
|
||||
|
||||
Starting from insightface>=0.2, we use onnxruntime as inference backend.
|
||||
|
||||
Please first download our **antelope** model release by command:
|
||||
For insightface>=0.3.3, model package will be downloaded automatically.
|
||||
For insightface==0.3.2, you must first download our **antelope** model release by command:
|
||||
|
||||
```
|
||||
insightface-cli model.download antelope
|
||||
|
||||
@@ -11,7 +11,7 @@ except ImportError:
|
||||
"Unable to import dependency onnxruntime. "
|
||||
)
|
||||
|
||||
__version__ = '0.3.2'
|
||||
__version__ = '0.3.3'
|
||||
|
||||
from . import model_zoo
|
||||
from . import utils
|
||||
|
||||
@@ -14,7 +14,7 @@ import os.path as osp
|
||||
from numpy.linalg import norm
|
||||
from ..model_zoo import model_zoo
|
||||
from ..utils import face_align
|
||||
from ..utils import get_model_dir
|
||||
from ..utils import ensure_available
|
||||
from .common import Face
|
||||
from ..utils import DEFAULT_MP_NAME
|
||||
|
||||
@@ -25,7 +25,8 @@ class FaceAnalysis:
|
||||
self.models = {}
|
||||
#root = os.path.expanduser(root)
|
||||
#self.model_dir = osp.join(root, name)
|
||||
self.model_dir = get_model_dir(name, root)
|
||||
#self.model_dir = get_model_dir(name, root)
|
||||
self.model_dir = ensure_available('models', name)
|
||||
onnx_files = glob.glob(osp.join(self.model_dir, '*.onnx'))
|
||||
onnx_files = sorted(onnx_files)
|
||||
for onnx_file in onnx_files:
|
||||
|
||||
@@ -5,7 +5,7 @@ import os
|
||||
import os.path as osp
|
||||
import zipfile
|
||||
import glob
|
||||
from ..utils import download, check_sha1
|
||||
from ..utils import download
|
||||
|
||||
|
||||
def model_download_command_factory(args):
|
||||
@@ -27,27 +27,10 @@ class ModelDownloadCommand(BaseInsightFaceCLICommand):
|
||||
download_parser.set_defaults(func=model_download_command_factory)
|
||||
|
||||
def __init__(self, model: str, root: str, force: bool):
|
||||
self.base_repo_url = 'http://storage.insightface.ai/files/'
|
||||
self._model = model
|
||||
self._root = os.path.expanduser(root)
|
||||
self._root = root
|
||||
self._force = force
|
||||
|
||||
def run(self):
|
||||
if not os.path.exists(self._root):
|
||||
os.makedirs(self._root)
|
||||
dir_path = os.path.join(self._root, 'models', self._model)
|
||||
if osp.exists(dir_path) and not self._force:
|
||||
return
|
||||
if not os.path.exists(dir_path):
|
||||
os.makedirs(dir_path)
|
||||
|
||||
print('dir_path:', dir_path)
|
||||
zip_file_path = os.path.join(self._root, 'models', self._model + '.zip')
|
||||
model_url = "%s/models/%s.zip"%(self.base_repo_url, self._model)
|
||||
download(model_url,
|
||||
path=zip_file_path,
|
||||
overwrite=True)
|
||||
with zipfile.ZipFile(zip_file_path) as zf:
|
||||
zf.extractall(dir_path)
|
||||
os.remove(zip_file_path)
|
||||
download('models', self._model, force=self._force, root=self._root)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from __future__ import absolute_import
|
||||
#from . import metrics
|
||||
#from . import parallel
|
||||
|
||||
from .download import download, check_sha1
|
||||
from .storage import download, ensure_available
|
||||
from .filesystem import get_model_dir
|
||||
from .filesystem import makedirs, try_import_dali
|
||||
from .constant import *
|
||||
|
||||
@@ -33,7 +33,7 @@ def check_sha1(filename, sha1_hash):
|
||||
return sha1.hexdigest()[0:l] == sha1_hash[0:l]
|
||||
|
||||
|
||||
def download(url, path=None, overwrite=False, sha1_hash=None):
|
||||
def download_file(url, path=None, overwrite=False, sha1_hash=None):
|
||||
"""Download an given URL
|
||||
Parameters
|
||||
----------
|
||||
|
||||
33
python-package/insightface/utils/storage.py
Normal file
33
python-package/insightface/utils/storage.py
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
import os
|
||||
import os.path as osp
|
||||
import zipfile
|
||||
from .download import download_file
|
||||
|
||||
BASE_REPO_URL='http://storage.insightface.ai/files'
|
||||
|
||||
def download(sub_dir, name, force=False, root='~/.insightface'):
|
||||
_root = os.path.expanduser(root)
|
||||
dir_path = os.path.join(_root, sub_dir, name)
|
||||
if osp.exists(dir_path) and not force:
|
||||
return dir_path
|
||||
if not os.path.exists(dir_path):
|
||||
os.makedirs(dir_path)
|
||||
print('download_path:', dir_path)
|
||||
zip_file_path = os.path.join(_root, sub_dir, name + '.zip')
|
||||
model_url = "%s/%s/%s.zip"%(BASE_REPO_URL, sub_dir, name)
|
||||
download_file(model_url,
|
||||
path=zip_file_path,
|
||||
overwrite=True)
|
||||
with zipfile.ZipFile(zip_file_path) as zf:
|
||||
zf.extractall(dir_path)
|
||||
os.remove(zip_file_path)
|
||||
return dir_path
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user