Skip to content

Commit 61515f9

Browse files
committed
Added docstrings, headers, black
1 parent 389e751 commit 61515f9

File tree

12 files changed

+210
-172
lines changed

12 files changed

+210
-172
lines changed

NOTICE.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# Main repository license
3+
- header: |
4+
DeepLabCut Toolbox (deeplabcut.org)
5+
© A. & M.W. Mathis Labs
6+
https://github.com/DeepLabCut/DeepLabCut
7+
8+
Please see AUTHORS for contributors.
9+
https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS
10+
11+
Licensed under GNU Lesser General Public License v3.0
12+
include:
13+
- 'dlclibrary/**/*.py'
14+
- 'dlclibrary/*.yaml'
15+
- 'tests/**/*.py'
16+
- 'tools/*.py'
17+
- 'setup.py'

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
# DLClib
2-
Library of useful functions for DeepLabCut
1+
[![Generic badge](https://img.shields.io/badge/Contributions-Welcome-brightgreen.svg)](README.md)
2+
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
3+
4+
# DLClibrary
5+
6+
DLClibrary is a lightweight library supporting universal functions for the DeepLabCut ecosystem.
7+
8+
Supported functions (at this point):
9+
- API for downloading model weights from the model zoo

dlclibrary/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
"""
2-
DeepLabCut2.0 Toolbox (deeplabcut.org)
3-
© A. & M. 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-
Licensed under GNU Lesser General Public License v3.0
9-
"""
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+
#
1011

1112
from dlclibrary.dlcmodelzoo.modelzoo_download import download_hugginface_model
1213
from dlclibrary.version import __version__, VERSION

dlclibrary/dlcmodelzoo/__init__.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
# just expand this list with new projects
2-
3-
Modeloptions = [
4-
"full_human",
5-
"full_cat",
6-
"primate_face",
7-
"mouse_pupil_vclose",
8-
"horse_sideview",
9-
"full_macaque",
10-
"superanimal_mouse",
11-
]
12-
13-
"""
14-
Modeloptions = [
15-
"full_human",
16-
"full_cat",
17-
"full_dog",
18-
"primate_face",
19-
"mouse_pupil_vclose",
20-
"horse_sideview",
21-
"full_macaque",
22-
"full_cheetah",
23-
] # just expand this list with new projects
24-
"""
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+
#

dlclibrary/dlcmodelzoo/modelzoo_download.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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+
#
111
import os
212

313
# just expand this list when adding new models:
@@ -12,29 +22,40 @@
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)

dlclibrary/modelzoo_urls.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
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+
##
11+
12+
113

214
#Model Zoo from HuggingFace
315
full_human: mwmathis/DeepLabCutModelZoo-DLC_human_fullbody_resnet_101/DLC_human_fullbody_resnet_101.tar.gz

dlclibrary/version.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
"""
2-
DeepLabCut Toolbox (deeplabcut.org)
3-
© A. & M. Mathis Labs
4-
https://github.com/DeepLabCut/DeepLabCut
5-
Please see AUTHORS for contributors.
6-
https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS
7-
Licensed under GNU Lesser General Public License v3.0
8-
"""
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+
#
911

1012
__version__ = "0.0b0"
1113
VERSION = __version__

pose_cfg.yaml

Lines changed: 0 additions & 106 deletions
This file was deleted.

setup.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
3-
"""
4-
DeepLabCut Toolbox (deeplabcut.org)
5-
© A. & M. Mathis Labs
6-
https://github.com/DeepLabCut/DeepLabCut
7-
Please see AUTHORS for contributors.
8-
https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS
9-
Licensed under GNU Lesser General Public License v3.0
10-
"""
11-
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+
#
1211
import setuptools
1312

1413
with open("README.md", "r") as fh:
@@ -31,7 +30,7 @@
3130
(
3231
"dlclibrary",
3332
[
34-
"dlclibrary/modelzoo_urls.yaml",
33+
"dlclibrary/modelzoo_urls.yaml",
3534
],
3635
)
3736
],

tests/test_modeldownload.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
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+
#
111
import pytest
212

13+
314
def test_catdownload():
415
# TODO: just download the lightweight stuff..
516
import dlclibrary, os
617

7-
os.mkdir('cat')
8-
dlclibrary.download_hugginface_model('full_cat','cat')
9-
18+
os.mkdir("cat")
19+
dlclibrary.download_hugginface_model("full_cat", "cat")
1020

1121
assert os.path.exists("cat/pose_cfg.yaml")
1222
assert os.path.exists("cat/snapshot-75000.meta")
1323

1424
import shutil
25+
1526
shutil.rmtree("cat")

0 commit comments

Comments
 (0)