1+ #
2+ # DeepLabCut Toolbox (deeplabcut.org)
3+ # © A. & M.W. Mathis Labs
4+ # https://github.com/DeepLabCut/DeepLabCut
5+ #
6+ # Please see AUTHORS for contributors.
7+ # https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS
8+ #
9+ # Licensed under GNU Lesser General Public License v3.0
10+ #
111import os
212
313# just expand this list when adding new models:
1222]
1323
1424
15- def get_dlclibrary_path ():
25+ def _get_dlclibrary_path ():
1626 """Get path of where dlclibrary (this repo) is currently running"""
1727 import importlib .util
28+
1829 return os .path .split (importlib .util .find_spec ("dlclibrary" ).origin )[0 ]
1930
2031
21- def loadmodelnames ():
22- """Load URLs and commits for available models"""
32+ def _loadmodelnames ():
33+ """Loads URLs and commit hashes for available models. """
2334 from ruamel .yaml import YAML
24- fn = os .path .join (get_dlclibrary_path (),"modelzoo_urls.yaml" )
35+
36+ fn = os .path .join (_get_dlclibrary_path (), "modelzoo_urls.yaml" )
2537 with open (fn ) as file :
2638 return YAML ().load (file )
2739
2840
29- def download_hugginface_model (modelname , target_dir , removeHFfolder = True ):
41+ def download_hugginface_model (modelname , target_dir = "." , removeHFfolder = True ):
3042 """
3143 Downloads a DeepLabCut Model Zoo Project from Hugging Face
44+
45+ Parameters
46+ ----------
47+ modelname : string
48+ Name of the ModelZoo model. For visualizations see: http://www.mackenziemathislab.org/dlc-modelzoo
49+ target_dir : directory (as string)
50+ Directory where to store the model weigths and pose_cfg.yaml file
51+ removeHFfolder : bool, default True
52+ Whether to remove the directory structure provided by HuggingFace after downloading and decompressing data into DeepLabCut format.
3253 """
3354 from huggingface_hub import hf_hub_download
3455 import tarfile , os
3556 from pathlib import Path
3657
37- neturls = loadmodelnames ()
58+ neturls = _loadmodelnames ()
3859
3960 if modelname in neturls .keys ():
4061 print ("Loading...." , modelname )
@@ -67,6 +88,7 @@ def download_hugginface_model(modelname, target_dir,removeHFfolder=True):
6788 if removeHFfolder :
6889 # Removing folder
6990 import shutil
91+
7092 shutil .rmtree (
7193 Path (os .path .join (target_dir , "models--" + url [0 ] + "--" + url [1 ]))
7294 )
@@ -81,8 +103,9 @@ def download_hugginface_model(modelname, target_dir,removeHFfolder=True):
81103 print ("Randomly downloading a model for testing..." )
82104
83105 import random
84- #modelname = 'full_cat'
106+
107+ # modelname = 'full_cat'
85108 modelname = random .choice (MODELOPTIONS )
86109
87- target_dir = ' /Users/alex/Downloads' # folder has to exist!
110+ target_dir = " /Users/alex/Downloads" # folder has to exist!
88111 download_hugginface_model (modelname , target_dir )
0 commit comments