Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.

Commit c7aa07c

Browse files
committed
v0.0 TF 2 for DLC release
1 parent ff2c11e commit c7aa07c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+7927
-4273
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5+
*.ckpt #TF
6+
57

68
# C extensions
79
*.so

conda-environments/DLCcore-CPU.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# DLC-CPU.yaml
2+
3+
#DeepLabCut2.0 Toolbox (deeplabcut.org)
4+
#© A. & M. Mathis Labs
5+
#https://github.com/AlexEMG/DeepLabCut
6+
#Please see AUTHORS for contributors.
7+
8+
#https://github.com/AlexEMG/DeepLabCut/blob/master/AUTHORS
9+
#Licensed under GNU Lesser General Public License v3.0
10+
11+
# install: conda env create -f DLCcore-CPU.yaml
12+
# update: conda env update -f DLCcore-CPU.yaml
13+
14+
name: DLCcore-CPU
15+
dependencies:
16+
- python=3.7
17+
- pip
18+
- jupyter
19+
- nb_conda
20+
- tensorflow
21+
- wxpython<4.1.0
22+
- Shapely
23+
- pip:
24+
- deeplabcutcore
25+
- tf_slim

conda-environments/DLCcore-GPU.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# DLC-GPU.yaml
2+
3+
#DeepLabCut2.0 Toolbox (deeplabcut.org)
4+
#© A. & M. Mathis Labs
5+
#https://github.com/AlexEMG/DeepLabCut
6+
#Please see AUTHORS for contributors.
7+
8+
#https://github.com/AlexEMG/DeepLabCut/blob/master/AUTHORS
9+
#Licensed under GNU Lesser General Public License v3.0
10+
#
11+
12+
# install: conda env create -f DLCcore-GPU.yaml
13+
# update: conda env update -f DLCcore-GPU.yaml
14+
15+
name: DLCcore-GPU
16+
dependencies:
17+
- python=3.7
18+
- pip
19+
- tensorflow-gpu
20+
- cudnn=7
21+
- wxpython<4.1.0
22+
- jupyter
23+
- nb_conda
24+
- Shapely
25+
- pip:
26+
- deeplabcutcore
27+
- tf_slim

deeplabcutcore/__init__.py

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,66 @@
1212
import platform
1313

1414
# Supress tensorflow warning messages
15-
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
16-
DEBUG = True and 'DEBUG' in os.environ and os.environ['DEBUG']
15+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
16+
DEBUG = True and "DEBUG" in os.environ and os.environ["DEBUG"]
1717
from deeplabcutcore import DEBUG
1818

1919

20-
from deeplabcutcore.create_project import create_new_project, create_new_project_3d, add_new_videos, load_demo_data
21-
from deeplabcutcore.create_project import create_pretrained_project, create_pretrained_human_project
22-
from deeplabcutcore.generate_training_dataset import extract_frames, select_cropping_area
23-
from deeplabcutcore.generate_training_dataset import check_labels,create_training_dataset, mergeandsplit, create_training_model_comparison
24-
from deeplabcutcore.utils import create_labeled_video,plot_trajectories, auxiliaryfunctions, convertcsv2h5, convertannotationdata_fromwindows2unixstyle, analyze_videos_converth5_to_csv, auxfun_videos
20+
from deeplabcutcore.create_project import (
21+
create_new_project,
22+
create_new_project_3d,
23+
add_new_videos,
24+
load_demo_data,
25+
)
26+
from deeplabcutcore.create_project import (
27+
create_pretrained_project,
28+
create_pretrained_human_project,
29+
)
30+
from deeplabcutcore.generate_training_dataset import (
31+
extract_frames,
32+
select_cropping_area,
33+
)
34+
from deeplabcutcore.generate_training_dataset import (
35+
check_labels,
36+
create_training_dataset,
37+
mergeandsplit,
38+
create_training_model_comparison,
39+
)
40+
from deeplabcutcore.utils import (
41+
create_labeled_video,
42+
plot_trajectories,
43+
auxiliaryfunctions,
44+
convertcsv2h5,
45+
convertannotationdata_fromwindows2unixstyle,
46+
analyze_videos_converth5_to_csv,
47+
auxfun_videos,
48+
)
2549
from deeplabcutcore.utils.auxfun_videos import ShortenVideo, DownSampleVideo, CropVideo
2650

2751
# Train, evaluate & predict functions / require TF
28-
from deeplabcutcore.pose_estimation_tensorflow import train_network, return_train_network_path
29-
from deeplabcutcore.pose_estimation_tensorflow import evaluate_network, return_evaluate_network_data
30-
from deeplabcutcore.pose_estimation_tensorflow import analyze_videos, analyze_time_lapse_frames
52+
from deeplabcutcore.pose_estimation_tensorflow import (
53+
train_network,
54+
return_train_network_path,
55+
)
56+
from deeplabcutcore.pose_estimation_tensorflow import (
57+
evaluate_network,
58+
return_evaluate_network_data,
59+
)
60+
from deeplabcutcore.pose_estimation_tensorflow import (
61+
analyze_videos,
62+
analyze_time_lapse_frames,
63+
)
3164
from deeplabcutcore.pose_estimation_tensorflow import export_model
3265

33-
from deeplabcutcore.pose_estimation_3d import calibrate_cameras,check_undistortion,triangulate,create_labeled_video_3d
66+
from deeplabcutcore.pose_estimation_3d import (
67+
calibrate_cameras,
68+
check_undistortion,
69+
triangulate,
70+
create_labeled_video_3d,
71+
)
3472

35-
from deeplabcutcore.refine_training_dataset import extract_outlier_frames, merge_datasets
73+
from deeplabcutcore.refine_training_dataset import (
74+
extract_outlier_frames,
75+
merge_datasets,
76+
)
3677
from deeplabcutcore.post_processing import filterpredictions, analyzeskeleton

deeplabcutcore/create_project/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
from deeplabcutcore.create_project.new_3d import create_new_project_3d
33
from deeplabcutcore.create_project.add import add_new_videos
44
from deeplabcutcore.create_project.demo_data import load_demo_data
5-
from deeplabcutcore.create_project.modelzoo import create_pretrained_human_project, create_pretrained_project
5+
from deeplabcutcore.create_project.modelzoo import (
6+
create_pretrained_human_project,
7+
create_pretrained_project,
8+
)

deeplabcutcore/create_project/add.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111

12-
def add_new_videos(config,videos,copy_videos=False,coords=None):
12+
def add_new_videos(config, videos, copy_videos=False, coords=None):
1313
"""
1414
Add new videos to the config file at any stage of the project.
1515
@@ -49,26 +49,26 @@ def add_new_videos(config,videos,copy_videos=False,coords=None):
4949
# Read the config file
5050
cfg = auxiliaryfunctions.read_config(config)
5151

52-
video_path = Path(config).parents[0] / 'videos'
53-
data_path = Path(config).parents[0] / 'labeled-data'
52+
video_path = Path(config).parents[0] / "videos"
53+
data_path = Path(config).parents[0] / "labeled-data"
5454
videos = [Path(vp) for vp in videos]
5555

56-
dirs = [data_path/Path(i.stem) for i in videos]
56+
dirs = [data_path / Path(i.stem) for i in videos]
5757

5858
for p in dirs:
5959
"""
6060
Creates directory under data & perhaps copies videos (to /video)
6161
"""
62-
p.mkdir(parents = True, exist_ok = True)
62+
p.mkdir(parents=True, exist_ok=True)
6363

6464
destinations = [video_path.joinpath(vp.name) for vp in videos]
65-
if copy_videos==True:
65+
if copy_videos == True:
6666
for src, dst in zip(videos, destinations):
6767
if dst.exists():
6868
pass
6969
else:
7070
print("Copying the videos")
71-
shutil.copy(os.fspath(src),os.fspath(dst))
71+
shutil.copy(os.fspath(src), os.fspath(dst))
7272
else:
7373
for src, dst in zip(videos, destinations):
7474
if dst.exists():
@@ -79,29 +79,35 @@ def add_new_videos(config,videos,copy_videos=False,coords=None):
7979
dst = str(dst)
8080
os.symlink(src, dst)
8181

82-
if copy_videos==True:
83-
videos=destinations # in this case the *new* location should be added to the config file
82+
if copy_videos == True:
83+
videos = (
84+
destinations
85+
) # in this case the *new* location should be added to the config file
8486
# adds the video list to the config.yaml file
85-
for idx,video in enumerate(videos):
87+
for idx, video in enumerate(videos):
8688
try:
87-
# For windows os.path.realpath does not work and does not link to the real video.
88-
video_path = str(Path.resolve(Path(video)))
89-
# video_path = os.path.realpath(video)
89+
# For windows os.path.realpath does not work and does not link to the real video.
90+
video_path = str(Path.resolve(Path(video)))
91+
# video_path = os.path.realpath(video)
9092
except:
91-
video_path = os.readlink(video)
93+
video_path = os.readlink(video)
9294

9395
vcap = cv2.VideoCapture(video_path)
9496
if vcap.isOpened():
9597
# get vcap property
96-
width = int(vcap.get(cv2.CAP_PROP_FRAME_WIDTH))
97-
height = int(vcap.get(cv2.CAP_PROP_FRAME_HEIGHT))
98-
if coords == None:
99-
cfg['video_sets'].update({video_path : {'crop': ', '.join(map(str, [0, width, 0, height]))}})
100-
else:
98+
width = int(vcap.get(cv2.CAP_PROP_FRAME_WIDTH))
99+
height = int(vcap.get(cv2.CAP_PROP_FRAME_HEIGHT))
100+
if coords == None:
101+
cfg["video_sets"].update(
102+
{video_path: {"crop": ", ".join(map(str, [0, width, 0, height]))}}
103+
)
104+
else:
101105
c = coords[idx]
102-
cfg['video_sets'].update({video_path : {'crop': ', '.join(map(str, c))}})
106+
cfg["video_sets"].update({video_path: {"crop": ", ".join(map(str, c))}})
103107
else:
104-
print("Cannot open the video file!")
108+
print("Cannot open the video file!")
105109

106-
auxiliaryfunctions.write_config(config,cfg)
107-
print("New video was added to the project! Use the function 'extract_frames' to select frames for labeling.")
110+
auxiliaryfunctions.write_config(config, cfg)
111+
print(
112+
"New video was added to the project! Use the function 'extract_frames' to select frames for labeling."
113+
)

deeplabcutcore/create_project/demo_data.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
import deeplabcutcore
1414
from deeplabcutcore.utils import auxiliaryfunctions
1515

16-
def load_demo_data(config,createtrainingset=True):
17-
"""
16+
17+
def load_demo_data(config, createtrainingset=True):
18+
"""
1819
Loads the demo data. Make sure that you are in the same directory where you have downloaded or cloned the deeplabcutcore.
1920
2021
Parameter
@@ -27,13 +28,14 @@ def load_demo_data(config,createtrainingset=True):
2728
>>> deeplabcutcore.load_demo_data('config.yaml')
2829
--------
2930
"""
30-
config = Path(config).resolve()
31-
config = str(config)
31+
config = Path(config).resolve()
32+
config = str(config)
33+
34+
transform_data(config)
35+
if createtrainingset:
36+
print("Loaded, now creating training data...")
37+
deeplabcutcore.create_training_dataset(config, num_shuffles=1)
3238

33-
transform_data(config)
34-
if createtrainingset:
35-
print("Loaded, now creating training data...")
36-
deeplabcutcore.create_training_dataset(config, num_shuffles=1)
3739

3840
def transform_data(config):
3941
"""
@@ -45,15 +47,17 @@ def transform_data(config):
4547
cfg = auxiliaryfunctions.read_config(config)
4648
project_path = str(Path(config).parents[0])
4749

48-
cfg['project_path'] = project_path
49-
if 'Reaching' in project_path:
50-
video_file = os.path.join(project_path, 'videos','reachingvideo1.avi')
51-
elif 'openfield' in project_path:
52-
video_file = os.path.join(project_path, 'videos','m4s1.mp4')
50+
cfg["project_path"] = project_path
51+
if "Reaching" in project_path:
52+
video_file = os.path.join(project_path, "videos", "reachingvideo1.avi")
53+
elif "openfield" in project_path:
54+
video_file = os.path.join(project_path, "videos", "m4s1.mp4")
5355
else:
5456
print("This is not an offical demo dataset.")
5557

56-
if 'WILL BE AUTOMATICALLY UPDATED BY DEMO CODE' in cfg['video_sets'].keys():
57-
cfg['video_sets'][str(video_file)] = cfg['video_sets'].pop('WILL BE AUTOMATICALLY UPDATED BY DEMO CODE')
58+
if "WILL BE AUTOMATICALLY UPDATED BY DEMO CODE" in cfg["video_sets"].keys():
59+
cfg["video_sets"][str(video_file)] = cfg["video_sets"].pop(
60+
"WILL BE AUTOMATICALLY UPDATED BY DEMO CODE"
61+
)
5862

59-
auxiliaryfunctions.write_config(config,cfg)
63+
auxiliaryfunctions.write_config(config, cfg)

0 commit comments

Comments
 (0)