Skip to content

Commit 4910439

Browse files
MMathisLabgkane26
andauthored
Gk dev (#1)
* dlclive: add tf_config as parameter * graph: add tfconfig, new full load graph function * bench + display: add display to benchmarking, fix bugs in display * fix bugs in display * add kwargs to processors * clean up load graph, color conversions * dlclive: add kwargs to get_pose and init_inference * add kalman filter processor * kalmanfilter processor: update delta time * dlclive: destroy display on close * new analyze tools: speed bench, display, analyze pose and labeled video * dlclive and graph: clean up/benign bug fix * fix colormaps for display * update readme: add benchmark info * setup: add pandas and tables, needed for analyze_videos * Update kalmanfilter.py * change display_lik to pcutoff * resolve setup and readme conflicts * Update README.md * fixed resize in python, check cmd * Update README.md * analyze: allow pixels/resize to be scalar or list * fix TF warnings * changed name to benchmark_videos * Update README.md * dlclive: tfgpu flip x and y * name update * complete convert analyze to benchmarking Co-authored-by: gkane <[email protected]>
1 parent 35e4f23 commit 4910439

File tree

13 files changed

+794
-87
lines changed

13 files changed

+794
-87
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,29 @@ dlclive.benchmark_videos('/path/to/exported/model', ['/path/to/video1', '/path/t
7373
```
7474
##### command line
7575
```
76-
dlc-live-analyze /path/to/exported/model /path/to/video1 /path/to/video2 -o /path/to/output -r 1.0 0.75 0.5
76+
dlc-live-benchmark /path/to/exported/model /path/to/video1 /path/to/video2 -o /path/to/output -r 1.0 0.75 0.5
7777
```
7878

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

8181
##### python
8282
```python
83-
dlclive.benchmark_videos('/path/to/exported/model', '/path/to/video', resize=[0.5], display=True, pcutoff=0.5, display_radius=4, cmap='bmy')
83+
dlclive.benchmark_videos('/path/to/exported/model', '/path/to/video', resize=0.5, display=True, pcutoff=0.5, display_radius=4, cmap='bmy')
8484
```
8585
##### command line
8686
```
87-
dlc-live-analyze /path/to/exported/model /path/to/video -r 0.5 --display --pcutoff 0.5 --display-radius 4 --cmap bmy
87+
dlc-live-benchmark /path/to/exported/model /path/to/video -r 0.5 --display --pcutoff 0.5 --display-radius 4 --cmap bmy
8888
```
8989

90-
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).
90+
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).
9191

9292
##### python
9393
```python
9494
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)
9595
```
9696
##### command line
9797
```
98-
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
98+
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
9999
```
100100

101101
### Citation:

dlclive/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
from dlclive.dlclive import DLCLive
1010
from dlclive.processor import Processor
1111
from dlclive.bench import benchmark_model_by_size
12+
from dlclive.benchmark import benchmark, benchmark_videos

dlclive/bench.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import time
1212
import sys
13+
import warnings
1314
import argparse
1415
import pickle
1516
import subprocess
@@ -99,8 +100,7 @@ def get_system_info() -> dict:
99100
'dlclive_version': VERSION
100101
}
101102

102-
103-
def run_benchmark(model_path, video_path, resize=None, pixels=None, n_frames=10000, print_rate=False) -> typing.Tuple[np.ndarray, int, bool]:
103+
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]:
104104
""" Benchmark on inference times for a given DLC model and video
105105
106106
Parameters
@@ -139,13 +139,13 @@ def run_benchmark(model_path, video_path, resize=None, pixels=None, n_frames=100
139139

140140
### initialize live object
141141

142-
live = DLCLive(model_path, resize=resize)
142+
live = DLCLive(model_path, tf_config=tf_config, resize=resize, display=display, pcutoff=pcutoff, display_radius=display_radius)
143143
live.init_inference(frame)
144144
TFGPUinference = True if len(live.outputs) == 1 else False
145145

146146
### perform inference
147147

148-
iterator = range(n_frames) if print_rate else tqdm(range(n_frames))
148+
iterator = range(n_frames) if (print_rate) or (display) else tqdm(range(n_frames))
149149
inf_times = np.zeros(n_frames)
150150

151151
for i in iterator:
@@ -155,7 +155,7 @@ def run_benchmark(model_path, video_path, resize=None, pixels=None, n_frames=100
155155
if not ret:
156156
warnings.warn("Did not complete {:d} frames. There probably were not enough frames in the video {}.".format(n_frames, video_path))
157157
break
158-
158+
159159
start_pose = time.time()
160160
live.get_pose(frame)
161161
inf_times[i] = time.time() - start_pose
@@ -238,7 +238,7 @@ def read_pickle(filename):
238238
with open(filename, "rb") as handle:
239239
return pickle.load(handle)
240240

241-
def benchmark_model_by_size(model_path, video_path, fn_ind, out_dir=None, n_frames=10000, resize=None, pixels=None, print_rate=False):
241+
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):
242242
"""Benchmark DLC model by image size
243243
244244
Parameters
@@ -278,17 +278,12 @@ def benchmark_model_by_size(model_path, video_path, fn_ind, out_dir=None, n_fram
278278

279279
### initialize full inference times
280280

281-
#inf_times = np.zeros((len(resize), n_frames))
282-
#pixels_out = np.zeros(len(resize))
283-
print(resize)
284-
285281
# get system info once, shouldn't change between runs
286282
sys_info = get_system_info()
287283

288284
for i in range(len(resize)):
289285

290286
sys_info = get_system_info()
291-
#print("Your system info:", sys_info)
292287
datafilename=get_savebenchmarkfn(sys_info ,i, fn_ind, out_dir=out_dir)
293288

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

320+
322321
benchmark_model_by_size(args.model_path,
323322
args.video_path,
324323
output=args.output,
325324
resize=args.resize,
326325
pixels=args.pixels,
327326
n_frames=args.n_frames,
328-
print_rate=args.print_rate)
327+
print_rate=args.print_rate,
328+
display=args.display,
329+
pcutoff=args.pcutoff,
330+
display_radius=args.display_radius)
329331

330332

331333
if __name__ == "__main__":

0 commit comments

Comments
 (0)