Skip to content
138 changes: 76 additions & 62 deletions deeplabcut/compat.py
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely like this one, we have several inconsistencies throughout between snake/camel case and this makes the API easier imo.

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions deeplabcut/pose_estimation_pytorch/apis/tracking_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from deeplabcut.pose_estimation_pytorch.task import Task
from deeplabcut.pose_tracking_pytorch import create_triplets_dataset
from deeplabcut.utils.auxfun_videos import collect_video_paths
from deeplabcut.utils.deprecation import renamed_parameter


def build_feature_extraction_runner(
Expand Down Expand Up @@ -125,11 +126,12 @@ def extract_features_for_video(
shelf_writer.close()


@renamed_parameter(old="videotype", new="extensions", since="3.0.0")
def create_tracking_dataset(
config: str,
videos: list[str] | list[Path],
track_method: str,
videotype: str | Sequence[str] | None = None,
extensions: str | Sequence[str] | None = None,
shuffle: int = 1,
trainingsetindex: int = 0,
destfolder: str | None = None,
Expand All @@ -149,7 +151,7 @@ def create_tracking_dataset(
the videos with same extension are stored.
track_method: Specifies the tracker used to generate the pose estimation data.
Must be either 'box', 'skeleton', or 'ellipse'.
videotype: Controls how ``videos`` are filtered, based on file extension.
extensions: Controls how ``videos`` are filtered, based on file extension.
File paths and directory contents are treated differently:
- ``None`` (default): file paths are accepted as-is; directories are
scanned for files with a recognized video extension.
Expand Down Expand Up @@ -245,7 +247,7 @@ def create_tracking_dataset(
modelprefix=modelprefix,
)

videos = collect_video_paths(videos, extensions=videotype)
videos = collect_video_paths(videos, extensions=extensions)
for video_path in videos:
print(f"Loading {video_path}")
video = VideoIterator(video_path, cropping=cropping)
Expand Down
6 changes: 4 additions & 2 deletions deeplabcut/pose_estimation_pytorch/apis/tracklets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
)
from deeplabcut.pose_estimation_pytorch.data.dlcloader import DLCLoader
from deeplabcut.utils.auxfun_videos import collect_video_paths
from deeplabcut.utils.deprecation import renamed_parameter


@renamed_parameter(old="videotype", new="extensions", since="3.0.0")
def convert_detections2tracklets(
config: str,
videos: str | list[str],
videotype: str | Sequence[str] | None = None,
extensions: str | Sequence[str] | None = None,
shuffle: int = 1,
trainingsetindex: int = 0,
overwrite: bool = False,
Expand Down Expand Up @@ -126,7 +128,7 @@ def convert_detections2tracklets(
)

paths_input = videos
videos = collect_video_paths(videos, extensions=videotype)
videos = collect_video_paths(videos, extensions=extensions)
if len(videos) == 0:
print(f"No videos were found in {paths_input}")
return
Expand Down
7 changes: 4 additions & 3 deletions deeplabcut/pose_estimation_pytorch/apis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
from deeplabcut.pose_estimation_pytorch.utils import resolve_device
from deeplabcut.utils import auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import SUPPORTED_VIDEOS, collect_video_paths
from deeplabcut.utils.deprecation import deprecated
from deeplabcut.utils.deprecation import deprecated, renamed_parameter


def parse_snapshot_index_for_analysis(
Expand Down Expand Up @@ -295,14 +295,15 @@ def get_scorer_name(


@deprecated(replacement="deeplabcut.collect_video_paths", since="3.0.0")
@renamed_parameter(old="video_type", new="extensions", since="3.0.0")
def list_videos_in_folder(
data_path: str | Path | list[str | Path],
video_type: str | Sequence[str] | None = SUPPORTED_VIDEOS,
extensions: str | Sequence[str] | None = SUPPORTED_VIDEOS,
shuffle: bool = False,
) -> list[Path]:
return collect_video_paths(
data_path=data_path,
extensions=video_type,
extensions=extensions,
shuffle=shuffle,
)

Expand Down
12 changes: 7 additions & 5 deletions deeplabcut/pose_estimation_pytorch/apis/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from deeplabcut.refine_training_dataset.stitch import stitch_tracklets
from deeplabcut.utils import VideoReader, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import collect_video_paths
from deeplabcut.utils.deprecation import renamed_parameter


class VideoIterator(VideoReader):
Expand Down Expand Up @@ -241,10 +242,11 @@ def video_inference(
return predictions


@renamed_parameter(old="videotype", new="extensions", since="3.0.0")
def analyze_videos(
config: str,
videos: str | list[str],
videotype: str | Sequence[str] | None = None,
extensions: str | Sequence[str] | None = None,
shuffle: int = 1,
trainingsetindex: int = 0,
save_as_csv: bool = False,
Expand Down Expand Up @@ -284,7 +286,7 @@ def analyze_videos(
videos: a str (or list of strings) containing the full paths to videos for
analysis or a path to the directory, where all the videos with same
extension are stored.
videotype: Controls how ``videos`` are filtered, based on file extension.
extensions: Controls how ``videos`` are filtered, based on file extension.
File paths and directory contents are treated differently:
- ``None`` (default): file paths are accepted as-is; directories are
scanned for files with a recognized video extension.
Expand Down Expand Up @@ -546,7 +548,7 @@ def analyze_videos(
print(f"Using scorer: {dlc_scorer}")

# Reading video and init variables
videos = collect_video_paths(videos, extensions=videotype, shuffle=in_random_order)
videos = collect_video_paths(videos, extensions=extensions, shuffle=in_random_order)
h5_files_created = False # Track if any .h5 files were created

for video in videos:
Expand Down Expand Up @@ -676,7 +678,7 @@ def analyze_videos(
convert_detections2tracklets(
config=config,
videos=str(video),
videotype=videotype,
extensions=extensions,
shuffle=shuffle,
trainingsetindex=trainingsetindex,
overwrite=False,
Expand All @@ -688,7 +690,7 @@ def analyze_videos(
stitch_tracklets(
config,
[str(video)],
videotype,
extensions,
shuffle,
trainingsetindex,
n_tracks=n_tracks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from deeplabcut.pose_estimation_tensorflow.core import predict_multianimal as predict
from deeplabcut.utils import auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import VideoWriter, collect_video_paths
from deeplabcut.utils.deprecation import renamed_parameter

warnings.simplefilter("ignore", category=RuntimeWarning)

Expand Down Expand Up @@ -243,12 +244,13 @@ def _video_inference(
return PredicteData, nframes


@renamed_parameter(old="videotype", new="extensions", since="3.0.0")
def video_inference(
videos,
project_name,
model_name,
scale_list=None,
videotype: str | Sequence[str] | None = None,
extensions: str | Sequence[str] | None = None,
destfolder=None,
batchsize=1,
robust_nframes=False,
Expand Down Expand Up @@ -307,7 +309,7 @@ def video_inference(

sess, inputs, outputs = single_predict.setup_pose_prediction(test_cfg, allow_growth=allow_growth)
DLCscorer = "DLC_" + Path(test_cfg["init_weights"]).stem
videos = collect_video_paths(videos, extensions=videotype)
videos = collect_video_paths(videos, extensions=extensions)

datafiles = []
for video in videos:
Expand Down
34 changes: 19 additions & 15 deletions deeplabcut/pose_estimation_tensorflow/predict_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@
from deeplabcut.refine_training_dataset.stitch import stitch_tracklets
from deeplabcut.utils import auxfun_models, auxfun_multianimal, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import collect_video_paths
from deeplabcut.utils.deprecation import renamed_parameter

####################################################
# Loading data, and defining model folder
####################################################


@renamed_parameter(old="videotype", new="extensions", since="3.0.0")
def create_tracking_dataset(
config,
videos,
track_method,
videotype: str | Sequence[str] | None = None,
extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
gputouse=None,
Expand Down Expand Up @@ -200,7 +202,7 @@ def create_tracking_dataset(
##################################################
# Looping over videos
##################################################
Videos = collect_video_paths(videos, extensions=videotype)
Videos = collect_video_paths(videos, extensions=extensions)
if len(Videos) > 0:
if "multi-animal" in dlc_cfg["dataset_type"]:
for video in Videos:
Expand Down Expand Up @@ -249,14 +251,15 @@ def create_tracking_dataset(
)
return DLCscorer # note: this is either DLCscorer or DLCscorerlegacy depending on what was used!
else:
print("No video(s) were found. Please check your paths and/or 'videotype'.")
print("No video(s) were found. Please check your paths and/or extensions filter.")
return DLCscorer


@renamed_parameter(old="videotype", new="extensions", since="3.0.0")
def analyze_videos(
config,
videos,
videotype: str | Sequence[str] | None = None,
extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
gputouse=None,
Expand Down Expand Up @@ -300,7 +303,7 @@ def analyze_videos(
A list of strings containing the full paths to videos for analysis or a path to
the directory, where all the videos with same extension are stored.

videotype : str | Sequence[str] | None, optional, default=None
extensions : str | Sequence[str] | None, optional, default=None
Controls how ``videos`` are filtered, based on file extension.
File paths and directory contents are treated differently:
- ``None`` (default): file paths are accepted as-is; directories are
Expand Down Expand Up @@ -445,7 +448,7 @@ def analyze_videos(
>>> deeplabcut.analyze_videos(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/videos'],
videotype='.avi',
extensions='.avi',
)

Analyze multiple videos
Expand Down Expand Up @@ -600,7 +603,7 @@ def analyze_videos(
##################################################
# Looping over videos
##################################################
Videos = collect_video_paths(videos, extensions=videotype, shuffle=in_random_order)
Videos = collect_video_paths(videos, extensions=extensions, shuffle=in_random_order)
if len(Videos) > 0:
if "multi-animal" in dlc_cfg["dataset_type"]:
from deeplabcut.pose_estimation_tensorflow.predict_multianimal import (
Expand All @@ -625,7 +628,7 @@ def analyze_videos(
convert_detections2tracklets(
config,
[video],
videotype,
extensions,
shuffle,
trainingsetindex,
destfolder=destfolder,
Expand All @@ -636,7 +639,7 @@ def analyze_videos(
stitch_tracklets(
config,
[video],
videotype,
extensions,
shuffle,
trainingsetindex,
destfolder=destfolder,
Expand Down Expand Up @@ -686,7 +689,7 @@ def analyze_videos(
)
return DLCscorer # note: this is either DLCscorer or DLCscorerlegacy depending on what was used!
else:
print("No video(s) were found. Please check your paths and/or 'videotype'.")
print("No video(s) were found. Please check your paths and/or extensions filter.")
return DLCscorer


Expand Down Expand Up @@ -1481,10 +1484,11 @@ def _convert_detections_to_tracklets(
pickle.dump(tracklets, f, pickle.HIGHEST_PROTOCOL)


@renamed_parameter(old="videotype", new="extensions", since="3.0.0")
def convert_detections2tracklets(
config,
videos,
videotype: str | Sequence[str] | None = None,
extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
overwrite=False,
Expand All @@ -1510,7 +1514,7 @@ def convert_detections2tracklets(
A list of strings containing the full paths to videos for analysis
or a path to the directory, where all the videos with same extension are stored.

videotype : str | Sequence[str] | None, optional, default=None
extensions : str | Sequence[str] | None, optional, default=None
Controls how ``videos`` are filtered, based on file extension.
File paths and directory contents are treated differently:
- ``None`` (default): file paths are accepted as-is; directories are
Expand Down Expand Up @@ -1570,14 +1574,14 @@ def convert_detections2tracklets(
>>> deeplabcut.convert_detections2tracklets(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/video1.mp4'],
videotype='.mp4'
extensions='.mp4'
)

If you want to convert detections to tracklets based on box_tracker:
>>> deeplabcut.convert_detections2tracklets(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/video1.mp4'],
videotype='.mp4',
extensions='.mp4',
track_method='box'
)

Expand Down Expand Up @@ -1661,7 +1665,7 @@ def convert_detections2tracklets(
##################################################
# Looping over videos
##################################################
Videos = collect_video_paths(videos, extensions=videotype)
Videos = collect_video_paths(videos, extensions=extensions)
if len(Videos) > 0:
for video in Videos:
print("Processing... ", video)
Expand Down
13 changes: 8 additions & 5 deletions deeplabcut/pose_tracking_pytorch/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

from collections.abc import Sequence

from deeplabcut.utils.deprecation import renamed_parameter


@renamed_parameter(old="videotype", new="extensions", since="3.0.0")
def transformer_reID(
config: str,
videos: list[str],
videotype: str | Sequence[str] | None = None,
extensions: str | Sequence[str] | None = None,
shuffle: int = 1,
trainingsetindex: int = 0,
track_method: str = "ellipse",
Expand Down Expand Up @@ -46,7 +49,7 @@ def transformer_reID(
A list of strings containing the full paths to videos for analysis or a path to
the directory, where all the videos with same extension are stored.

videotype : str | Sequence[str] | None, optional, default=None
extensions : str | Sequence[str] | None, optional, default=None
Controls how ``videos`` are filtered, based on file extension.
File paths and directory contents are treated differently:
- ``None`` (default): file paths are accepted as-is; directories are
Expand Down Expand Up @@ -112,7 +115,7 @@ def transformer_reID(
config,
videos,
track_method,
videotype=videotype,
extensions=extensions,
shuffle=shuffle,
trainingsetindex=trainingsetindex,
modelprefix=modelprefix,
Expand All @@ -135,7 +138,7 @@ def transformer_reID(
config,
DLCscorer,
videos,
videotype=videotype,
extensions=extensions,
train_frac=train_frac,
modelprefix=modelprefix,
train_epochs=train_epochs,
Expand All @@ -151,7 +154,7 @@ def transformer_reID(
deeplabcut.stitch_tracklets(
config,
videos,
videotype=videotype,
extensions=extensions,
shuffle=shuffle,
trainingsetindex=trainingsetindex,
track_method=track_method,
Expand Down
Loading
Loading