deeplabcut.utils
Modules:
| Name | Description |
|---|---|
auxfun_models |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
auxfun_multianimal |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
auxfun_videos |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
auxiliaryfunctions |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
auxiliaryfunctions_3d |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
conversioncode |
|
core_config |
|
crossvalutils |
|
frameselectiontools |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
make_labeled_video |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
multiprocessing |
DeepLabCut2.2 Toolbox (deeplabcut.org) |
pandas_future_mode |
Opt-in pandas 2.3 future-behavior checks for CI/local DLC test runs. |
plotting |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
pseudo_label |
|
skeleton |
DeepLabCut2.2 Toolbox (deeplabcut.org) |
video_processor |
Author: Hao Wu |
visualization |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
Classes:
| Name | Description |
|---|---|
DLCDeprecationWarning |
Project-specific deprecation warning. Helps with filtering. |
PoseConfig |
Main configuration class for DeepLabCut pose estimation models. |
VideoProcessor |
Abstract base class for video reading and writing. |
VideoProcessorCV |
OpenCV-backed video reader and writer. |
VideoWriter |
|
vp |
OpenCV-backed video reader and writer. |
Functions:
| Name | Description |
|---|---|
CreateVideo |
Creating individual frames with labeled body parts and making a video. |
CreateVideoSlow |
Creating individual frames with labeled body parts and making a video. |
CropVideo |
Auxiliary function to crop a video and output it to the same folder with |
DownSampleVideo |
Auxiliary function to downsample a video and output it to the same folder with |
IntersectionofIndividualsandOnesGivenbyUser |
Returns all individuals when set to 'all', otherwise all bpts that are in the |
KmeansbasedFrameselection |
This code downsamples the video to a width of resizewidth. |
KmeansbasedFrameselectioncv2 |
This code downsamples the video to a width of resizewidth. The video is extracted |
LoadFullMultiAnimalData |
Load predicted data and metadata from pickle files created by predict_videos.py. |
PlottingResults |
Plots poses vs time; pose x vs pose y; histogram of differences and |
SaveFullMultiAnimalData |
Save predicted data as h5 file and metadata as pickle file; created by |
ShortenVideo |
Auxiliary function to shorten video and output with outsuffix appended to the |
UniformFrames |
Temporally uniformly sampling frames in interval (start,stop). Visual information |
UniformFramescv2 |
Temporally uniformly sampling frames in interval (start,stop). Visual information |
adapt_labeled_data_to_new_project |
Given the config.yaml file, this function will convert the labels of an ancient |
analyze_videos_converth5_to_csv |
By default the output poses (when running analyze_videos) are stored as |
analyze_videos_converth5_to_nwb |
Convert all h5 output data files in |
attempt_to_make_folder |
Attempts to create a folder with specified name. |
check_if_post_processing |
Checks if filtered/bone lengths were already calculated. |
collect_video_paths |
Collects video paths from a given set of data paths: directories, files, or a mix |
convert2_maDLC |
Convert a single-animal annotation file into a multianimal annotation file. |
convert_single2multiplelegacyAM |
Convert multi animal to single animal code and vice versa. |
convertcsv2h5 |
Convert annotation files in labeled-data from csv to h5. |
create_labeled_video |
Labels the bodyparts in a video. |
create_video_with_all_detections |
Create a video labeled with all the detections stored in a '*_full.pickle' file. |
deprecated |
Mark a function as deprecated. |
filter_files_by_patterns |
Filters files in a folder based on start, contain, and end patterns. |
filter_unwanted_paf_connections |
Get rid of skeleton connections between multi and unique body parts. |
find_analyzed_data |
Find potential data files from the hints given to the function. |
find_video_metadata |
For backward compatibility, let us search the substring 'meta'. |
get_bodyparts |
Get the bodyparts. |
get_data_and_metadata_filenames |
Paths to data and metadata files relative to the project root. |
get_deeplabcut_path |
Get path of where deeplabcut is currently running. |
get_evaluation_folder |
Get the evaluation folder. |
get_model_folder |
Get the model folder. |
get_scorer_name |
Extract the scorer/network name for a particular shuffle, training fraction, etc. |
get_snapshots_from_folder |
Returns an ordered list of existing snapshot names in the train folder, sorted by |
get_training_set_folder |
Training Set folder for config file based on parameters. |
get_unique_bodyparts |
Get the unique bodyparts. |
get_video_list |
Get list of videos in a path (if filetype == all), otherwise just a specific |
getpafgraph |
Auxiliary function that turns skeleton (list of connected bodypart pairs) into a |
grab_files_in_folder |
Return the paths of files with extension ext present in folder. |
imread |
Read image either with skimage or cv2. |
intersection_of_body_parts_and_ones_given_by_user |
Returns all body parts when comparisonbodyparts=='all', otherwise all bpts that |
merge_windowsannotationdataONlinuxsystem |
If a project was created on Windows (and labeled there,) but ran on unix then the |
plot_edge_affinity_distributions |
Display the distribution of affinity costs of within- and between-animal edges. |
plot_trajectories |
Plots the trajectories of various bodyparts across the video. |
proc_video |
Helper function for create_labeled_video. |
read_inferencecfg |
Load inferencecfg or initialize it. |
read_pickle |
Read the pickle file. |
read_plainconfig |
Load a YAML config (alias for read_config_as_dict). See deeplabcut.core.config. |
renamed_parameter |
Support a renamed keyword argument while warning callers to update. |
reorder_individuals_in_df |
Reorders data of df to match the order given in a list. |
returnlabelingdata |
Returns a specific labeleing data set -- the user will be asked which one. |
rotate_video |
Auxiliary function to rotate a video and output it to the same folder with |
safe_resolve |
Return a resolved Path that is safe to use with str-based I/O. |
save_data |
Save predicted data as h5 file and metadata as pickle file; created by |
write_pickle |
Write the pickle file. |
write_plainconfig |
Write a config dict to YAML (alias for write_config). See deeplabcut.core.config. |
DLCDeprecationWarning
Bases: DeprecationWarning
Project-specific deprecation warning. Helps with filtering.
PoseConfig
Bases: DLCVersionedConfig
Main configuration class for DeepLabCut pose estimation models.
This is the top-level configuration that brings together all the different configuration domains (project, model, data, training, etc.).
Attributes:
| Name | Type | Description |
|---|---|---|
net_type |
NetType
|
Network architecture type (e.g., resnet_50, hrnet_w32, dlcrnet_stride16_ms5) |
method |
MethodType
|
Method type (bu=Bottom-Up, td=Top-Down, ctd=Conditional Top-Down) |
device |
str
|
Device configuration (auto, cpu, cuda) |
project |
str
|
Project configuration (skeleton, individuals, etc.) |
model |
ModelConfig
|
Model configuration (backbone, heads, etc.) |
detector |
DetectorConfig | None
|
Detector configuration (for top-down models) |
data |
DataConfig
|
Data configuration (loaders, transforms, etc.) |
training |
DataConfig
|
Training configuration (runner, optimizer, etc.) |
inference |
InferenceConfig
|
Inference configuration (multithreading, compilation, etc.) |
logger |
CSVLoggerConfig | WandbLoggerConfig | None
|
Logger configuration (e.g., WandB or CSV logger) |
with_center_keypoints |
bool
|
Whether to include center keypoints (for DEKR models) |
Methods:
| Name | Description |
|---|---|
build |
Build a typed PoseConfig for a project |
Source code in deeplabcut/pose_estimation_pytorch/config/pose.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
build
classmethod
build(
project_config: ProjectConfig | dict | Path | str,
pose_config_path: str | Path,
*,
top_down: bool,
multi_animal: bool | None = None,
net_type: NetType | str | None = None,
detector_type: DetectorType | str | None = None,
weight_init: WeightInitialization | dict | Path | str | None = None,
ctd_conditions: int | str | Path | tuple[int, str] | tuple[int, int] | None = None,
save: bool = False
) -> Self
Build a typed PoseConfig for a project
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ProjectConfig | dict | Path | str
|
The project configuration. |
required |
|
str | Path
|
The path to the pose configuration. |
required |
|
bool
|
Whether to use a top-down backbone. |
required |
|
NetType | str | None
|
The network architecture type (without 'top_down_' prefix). If None, the default net type from the project config will be used. |
None
|
|
DetectorType | str | None
|
The detector architecture. Required for td models. |
None
|
|
WeightInitialization | None
|
The weight initialization object or path. |
None
|
|
int | str | Path | tuple[int, str] | tuple[int, int] | None
|
The conditional top-down conditions. Only required for CTD models. A predictions file path is evaluation-only; shuffle refs work for both evaluation and live analyze. |
None
|
|
bool
|
Whether to save the pose configuration. |
False
|
Note
For generic backbone models, method is resolved from top_down. For non-backbone models,
the top_down is ignored and method is resolved from the default config.
Source code in deeplabcut/pose_estimation_pytorch/config/pose.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
VideoProcessor
Bases: ABC
Abstract base class for video reading and writing.
Subclasses implement backend-specific video loading, metadata extraction, output video creation, frame reading, frame writing, and cleanup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path to the input video. If empty, no input video is opened. |
''
|
|
str
|
Path to the output video. If empty, no output video is created. |
''
|
|
int
|
Number of frames to process. |
-1
|
|
float | None
|
Optional FPS override. |
None
|
|
str
|
FourCC codec string used for output videos. |
'X264'
|
|
int | Literal[''] | None
|
Output video height. |
''
|
|
int | Literal[''] | None
|
Output video width. |
''
|
Attributes:
| Name | Type | Description |
|---|---|---|
fname |
str
|
Input video path. |
sname |
str
|
Output video path. |
nframes |
int
|
Number of frames to process. |
video_fps |
float | None
|
Video frame rate. |
FPS |
float | None
|
Legacy alias for |
h |
int
|
Input video height. |
w |
int
|
Input video width. |
nc |
int
|
Number of channels. |
i |
int
|
Number of successfully loaded frames. |
vid |
Backend-specific input video object. |
|
svid |
Backend-specific output video object. |
|
sh |
int
|
Output video height. |
sw |
int
|
Output video width. |
Notes
height(), width(), fps(), counter(), and
frame_count() are retained as methods for backwards compatibility.
Methods:
| Name | Description |
|---|---|
close |
Implement your own. |
create_video |
Implement your own. |
get_info |
Implement your own. |
save_frame |
Implement your own. |
Source code in deeplabcut/utils/video_processor.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
close
abstractmethod
create_video
abstractmethod
get_info
abstractmethod
VideoProcessorCV
Bases: VideoProcessor
OpenCV-backed video reader and writer.
This implementation uses cv2.VideoCapture for reading videos and
cv2.VideoWriter for writing videos. Frames returned by
load_frame are converted from OpenCV's native BGR channel order to
RGB channel order. Frames passed to save_frame are expected to be in
RGB order and are converted back to BGR before writing.
Attributes:
| Name | Type | Description |
|---|---|---|
fname |
str
|
Path to the input video. If empty, no input video is opened. |
sname |
str
|
Path to the output video. If empty, no output video is created. |
nframes |
int
|
Number of frames to process. If initialized as |
codec |
str
|
FourCC codec string used when creating the output video. |
h |
int
|
Input video height in pixels. |
w |
int
|
Input video width in pixels. |
nc |
int
|
Number of channels. This implementation uses |
i |
int
|
Number of frames successfully loaded through |
FPS |
float
|
Frames per second reported by OpenCV, or the user-provided override. |
sh |
int
|
Output video height in pixels. |
sw |
int
|
Output video width in pixels. |
vid |
VideoCapture | None
|
OpenCV video reader. |
svid |
VideoWriter | None
|
OpenCV video writer. |
Methods:
| Name | Description |
|---|---|
close |
Release OpenCV reader and writer resources. |
create_video |
Create an OpenCV video writer. |
get_info |
Populate metadata from the OpenCV video reader. |
get_video |
Open the input video with OpenCV. |
save_frame |
Write one RGB frame to the output video. |
Source code in deeplabcut/utils/video_processor.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
close
Release OpenCV reader and writer resources.
This method is safe to call multiple times. After release, self.svid
and self.vid are set to None to avoid accidental reuse of closed
OpenCV handles.
Source code in deeplabcut/utils/video_processor.py
create_video
Create an OpenCV video writer.
Returns:
| Type | Description |
|---|---|
|
cv2.VideoWriter: OpenCV video writer for |
Notes
self.sw and self.sh are expected to be set by the base class
before this method is called. The codec is interpreted as a FourCC
string, preserving the historical OpenCV behavior.
Source code in deeplabcut/utils/video_processor.py
get_info
Populate metadata from the OpenCV video reader.
Sets
self.w: Frame width in pixels.
self.h: Frame height in pixels.
self.nframes: Number of frames to process.
self.FPS: Frames per second reported by OpenCV.
self.nc: Number of channels, always 3.
Notes
If self.nframes is -1 or greater than the total number of
frames reported by OpenCV, it is replaced by OpenCV's frame count.
Source code in deeplabcut/utils/video_processor.py
get_video
Open the input video with OpenCV.
Returns:
| Type | Description |
|---|---|
|
cv2.VideoCapture: OpenCV video capture object for |
save_frame
Write one RGB frame to the output video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray | None
|
RGB frame to write. |
required |
Notes
This method preserves the historical behavior of silently ignoring
None frames. Non-None frames are converted from RGB to BGR
before being passed to OpenCV.
Source code in deeplabcut/utils/video_processor.py
VideoWriter
Bases: VideoReader
Methods:
| Name | Description |
|---|---|
shorten |
Shorten the video from start to end. |
split |
Split a video into several shorter ones of equal duration. |
Source code in deeplabcut/utils/auxfun_videos.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
shorten
Shorten the video from start to end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall start. |
required |
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall end. |
required |
|
str
|
String added to the name of the shortened video. Defaults to 'short'. |
'short'
|
|
str
|
Folder the video is saved into. By default, same as the original video. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Full path to the shortened video. |
Source code in deeplabcut/utils/auxfun_videos.py
split
Split a video into several shorter ones of equal duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Number of shorter videos to produce. |
required |
|
str
|
String added to the name of the splits. Defaults to 'split'. |
'split'
|
|
str
|
Folder the video splits are saved into. By default, same as the original video. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
Paths of the video splits. |
Source code in deeplabcut/utils/auxfun_videos.py
vp
Bases: VideoProcessor
OpenCV-backed video reader and writer.
This implementation uses cv2.VideoCapture for reading videos and
cv2.VideoWriter for writing videos. Frames returned by
load_frame are converted from OpenCV's native BGR channel order to
RGB channel order. Frames passed to save_frame are expected to be in
RGB order and are converted back to BGR before writing.
Attributes:
| Name | Type | Description |
|---|---|---|
fname |
str
|
Path to the input video. If empty, no input video is opened. |
sname |
str
|
Path to the output video. If empty, no output video is created. |
nframes |
int
|
Number of frames to process. If initialized as |
codec |
str
|
FourCC codec string used when creating the output video. |
h |
int
|
Input video height in pixels. |
w |
int
|
Input video width in pixels. |
nc |
int
|
Number of channels. This implementation uses |
i |
int
|
Number of frames successfully loaded through |
FPS |
float
|
Frames per second reported by OpenCV, or the user-provided override. |
sh |
int
|
Output video height in pixels. |
sw |
int
|
Output video width in pixels. |
vid |
VideoCapture | None
|
OpenCV video reader. |
svid |
VideoWriter | None
|
OpenCV video writer. |
Methods:
| Name | Description |
|---|---|
close |
Release OpenCV reader and writer resources. |
create_video |
Create an OpenCV video writer. |
get_info |
Populate metadata from the OpenCV video reader. |
get_video |
Open the input video with OpenCV. |
save_frame |
Write one RGB frame to the output video. |
Source code in deeplabcut/utils/video_processor.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
close
Release OpenCV reader and writer resources.
This method is safe to call multiple times. After release, self.svid
and self.vid are set to None to avoid accidental reuse of closed
OpenCV handles.
Source code in deeplabcut/utils/video_processor.py
create_video
Create an OpenCV video writer.
Returns:
| Type | Description |
|---|---|
|
cv2.VideoWriter: OpenCV video writer for |
Notes
self.sw and self.sh are expected to be set by the base class
before this method is called. The codec is interpreted as a FourCC
string, preserving the historical OpenCV behavior.
Source code in deeplabcut/utils/video_processor.py
get_info
Populate metadata from the OpenCV video reader.
Sets
self.w: Frame width in pixels.
self.h: Frame height in pixels.
self.nframes: Number of frames to process.
self.FPS: Frames per second reported by OpenCV.
self.nc: Number of channels, always 3.
Notes
If self.nframes is -1 or greater than the total number of
frames reported by OpenCV, it is replaced by OpenCV's frame count.
Source code in deeplabcut/utils/video_processor.py
get_video
Open the input video with OpenCV.
Returns:
| Type | Description |
|---|---|
|
cv2.VideoCapture: OpenCV video capture object for |
save_frame
Write one RGB frame to the output video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray | None
|
RGB frame to write. |
required |
Notes
This method preserves the historical behavior of silently ignoring
None frames. Non-None frames are converted from RGB to BGR
before being passed to OpenCV.
Source code in deeplabcut/utils/video_processor.py
CreateVideo
CreateVideo(
clip,
Dataframe,
pcutoff,
dotsize,
colormap,
bodyparts2plot,
trailpoints,
cropping,
x1,
x2,
y1,
y2,
bodyparts2connect,
skeleton_color,
draw_skeleton,
displaycropped,
color_by,
confidence_to_alpha=None,
plot_bboxes=True,
bboxes_list=None,
bboxes_pcutoff=0.6,
bboxes_color: tuple | None = None,
)
Creating individual frames with labeled body parts and making a video.
Source code in deeplabcut/utils/make_labeled_video.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
CreateVideoSlow
CreateVideoSlow(
videooutname,
clip,
Dataframe,
tmpfolder,
dotsize,
colormap,
alphavalue,
pcutoff,
trailpoints,
cropping,
x1,
x2,
y1,
y2,
save_frames,
bodyparts2plot,
outputframerate,
Frames2plot,
bodyparts2connect,
skeleton_color,
draw_skeleton,
displaycropped,
color_by,
plot_bboxes=True,
bboxes_list=None,
bboxes_pcutoff=0.6,
bboxes_color: str | None = None,
)
Creating individual frames with labeled body parts and making a video.
Source code in deeplabcut/utils/make_labeled_video.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
CropVideo
CropVideo(vname, width=256, height=256, origin_x=0, origin_y=0, outsuffix='cropped', outpath=None, useGUI=False)
Auxiliary function to crop a video and output it to the same folder with "outsuffix" appended in its name. Width and height will control the new dimensions.
ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
A string containing the full path of the video. |
required |
|
int
|
Width of output video. |
256
|
|
int
|
Height of output video. |
256
|
|
int
|
X-axis origin of bounding box for cropping. |
0
|
|
int
|
Y-axis origin of bounding box for cropping. |
0
|
|
str
|
Suffix for output videoname (see example). |
'cropped'
|
|
str
|
Output path for saving video to (by default, same folder as the video). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The full path to the cropped video. |
Examples:
Linux/MacOs:
deeplabcut.CropVideo("/data/videos/mouse1.avi")
Crops the video using default values and saves it in /data/videos as mouse1cropped.avi
Windows:
deeplabcut.CropVideo(
"C:\yourusername\rig-95\Videos\reachingvideo1.avi",
width=220,
height=320,
outsuffix="cropped",
)
Crops the video to a width of 220 and height of 320 starting at the origin (top left) and saves it in C:\yourusername\rig-95\Videos as reachingvideo1cropped.avi
Source code in deeplabcut/utils/auxfun_videos.py
DownSampleVideo
DownSampleVideo(vname, width=-1, height=200, outsuffix='downsampled', outpath=None, rotatecw='No', angle=0.0)
Auxiliary function to downsample a video and output it to the same folder with "outsuffix" appended in its name. Width and height will control the new dimensions. You can also pass only height or width and set the other one to -1, this will keep the aspect ratio identical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
A string containing the full path of the video. |
required |
|
int
|
Width of output video. |
-1
|
|
int
|
Height of output video. |
200
|
|
str
|
Suffix for output videoname (see example). |
'downsampled'
|
|
str
|
Output path for saving video to (by default, same folder as the video). |
None
|
|
str
|
Default "No", rotates clockwise if "Yes", "Arbitrary" for arbitrary rotation by specified angle. |
'No'
|
|
float
|
Angle to rotate by in degrees, default 0.0. Negative values rotate counter-clockwise. |
0.0
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The full path to the downsampled video. |
Examples:
Linux/MacOs:
deeplabcut.DownSampleVideo("/data/videos/mouse1.avi")
Downsamples the video using default values and saves it in /data/videos as mouse1downsampled.avi
Windows:
shortenedvideoname = deeplabcut.DownSampleVideo(
"C:\yourusername\rig-95\Videos\reachingvideo1.avi",
width=220,
height=320,
outsuffix="cropped",
)
Downsamples the video to a width of 220 and height of 320 and saves it in C:\yourusername\rig-95\Videos as reachingvideo1cropped.avi
Source code in deeplabcut/utils/auxfun_videos.py
IntersectionofIndividualsandOnesGivenbyUser
Returns all individuals when set to 'all', otherwise all bpts that are in the intersection of comparisonbodyparts and the actual bodyparts.
Source code in deeplabcut/utils/auxfun_multianimal.py
KmeansbasedFrameselection
KmeansbasedFrameselection(
clip, numframes2pick, start, stop, Index=None, step=1, resizewidth=30, batchsize=100, max_iter=50, color=False
)
This code downsamples the video to a width of resizewidth.
The video is extracted as a numpy array, which is then clustered with kmeans, whereby each frames is treated as a vector. Frames from different clusters are then selected for labeling. This procedure makes sure that the frames "look different", i.e. different postures etc. On large videos this code is slow.
Consider not extracting the frames from the whole video but rather set start and stop to a period around interesting behavior.
Note: this method can return fewer images than numframes2pick.
Source code in deeplabcut/utils/frameselectiontools.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
KmeansbasedFrameselectioncv2
KmeansbasedFrameselectioncv2(
cap, numframes2pick, start, stop, Index=None, step=1, resizewidth=30, batchsize=100, max_iter=50, color=False
)
This code downsamples the video to a width of resizewidth. The video is extracted as a numpy array, which is then clustered with kmeans, whereby each frames is treated as a vector. Frames from different clusters are then selected for labeling. This procedure makes sure that the frames "look different", i.e. different postures etc. On large videos this code is slow.
Consider not extracting the frames from the whole video but rather set start and stop to a period around interesting behavior.
Note: this method can return fewer images than numframes2pick.
Attention: the flow of commands was not optimized for readability, but rather speed. This is why it might appear tedious and repetitive.
Source code in deeplabcut/utils/frameselectiontools.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
LoadFullMultiAnimalData
Load predicted data and metadata from pickle files created by predict_videos.py.
Source code in deeplabcut/utils/auxfun_multianimal.py
PlottingResults
PlottingResults(
tmpfolder,
Dataframe,
cfg,
bodyparts2plot,
individuals2plot,
showfigures=False,
suffix=".png",
resolution=100,
linewidth=1.0,
)
Plots poses vs time; pose x vs pose y; histogram of differences and likelihoods.
Source code in deeplabcut/utils/plotting.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
SaveFullMultiAnimalData
Save predicted data as h5 file and metadata as pickle file; created by predict_videos.py.
Source code in deeplabcut/utils/auxfun_multianimal.py
ShortenVideo
Auxiliary function to shorten video and output with outsuffix appended to the same folder from start (hours:minutes:seconds) to stop (hours:minutes:seconds).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
A string containing the full path of the video. |
required |
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall start. |
'00:00:01'
|
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall end. |
'00:01:00'
|
|
str
|
Suffix for output videoname (see example). |
'short'
|
|
str
|
Output path for saving video to (by default, same folder as the video). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The full path to the shortened video. |
Examples:
Linux/MacOs:
deeplabcut.ShortenVideo("/data/videos/mouse1.avi")
Extracts (sub)video from 1st second to 1st minutes (default values) and saves it in /data/videos as mouse1short.avi
Windows:
deeplabcut.ShortenVideo(
"C:\yourusername\rig-95\Videos\reachingvideo1.avi",
start="00:17:00",
stop="00:22:00",
outsuffix="brief",
)
Extracts (sub)video from minute 17 to 22 and saves it in C:\yourusername\rig-95\Videos as reachingvideo1brief.avi
Source code in deeplabcut/utils/auxfun_videos.py
UniformFrames
Temporally uniformly sampling frames in interval (start,stop). Visual information of video is irrelevant for this method. This code is fast and sufficient (to extract distinct frames), when behavioral videos naturally covers many states.
The variable Index allows to pass on a subindex for the frames.
Source code in deeplabcut/utils/frameselectiontools.py
UniformFramescv2
Temporally uniformly sampling frames in interval (start,stop). Visual information of video is irrelevant for this method. This code is fast and sufficient (to extract distinct frames), when behavioral videos naturally covers many states.
The variable Index allows to pass on a subindex for the frames.
Source code in deeplabcut/utils/frameselectiontools.py
adapt_labeled_data_to_new_project
adapt_labeled_data_to_new_project(
config_path: str | Path, remove_old_bodyparts=False, other_scorer=False, userfeedback=False
)
Given the config.yaml file, this function will convert the labels of an ancient project to a new project. For this, the labeled data must be in the project folder, under the labeled-data folder and with the same configuration as all deeplabcut projects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The path to the config.yaml file. |
required |
|
bool
|
If True, old bodyparts not in the new project are removed from the dataframe. Defaults to False. |
False
|
|
bool
|
If True, the labels will be converted to the new scorer. Defaults to False. |
False
|
|
bool
|
If true the user will be asked specifically for each folder in labeled-data if the containing csv shall be converted to hdf format. Defaults to True. |
False
|
Source code in deeplabcut/utils/conversioncode.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
analyze_videos_converth5_to_csv
By default the output poses (when running analyze_videos) are stored as MultiIndex Pandas Array, which contains the name of the network, body part name, (x, y) label position in pixels, and the likelihood for each frame per body part. These arrays are stored in an efficient Hierarchical Data Format (HDF) in the same directory, where the video is stored. This functions converts hdf (h5) files to the comma-separated values format (.csv), which in turn can be imported in many programs, such as MATLAB, R, Prism, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
Absolute path of a folder containing videos and the corresponding h5 data files. |
required |
|
string
|
Only videos with this extension are screened. Defaults to .mp4. |
'.mp4'
|
Examples:
Converts all pose-output files belonging to mp4 videos in the folder '/media/alex/experimentaldata/cheetahvideos' to csv files:
deeplabcut.analyze_videos_converth5_to_csv(
"/media/alex/experimentaldata/cheetahvideos",
".mp4",
)
Source code in deeplabcut/utils/conversioncode.py
analyze_videos_converth5_to_nwb
analyze_videos_converth5_to_nwb(config: str | Path, video_folder: str | Path, videotype='.mp4', listofvideos=False)
Convert all h5 output data files in video_folder to NWB format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
Absolute path to the project YAML config file. |
required |
|
string
|
Absolute path of a folder containing videos and the corresponding h5 data files. |
required |
|
string
|
Only videos with this extension are screened. Defaults to .mp4. |
'.mp4'
|
Examples:
Converts all pose-output files belonging to mp4 videos in the folder '/media/alex/experimentaldata/cheetahvideos' to NWB files:
deeplabcut.analyze_videos_converth5_to_nwb(
config,
"/media/alex/experimentaldata/cheetahvideos",
".mp4",
)
Source code in deeplabcut/utils/conversioncode.py
attempt_to_make_folder
Attempts to create a folder with specified name.
Does nothing if it already exists.
Source code in deeplabcut/utils/auxiliaryfunctions.py
check_if_post_processing
Checks if filtered/bone lengths were already calculated.
If not, figures out if data was already analyzed (either with legacy scorer name or new one!)
Source code in deeplabcut/utils/auxiliaryfunctions.py
collect_video_paths
collect_video_paths(
data_path: str | Path | list[str | Path],
extensions: str | Sequence[str] | None = None,
shuffle: bool = False,
exclude_patterns: Sequence[str] = DEFAULT_EXCLUDE_PATTERNS,
) -> list[Path]
Collects video paths from a given set of data paths: directories, files, or a mix of both. Directories are scanned one level deep (non-recursively).
Files and directories are treated differently with respect to extension filtering:
- File paths are accepted as-is when extensions is None; only filtered when
extensions is explicitly set.
- Directory contents are always filtered by extension: by SUPPORTED_VIDEOS when
extensions is None, or by the given value(s) otherwise.
- exclude_patterns are always applied to both files and directory contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | list[str | Path]
|
Path or list of paths to folders containing videos, or individual video files. Can be a mix of directories and files. |
required |
|
str | Sequence[str] | None
|
Controls extension filtering for collected video files.
- |
None
|
|
bool
|
Whether to shuffle the order of videos. If |
False
|
|
Sequence[str]
|
Patterns to exclude from the collection. Defaults to
|
DEFAULT_EXCLUDE_PATTERNS
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
The paths of videos to analyze. Duplicate paths are removed. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If any path in |
ValueError
|
If |
Source code in deeplabcut/utils/auxfun_videos.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | |
convert2_maDLC
Convert a single-animal annotation file into a multianimal annotation file.
Introduces an individuals column with either the first individual in individuals list in config.yaml or whatever is passed via "forceindividual".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Full path of the config.yaml file as a string. |
required |
|
bool
|
If false, all folders are processed without prompting. If true, the user is asked for each folder whether to convert. Use this, e.g. if you have already labeled some folders and want to convert data for new videos only. |
True
|
|
str | None
|
If a string is given, that value is used in the individuals column. Defaults to None. |
None
|
Examples:
Convert multianimalbodyparts under the 'first individual' in individuals list in
config.yaml and uniquebodyparts under 'single':
deeplabcut.convert2_maDLC("/socialrearing-task/config.yaml")
Convert multianimalbodyparts under the individual label mus17 and uniquebodyparts under 'single':
deeplabcut.convert2_maDLC("/socialrearing-task/config.yaml", forceindividual="mus17")
Source code in deeplabcut/utils/auxfun_multianimal.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
convert_single2multiplelegacyAM
Convert multi animal to single animal code and vice versa.
Note that by providing target='single'/'multi' this will be target!
Source code in deeplabcut/utils/auxfun_multianimal.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
convertcsv2h5
Convert annotation files in labeled-data from csv to h5.
Allows the user to manually edit the csv (e.g. to correct the scorer name and then convert it into hdf format). WARNING: conversion might corrupt the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Full path of the config.yaml file as a string. |
required |
|
bool
|
If true the user will be asked specifically for each folder in labeled-data if the containing csv shall be converted to hdf format. |
True
|
|
string
|
If a string is given, then the scorer/annotator in all csv and hdf files that are changed, will be overwritten with this name. |
None
|
Examples:
Convert csv annotation files for reaching-task project into hdf:
deeplabcut.convertcsv2h5("/analysis/project/reaching-task/config.yaml")
Convert csv annotation files for reaching-task project into hdf while changing the scorer/annotator in all annotation files to Albert:
deeplabcut.convertcsv2h5("/analysis/project/reaching-task/config.yaml", scorer="Albert")
Source code in deeplabcut/utils/conversioncode.py
create_labeled_video
create_labeled_video(
config: str | Path,
videos: list[str | Path],
video_extensions: str | Sequence[str] | None = None,
shuffle: int = 1,
trainingsetindex: int = 0,
filtered: bool = False,
fastmode: bool = True,
save_frames: bool = False,
keypoints_only: bool = False,
Frames2plot: list[int] | None = None,
displayedbodyparts: list[str] | str = "all",
displayedindividuals: list[str] | str = "all",
codec: str = "mp4v",
outputframerate: int | None = None,
destfolder: Path | str | None = None,
draw_skeleton: bool = False,
trailpoints: int = 0,
displaycropped: bool = False,
color_by: str = "bodypart",
modelprefix: str = "",
init_weights: str = "",
track_method: str = "",
superanimal_name: str = "",
pcutoff: float | None = None,
skeleton: list = None,
skeleton_color: str = "white",
dotsize: int = 8,
colormap: str = "rainbow",
alphavalue: float = 0.5,
overwrite: bool = False,
confidence_to_alpha: bool | Callable[[float], float] = False,
plot_bboxes: bool = True,
bboxes_pcutoff: float | None = None,
max_workers: int | None = None,
**kwargs
)
Labels the bodyparts in a video.
Make sure the video is already analyzed by the function
deeplabcut.analyze_videos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Full path of the config.yaml file. |
required |
|
list[str | Path]
|
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. |
required |
|
str | Sequence[str] | None
|
Controls how |
None
|
|
int
|
Number of shuffles of training dataset. Defaults to 1. |
1
|
|
int
|
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml. Defaults to 0. |
0
|
|
bool
|
If True, plot filtered output rather than
frame-by-frame predictions. Filtered version can be calculated with
|
False
|
|
bool
|
If |
True
|
|
bool
|
If |
False
|
|
bool
|
By default, both video frames and keypoints are visible. If |
False
|
|
List[int] or None
|
If not |
None
|
|
list[str] or str
|
Body parts plotted in the video. If |
'all'
|
|
list[str] or str
|
Individuals plotted in the video. By default, all individuals present in the config will be shown. Defaults to "all". |
'all'
|
|
str
|
Codec for labeled video. For available options, see http://www.fourcc.org/codecs.php. Note that this depends on your ffmpeg installation. Defaults to "mp4v". |
'mp4v'
|
|
int or None
|
Output frame rate for labeled video (only
when saving frames). If |
None
|
|
(Path, string or None)
|
Destination folder used for storing analysis data. If
|
None
|
|
bool
|
If |
False
|
|
int
|
Number of previous frames whose body parts are plotted in a frame (for displaying history). Defaults to 0. |
0
|
|
bool
|
Specifies whether only cropped frame is displayed (with labels analyzed therein), or the original frame with the labels analyzed in the cropped subset. Defaults to False. |
False
|
|
string
|
Coloring rule. By default, each bodypart is colored differently. If set to 'individual', points belonging to a single individual are colored the same. Defaults to 'bodypart'. |
'bodypart'
|
|
str
|
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder. Defaults to "". |
''
|
|
str
|
Checkpoint path to the super model. Defaults to "". |
''
|
|
string
|
Tracker used to generate the data. Empty by default (corresponding to a single animal project). For multiple animals, must be either 'box', 'skeleton', or 'ellipse' and will be taken from the config.yaml file if none is given. Defaults to "". |
''
|
|
str
|
Name of the superanimal model. Defaults to "". |
''
|
|
float
|
Overrides the pcutoff set in the project configuration to plot the trajectories. Defaults to None. |
None
|
|
list
|
Skeleton definition for drawing. Defaults to None. |
None
|
|
string
|
Color for the skeleton. Defaults to "white". |
'white'
|
|
int
|
Size of label dots to use. Defaults to 8. |
8
|
|
str
|
Colormap to use for the labels. Defaults to "rainbow". |
'rainbow'
|
|
float
|
Transparency of markers. Defaults to 0.5. |
0.5
|
|
bool
|
If |
False
|
|
bool | Callable[[float], float]
|
If False, all keypoints use alpha=1. Otherwise, a function f: [0, 1] -> [0, 1] maps score to alpha. When True, f(x) = max(0, (x - pcutoff)/(1 - pcutoff)). Defaults to False. |
False
|
|
bool
|
If using Pytorch and in Top-Down mode, setting this to true will also plot the bounding boxes. Defaults to True. |
True
|
|
float
|
If plotting bounding boxes, this overrides the bboxes_pcutoff set in the model configuration. Defaults to None. |
None
|
|
int | None
|
Maximum number of processes to use for multiprocessing. Set this parameter to limit the total RAM-usage of simultaneous processes. Default: no maximum (i.e. number of spawned processes is based on the number of cores and the number of input videos). |
None
|
|
dict
|
Additional arguments. For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index |
{}
|
Returns:
| Type | Description |
|---|---|
|
list[bool]: |
Examples:
Create the labeled video for a single video
deeplabcut.create_labeled_video(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/videos/reachingvideo1.avi'],
)
Create the labeled video for a single video and store the individual frames
deeplabcut.create_labeled_video(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/videos/reachingvideo1.avi'],
fastmode=True,
save_frames=True,
)
Create the labeled video for multiple videos
deeplabcut.create_labeled_video(
'/analysis/project/reaching-task/config.yaml',
[
'/analysis/project/videos/reachingvideo1.avi',
'/analysis/project/videos/reachingvideo2.avi',
],
)
Create the labeled video for all the videos with an .avi extension in a directory.
deeplabcut.create_labeled_video(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/videos/'],
)
Create the labeled video for all the videos with an .mp4 extension in a directory.
deeplabcut.create_labeled_video(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/videos/'],
video_extensions='mp4',
)
Source code in deeplabcut/utils/make_labeled_video.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 | |
create_video_with_all_detections
create_video_with_all_detections(
config: str | Path,
videos: list[str | Path],
video_extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
displayedbodyparts="all",
cropping: list[int] | None = None,
destfolder=None,
modelprefix="",
confidence_to_alpha: bool | Callable[[float], float] = False,
plot_bboxes: bool = True,
**kwargs
)
Create a video labeled with all the detections stored in a '*_full.pickle' file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Absolute path to the config.yaml file. |
required |
|
list[str | Path]
|
Full paths to videos for analysis, or a directory where all videos with the same extension are stored. |
required |
|
str | Sequence[str] | None
|
Controls how |
None
|
|
int
|
Number of shuffles of training dataset. Defaults to 1. |
1
|
|
int
|
Integer specifying which TrainingsetFraction to use. By default the first (note that TrainingFraction is a list in config.yaml). |
0
|
|
list of strings
|
Body parts plotted in the video.
Either |
'all'
|
|
list[int]
|
If passed in, [x1, x2, y1, y2] crop coordinates shift detections appropriately. Defaults to None. |
None
|
|
string
|
Destination folder used for storing analysis data (default is the path of the video). |
None
|
|
bool | Callable[[float], float]
|
If False, all keypoints use alpha=1. Otherwise, a function f: [0, 1] -> [0, 1] maps score to alpha. When True, f(x) = x. Defaults to False. |
False
|
|
bool
|
If detections were produced using a Pytorch Top-Down model, setting this parameter to True will also plot the bounding boxes generated by the detector. Defaults to True. |
True
|
|
dict
|
Additional arguments. For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index |
{}
|
Source code in deeplabcut/utils/make_labeled_video.py
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | |
deprecated
deprecated(
*, replacement: str | None = None, since: str | None = None, removed_in: str | None = None
) -> Callable[[Callable[P, R]], Callable[P, R]]
Mark a function as deprecated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | None
|
Fully-qualified name of the replacement callable, e.g.
|
None
|
|
str | None
|
Version in which the function was deprecated. |
None
|
|
str | None
|
Version in which the function will be removed. |
None
|
Source code in deeplabcut/core/deprecation.py
filter_files_by_patterns
filter_files_by_patterns(
folder: str | Path,
start_patterns: set[str] | None = None,
contain_patterns: set[str] | None = None,
end_patterns: set[str] | None = None,
) -> list[Path]
Filters files in a folder based on start, contain, and end patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
The folder to search for files. |
required |
|
Set[str] | None
|
Patterns the filenames should start with. If None or empty, this pattern is not taken into account. |
None
|
|
set[str]
|
Patterns the filenames should contain. If None or empty, this pattern is not taken into account. |
None
|
|
set[str]
|
Patterns the filenames should end with. If None or empty, this pattern is not taken into account. |
None
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
List[Path]: List of files that match the criteria. |
Source code in deeplabcut/utils/auxiliaryfunctions.py
filter_unwanted_paf_connections
Get rid of skeleton connections between multi and unique body parts.
Source code in deeplabcut/utils/auxfun_multianimal.py
find_analyzed_data
Find potential data files from the hints given to the function.
Source code in deeplabcut/utils/auxiliaryfunctions.py
find_video_metadata
For backward compatibility, let us search the substring 'meta'.
Source code in deeplabcut/utils/auxiliaryfunctions.py
get_bodyparts
Get the bodyparts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
a project configuration file |
required |
Returns: bodyparts listed in the project (does not include the unique_bodyparts entry)
Source code in deeplabcut/utils/auxiliaryfunctions.py
get_data_and_metadata_filenames
get_data_and_metadata_filenames(
trainingsetfolder: str | Path, trainFraction: float, shuffle: int, cfg: dict
) -> tuple[Path, Path]
Paths to data and metadata files relative to the project root.
Source code in deeplabcut/utils/auxiliaryfunctions.py
get_deeplabcut_path
Get path of where deeplabcut is currently running.
get_evaluation_folder
get_evaluation_folder(
trainFraction: float, shuffle: int, cfg: dict, engine: Engine | None = None, modelprefix: str = ""
) -> Path
Get the evaluation folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float
|
the training fraction (as defined in the project configuration) for which to get the evaluation folder |
required |
|
int
|
the index of the shuffle for which to get the evaluation folder |
required |
|
dict
|
the project configuration |
required |
|
Engine | None
|
The engine for which we want the model folder. Defaults to None, which automatically gets the engine for the shuffle from the training dataset metadata file. |
None
|
|
str
|
The name of the folder |
''
|
Returns:
| Type | Description |
|---|---|
Path
|
the relative path from the project root to the folder containing the model files for a shuffle (configuration files, snapshots, training logs, ...) |
Source code in deeplabcut/utils/auxiliaryfunctions.py
get_model_folder
get_model_folder(
trainFraction: float, shuffle: int, cfg: dict, modelprefix: str = "", engine: Engine = Engine.TF
) -> Path
Get the model folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float
|
the training fraction (as defined in the project configuration) for which to get the model folder |
required |
|
int
|
the index of the shuffle for which to get the model folder |
required |
|
dict
|
the project configuration |
required |
|
str
|
The name of the folder |
''
|
|
Engine
|
The engine for which we want the model folder. Defaults to |
TF
|
Returns:
| Type | Description |
|---|---|
Path
|
the relative path from the project root to the folder containing the model files for a shuffle (configuration files, snapshots, training logs, ...) |
Source code in deeplabcut/utils/auxiliaryfunctions.py
get_scorer_name
get_scorer_name(
cfg: dict,
shuffle: int,
trainFraction: float,
trainingsiterations: str | int = "unknown",
modelprefix: str = "",
engine: Engine | None = None,
**kwargs
)
Extract the scorer/network name for a particular shuffle, training fraction, etc.
If the engine is not specified, determines which to use from the project configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Additional arguments. For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
DLCscorer and DLCscorerlegacy (old naming convention). |
Source code in deeplabcut/utils/auxiliaryfunctions.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
get_snapshots_from_folder
Returns an ordered list of existing snapshot names in the train folder, sorted by increasing training iterations.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no snapshot_names are found in the train_folder. |
Source code in deeplabcut/utils/auxiliaryfunctions.py
get_training_set_folder
Training Set folder for config file based on parameters.
Source code in deeplabcut/utils/auxiliaryfunctions.py
get_unique_bodyparts
Get the unique bodyparts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
a project configuration file |
required |
Returns: all unique bodyparts listed in the project
Source code in deeplabcut/utils/auxiliaryfunctions.py
get_video_list
Get list of videos in a path (if filetype == all), otherwise just a specific file.
Source code in deeplabcut/utils/auxiliaryfunctions.py
getpafgraph
Auxiliary function that turns skeleton (list of connected bodypart pairs) into a list of corresponding indices (with regard to the stacked multianimal/uniquebodyparts)
Convention: multianimalbodyparts go first!
Source code in deeplabcut/utils/auxfun_multianimal.py
grab_files_in_folder
Return the paths of files with extension ext present in folder.
Source code in deeplabcut/utils/auxiliaryfunctions.py
imread
Read image either with skimage or cv2.
Returns frame in uint with 3 color channels.
Source code in deeplabcut/utils/auxfun_videos.py
intersection_of_body_parts_and_ones_given_by_user
Returns all body parts when comparisonbodyparts=='all', otherwise all bpts that are in the intersection of comparisonbodyparts and the actual bodyparts.
Source code in deeplabcut/utils/auxiliaryfunctions.py
merge_windowsannotationdataONlinuxsystem
If a project was created on Windows (and labeled there,) but ran on unix then the data folders corresponding in the keys in cfg['video_sets'] are not found.
This function gets them directly by looping over all folders in labeled-data
Source code in deeplabcut/utils/conversioncode.py
plot_edge_affinity_distributions
plot_edge_affinity_distributions(eval_pickle_file, include_bodyparts='all', output_name='', figsize=(10, 7))
Display the distribution of affinity costs of within- and between-animal edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Path to a *_full.pickle from the evaluation-results folder. |
required |
|
list of strings
|
A list of body part names whose edges are to be shown. By default, all body parts and their corresponding edges are analyzed. We recommend only passing a subset of body parts for projects with large graphs. Defaults to "all". |
'all'
|
|
string
|
Path where the plot is saved. By default, it is stored as costdist.png. |
''
|
|
tuple
|
Figure size in inches. |
(10, 7)
|
Source code in deeplabcut/utils/plotting.py
plot_trajectories
plot_trajectories(
config: str | Path,
videos: list[str | Path],
video_extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
filtered=False,
displayedbodyparts="all",
displayedindividuals="all",
showfigures=False,
destfolder=None,
modelprefix="",
imagetype=".png",
resolution=100,
linewidth=1.0,
track_method="",
pcutoff: float | None = None,
**kwargs
)
Plots the trajectories of various bodyparts across the video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Full path of the config.yaml file. |
required |
|
list[str | Path]
|
Full paths to videos for analysis or a path to the directory, where all the videos with same extension are stored. |
required |
|
str | Sequence[str] | None
|
Controls how |
None
|
|
int
|
Integer specifying the shuffle index of the training dataset. Defaults to 1. |
1
|
|
int
|
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml. Defaults to 0. |
0
|
|
bool
|
Boolean variable indicating if filtered output should be plotted rather than
frame-by-frame predictions. Filtered version can be calculated with
|
False
|
|
list[str] or str
|
This select the body parts that are plotted in the video.
Either |
'all'
|
|
bool
|
If |
False
|
|
string or None
|
Destination folder for analysis data. If
|
None
|
|
str
|
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder. Defaults to "". |
''
|
|
string
|
Output image format: '.tif', '.jpg', '.svg', ".png". Defaults to ".png". |
'.png'
|
|
int
|
Specifies the resolution (in dpi) of saved figures. Note higher resolution figures take longer to generate. Defaults to 100. |
100
|
|
float
|
Specifies width of line for line and histogram plots. Defaults to 1.0. |
1.0
|
|
string
|
Specifies the tracker used to generate the data. Empty by default (corresponding to a single animal project). For multiple animals, must be either 'box', 'skeleton', or 'ellipse' and will be taken from the config.yaml file if none is given. Defaults to "". |
''
|
|
float | None
|
Overrides project pcutoff for plotting trajectories. Defaults to None. |
None
|
|
dict
|
Additional arguments. For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index |
{}
|
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
To label the frames
deeplabcut.plot_trajectories(
'home/alex/analysis/project/reaching-task/config.yaml',
['/home/alex/analysis/project/videos/reachingvideo1.avi'],
)
Source code in deeplabcut/utils/plotting.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
proc_video
proc_video(
videos,
destfolder,
filtered,
DLCscorer,
DLCscorerlegacy,
track_method,
cfg,
individuals,
color_by,
bodyparts,
codec,
bodyparts2connect,
trailpoints,
save_frames,
outputframerate,
Frames2plot,
draw_skeleton,
skeleton_color,
displaycropped,
fastmode,
keypoints_only,
overwrite,
video,
init_weights="",
pcutoff: float | None = None,
confidence_to_alpha: Callable[[float], float] | None = None,
plot_bboxes: bool = True,
bboxes_pcutoff: float = 0.6,
)
Helper function for create_labeled_video.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
|
Source code in deeplabcut/utils/make_labeled_video.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 | |
read_inferencecfg
Load inferencecfg or initialize it.
Source code in deeplabcut/utils/auxfun_multianimal.py
read_pickle
read_plainconfig
Load a YAML config (alias for read_config_as_dict). See deeplabcut.core.config.
renamed_parameter
renamed_parameter(*, old: str, new: str, since: str | None = None) -> Callable[[Callable[P, R]], Callable[P, R]]
Support a renamed keyword argument while warning callers to update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The old parameter name that callers may still pass. |
required |
|
str
|
The current parameter name the function actually accepts. |
required |
|
str | None
|
Version when the rename happened. |
None
|
Rules
newmust be the name used in the function signature and all internal call-sites.oldmust not appear in the signature.- Do not chain renames. If
Awas renamed toBandBis later renamed toC, replace theA→Bdecorator withA→Cdirectly rather than stacking a second decorator. Example: @renamed_parameter(old="A", new="C", since="12.4.0") @renamed_parameter(old="B", new="C", since="13.0.0") def func(*, C: int): print(f"C={C}") - Multiple independent renames on the same function (e.g.
batchsize→batch_sizeandvideotype→video_extensions) are fine as long as they do not form a chain. - This decorator only intercepts keyword arguments. Positional arguments are passed through unchanged; renaming a parameter that callers commonly pass positionally will not be caught.
Source code in deeplabcut/core/deprecation.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
reorder_individuals_in_df
Reorders data of df to match the order given in a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
DataFrame
|
Data from tracked .h5 file. |
required |
|
list of str
|
Desired order of individuals. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Reordered DataFrame. |
Source code in deeplabcut/utils/auxfun_multianimal.py
returnlabelingdata
Returns a specific labeleing data set -- the user will be asked which one.
Source code in deeplabcut/utils/auxfun_multianimal.py
rotate_video
Auxiliary function to rotate a video and output it to the same folder with "outsuffix" appended in its name. Angle is in degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
A string containing the full path of the video. |
required |
|
float
|
Angle to rotate by in degrees. Negative values rotate counter-clockwise. |
required |
|
str
|
Default "Arbitrary", rotates clockwise if "Yes", "Arbitrary" for arbitrary rotation by specified angle. |
'Arbitrary'
|
|
str
|
Suffix for output videoname (see example). |
'rotated'
|
|
str
|
Output path for saving video to (by default, same folder as the video). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The full path to the rotated video. |
Examples:
Linux/MacOs:
deeplabcut.rotate_video("/data/videos/mouse1.avi", angle=90)
Rotates the video by 90 degrees and saves it in /data/videos as mouse1rotated.avi
Windows:
shortenedvideoname = deeplabcut.rotate_video(
"C:\yourusername\rig-95\Videos\reachingvideo1.avi",
angle=180,
rotatecw="Yes",
)
Rotates the video by 180 degrees and saves it in C:\yourusername\rig-95\Videos as reachingvideo1rotated.avi
Source code in deeplabcut/utils/auxfun_videos.py
safe_resolve
Return a resolved Path that is safe to use with str-based I/O.
Prefers Path.resolve() so that symlinks are followed (useful on Linux). Falls back to Path.absolute() when resolve() fails or the resolved path cannot be stat'd via its plain string form — e.g. on Windows 11 + SMB network drives where resolve() may return an unusable \?\Volume{GUID}... form.
See https://github.com/DeepLabCut/DeepLabCut/issues/3348
Source code in deeplabcut/utils/auxiliaryfunctions.py
save_data
Save predicted data as h5 file and metadata as pickle file; created by predict_videos.py.
Source code in deeplabcut/utils/auxiliaryfunctions.py
write_pickle
write_plainconfig
Write a config dict to YAML (alias for write_config). See deeplabcut.core.config.