Skip to content

Commit

Permalink
fix #111: coerce floats and ints for pixels, replace string with floa…
Browse files Browse the repository at this point in the history
…t in readme
  • Loading branch information
sneakers-the-rat committed Feb 14, 2024
1 parent 9bb640f commit 08ebec2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ DeepLabCut-live offers some analysis tools that allow users to peform the follow
1. Test inference speed across a range of image sizes, downsizing images by specifying the `resize` or `pixels` parameter. Using the `pixels` parameter will resize images to the desired number of `pixels`, without changing the aspect ratio. Results will be saved (along with system info) to a pickle file if you specify an output directory.
##### python
```python
dlclive.benchmark_videos('/path/to/exported/model', ['/path/to/video1', '/path/to/video2'], output='/path/to/output', resize=[1.0, 0.75, '0.5'])
dlclive.benchmark_videos('/path/to/exported/model', ['/path/to/video1', '/path/to/video2'], output='/path/to/output', resize=[1.0, 0.75, 0.5])
```
##### command line
```
Expand Down
18 changes: 9 additions & 9 deletions dlclive/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys
import warnings
import subprocess
import typing
from typing import List, Optional, Tuple, Union
import pickle
import colorcet as cc
from PIL import ImageColor
Expand Down Expand Up @@ -151,8 +151,8 @@ def benchmark(
model_path,
video_path,
tf_config=None,
resize=None,
pixels=None,
resize: Optional[float] = None,
pixels: Optional[int] = None,
cropping=None,
dynamic=(False, 0.5, 10),
n_frames=1000,
Expand All @@ -164,7 +164,7 @@ def benchmark(
save_poses=False,
save_video=False,
output=None,
) -> typing.Tuple[np.ndarray, tuple, bool, dict]:
) -> Tuple[np.ndarray, tuple, bool, dict]:
""" Analyze DeepLabCut-live exported model on a video:
Calculate inference time,
display keypoints, or
Expand Down Expand Up @@ -521,8 +521,8 @@ def benchmark_videos(
output=None,
n_frames=1000,
tf_config=None,
resize=None,
pixels=None,
resize: Optional[Union[float, List[float]]] = None,
pixels: Optional[Union[int, List[int]]] = None,
cropping=None,
dynamic=(False, 0.5, 10),
print_rate=False,
Expand Down Expand Up @@ -551,7 +551,7 @@ def benchmark_videos(
path to directory to save results
tf_config : :class:`tensorflow.ConfigProto`
tensorflow session configuration
resize : int, optional
resize : float, optional
resize factor. Can only use one of resize or pixels. If both are provided, will use pixels. by default None
pixels : int, optional
downsize image to this number of pixels, maintaining aspect ratio. Can only use one of resize or pixels. If both are provided, will use pixels. by default None
Expand Down Expand Up @@ -603,10 +603,10 @@ def benchmark_videos(
# fix resize

if pixels:
pixels = pixels if type(pixels) is list else [pixels]
pixels = [int(p) for p in pixels] if type(pixels) is list else [int(pixels)]
resize = [None for p in pixels]
elif resize:
resize = resize if type(resize) is list else [resize]
resize = [float(r) for r in resize] if type(resize) is list else [float(resize)]
pixels = [None for r in resize]
else:
resize = [None]
Expand Down

0 comments on commit 08ebec2

Please sign in to comment.