Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9b62a9e
dlclive: add tf_config as parameter
gkane26 Jun 9, 2020
bd2d3cd
graph: add tfconfig, new full load graph function
gkane26 Jun 9, 2020
eab4370
bench + display: add display to benchmarking, fix bugs in display
gkane26 Jun 9, 2020
c8ca18d
fix bugs in display
gkane26 Jun 9, 2020
d33b5f2
add kwargs to processors
gkane26 Jun 15, 2020
a818b6d
clean up load graph, color conversions
gkane26 Jun 15, 2020
65c0cfe
dlclive: add kwargs to get_pose and init_inference
gkane26 Jun 19, 2020
f8d35a5
add kalman filter processor
gkane26 Jun 30, 2020
3647550
kalmanfilter processor: update delta time
gkane26 Jul 9, 2020
cca80d8
dlclive: destroy display on close
gkane26 Jul 9, 2020
5f4ef09
new analyze tools: speed bench, display, analyze pose and labeled video
gkane26 Jul 9, 2020
3407376
dlclive and graph: clean up/benign bug fix
gkane26 Jul 9, 2020
95cedd9
fix colormaps for display
gkane26 Jul 9, 2020
01a7bbe
update readme: add benchmark info
gkane26 Jul 9, 2020
9b0ef34
setup: add pandas and tables, needed for analyze_videos
gkane26 Jul 9, 2020
4436266
Update kalmanfilter.py
MMathisLab Jul 9, 2020
8ea6b97
change display_lik to pcutoff
gkane26 Jul 9, 2020
6a6a0d5
resolve setup and readme conflicts
gkane26 Jul 9, 2020
bbabf80
Merge branch 'master' into gk-dev
gkane26 Jul 9, 2020
de06ad2
Update README.md
MMathisLab Jul 9, 2020
2aa7dc8
fixed resize in python, check cmd
MMathisLab Jul 9, 2020
2fff10f
Update README.md
MMathisLab Jul 9, 2020
faade24
analyze: allow pixels/resize to be scalar or list
gkane26 Jul 10, 2020
54fed1d
fix TF warnings
MMathisLab Jul 10, 2020
a739cf6
changed name to benchmark_videos
MMathisLab Jul 10, 2020
a7c50e7
Update README.md
MMathisLab Jul 10, 2020
84aa1a6
dlclive: tfgpu flip x and y
gkane26 Jul 10, 2020
dd25669
Merge branch 'gk-dev' of https://github.com/AlexEMG/DeepLabCut-live i…
gkane26 Jul 10, 2020
768b8fe
name update
MMathisLab Jul 10, 2020
ab35d11
complete convert analyze to benchmarking
gkane26 Jul 13, 2020
4cb299c
merge master into gk-dev; keep most of master bench.py
gkane26 Jul 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,29 @@ dlclive.benchmark_videos('/path/to/exported/model', ['/path/to/video1', '/path/t
```
##### command line
```
dlc-live-analyze /path/to/exported/model /path/to/video1 /path/to/video2 -o /path/to/output -r 1.0 0.75 0.5
dlc-live-benchmark /path/to/exported/model /path/to/video1 /path/to/video2 -o /path/to/output -r 1.0 0.75 0.5
```

2. Display keypoints to visually inspect the accuracy of exported models on different image sizes (note, this is slow and only for testing purposes):

##### python
```python
dlclive.benchmark_videos('/path/to/exported/model', '/path/to/video', resize=[0.5], display=True, pcutoff=0.5, display_radius=4, cmap='bmy')
dlclive.benchmark_videos('/path/to/exported/model', '/path/to/video', resize=0.5, display=True, pcutoff=0.5, display_radius=4, cmap='bmy')
```
##### command line
```
dlc-live-analyze /path/to/exported/model /path/to/video -r 0.5 --display --pcutoff 0.5 --display-radius 4 --cmap bmy
dlc-live-benchmark /path/to/exported/model /path/to/video -r 0.5 --display --pcutoff 0.5 --display-radius 4 --cmap bmy
```

3. Analyze and create a labeled video using the exported model and desired resize parameters. This option functions similar to `deeplabcut.analyze_videos` and `deeplabcut.create_labeled_video` (note, this is slow and only for testing purposes).
3. Analyze and create a labeled video using the exported model and desired resize parameters. This option functions similar to `deeplabcut.benchmark_videos` and `deeplabcut.create_labeled_video` (note, this is slow and only for testing purposes).

##### python
```python
dlclive.benchmark_videos('/path/to/exported/model', '/path/to/video', resize=[1.0, 0.75, 0.5], pcutoff=0.5, display_radius=4, cmap='bmy', save_poses=True, save_video=True)
```
##### command line
```
dlc-live-analyze /path/to/exported/model /path/to/video -r 0.5 --pcutoff 0.5 --display-radius 4 --cmap bmy --save_poses --save_video
dlc-live-benchmark /path/to/exported/model /path/to/video -r 0.5 --pcutoff 0.5 --display-radius 4 --cmap bmy --save-poses --save-video
```

### Citation:
Expand Down
1 change: 1 addition & 0 deletions dlclive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from dlclive.dlclive import DLCLive
from dlclive.processor import Processor
from dlclive.bench import benchmark_model_by_size
from dlclive.benchmark import benchmark, benchmark_videos
28 changes: 15 additions & 13 deletions dlclive/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import time
import sys
import warnings
import argparse
import pickle
import subprocess
Expand Down Expand Up @@ -99,8 +100,7 @@ def get_system_info() -> dict:
'dlclive_version': VERSION
}


def run_benchmark(model_path, video_path, resize=None, pixels=None, n_frames=10000, print_rate=False) -> typing.Tuple[np.ndarray, int, bool]:
def run_benchmark(model_path, video_path, tf_config=None, resize=None, pixels=None, n_frames=10000, print_rate=False, display=False, pcutoff=0.0, display_radius=3) -> typing.Tuple[np.ndarray, int, bool]:
""" Benchmark on inference times for a given DLC model and video

Parameters
Expand Down Expand Up @@ -139,13 +139,13 @@ def run_benchmark(model_path, video_path, resize=None, pixels=None, n_frames=100

### initialize live object

live = DLCLive(model_path, resize=resize)
live = DLCLive(model_path, tf_config=tf_config, resize=resize, display=display, pcutoff=pcutoff, display_radius=display_radius)
live.init_inference(frame)
TFGPUinference = True if len(live.outputs) == 1 else False

### perform inference

iterator = range(n_frames) if print_rate else tqdm(range(n_frames))
iterator = range(n_frames) if (print_rate) or (display) else tqdm(range(n_frames))
inf_times = np.zeros(n_frames)

for i in iterator:
Expand All @@ -155,7 +155,7 @@ def run_benchmark(model_path, video_path, resize=None, pixels=None, n_frames=100
if not ret:
warnings.warn("Did not complete {:d} frames. There probably were not enough frames in the video {}.".format(n_frames, video_path))
break

start_pose = time.time()
live.get_pose(frame)
inf_times[i] = time.time() - start_pose
Expand Down Expand Up @@ -238,7 +238,7 @@ def read_pickle(filename):
with open(filename, "rb") as handle:
return pickle.load(handle)

def benchmark_model_by_size(model_path, video_path, fn_ind, out_dir=None, n_frames=10000, resize=None, pixels=None, print_rate=False):
def benchmark_model_by_size(model_path, video_path, output=None, n_frames=10000, tf_config=None, resize=None, pixels=None, print_rate=False, display=False, pcutoff=0.5, display_radius=3):
"""Benchmark DLC model by image size

Parameters
Expand Down Expand Up @@ -278,17 +278,12 @@ def benchmark_model_by_size(model_path, video_path, fn_ind, out_dir=None, n_fram

### initialize full inference times

#inf_times = np.zeros((len(resize), n_frames))
#pixels_out = np.zeros(len(resize))
print(resize)

# get system info once, shouldn't change between runs
sys_info = get_system_info()

for i in range(len(resize)):

sys_info = get_system_info()
#print("Your system info:", sys_info)
datafilename=get_savebenchmarkfn(sys_info ,i, fn_ind, out_dir=out_dir)

#Check if a subset was already been completed?
Expand All @@ -313,19 +308,26 @@ def main():
parser.add_argument('model_path', type=str)
parser.add_argument('video_path', type=str)
parser.add_argument('-o', '--output', type=str, default=os.getcwd())
parser.add_argument('-n', '--n_frames', type=int, default=10000)
parser.add_argument('-n', '--n-frames', type=int, default=10000)
parser.add_argument('-r', '--resize', type=float, nargs='+')
parser.add_argument('-p', '--pixels', type=float, nargs='+')
parser.add_argument('-v', '--print_rate', default=False, action='store_true')
parser.add_argument('-d', '--display', default=False, action='store_true')
parser.add_argument('-l', '--pcutoff', default=0.5, type=float)
parser.add_argument('-s', '--display-radius', default=3, type=int)
args = parser.parse_args()


benchmark_model_by_size(args.model_path,
args.video_path,
output=args.output,
resize=args.resize,
pixels=args.pixels,
n_frames=args.n_frames,
print_rate=args.print_rate)
print_rate=args.print_rate,
display=args.display,
pcutoff=args.pcutoff,
display_radius=args.display_radius)


if __name__ == "__main__":
Expand Down
Loading