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 |
|
crossvalutils |
|
deprecation |
|
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) |
trainingsetmanipulation |
|
video_processor |
Author: Hao Wu |
visualization |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
Classes:
| Name | Description |
|---|---|
DLCDeprecationWarning |
Project-specific deprecation warning. Helps with filtering. |
VideoProcessor |
Base class for a video processing unit, implementation is required for video |
VideoProcessorCV |
OpenCV implementation of VideoProcessor requires opencv-python==3.4.0.12. |
VideoWriter |
|
vp |
OpenCV implementation of VideoProcessor requires opencv-python==3.4.0.12. |
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 |
Save predicted data as h5 file and metadata as pickle file; created by |
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 |
Converts single animal annotation file into a multianimal annotation file, |
convert_single2multiplelegacyAM |
Convert multi animal to single animal code and vice versa. |
convertcsv2h5 |
Convert (image) annotation files in folder labeled-data from csv to h5. |
create_config_template |
Creates a template for config.yaml file. |
create_config_template_3d |
Creates a template for config.yaml file for 3d project. |
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. |
edit_config |
Convenience function to edit and save a config file from a dictionary. |
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 |
Args: |
get_deeplabcut_path |
Get path of where deeplabcut is currently running. |
get_evaluation_folder |
Args: |
get_immediate_subdirectories |
Get list of immediate subdirectories. |
get_model_folder |
Args: |
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 |
Args: |
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_videos. |
read_config |
Reads structured config file defining a project. |
read_inferencecfg |
Load inferencecfg or initialize it. |
read_pickle |
Read the pickle file. |
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 |
save_data |
Save predicted data as h5 file and metadata as pickle file; created by |
write_config |
Write structured config file. |
write_config_3d |
Write structured 3D config file. |
write_pickle |
Write the pickle file. |
DLCDeprecationWarning
Bases: DeprecationWarning
Project-specific deprecation warning. Helps with filtering.
VideoProcessor
Base class for a video processing unit, implementation is required for video loading and saving.
sh and sw are the output height and width respectively.
Methods:
| Name | Description |
|---|---|
close |
Implement your own. |
create_video |
Implement your own. |
get_info |
Implement your own. |
get_video |
Implement your own. |
save_frame |
Implement your own. |
Source code in deeplabcut/utils/video_processor.py
close
create_video
get_info
get_video
VideoProcessorCV
Bases: VideoProcessor
OpenCV implementation of VideoProcessor requires opencv-python==3.4.0.12.
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
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 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
shorten
Shorten the video from start to end.
Parameter
start: str Time formatted in hours:minutes:seconds, where shortened video shall start.
str
Time formatted in hours:minutes:seconds, where shortened video shall end.
str, optional
String added to the name of the shortened video ('short' by default).
str, optional
Folder the video is saved into (by default, same as the original video)
Returns
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
n_splits : int Number of shorter videos to produce
str, optional
String added to the name of the splits ('short' by default).
str, optional
Folder the video splits are saved into (by default, same as the original video)
Returns
list Paths of the video splits
Source code in deeplabcut/utils/auxfun_videos.py
vp
Bases: VideoProcessor
OpenCV implementation of VideoProcessor requires opencv-python==3.4.0.12.
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 391 | |
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.
Returns the full path to the downsampled video!
ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
Parameter
vname : string A string containing the full path of the video.
int
width of output video
int
height of output video.
origin_x, origin_y: int x- and y- axis origin of bounding box for cropping.
str
Suffix for output videoname (see example).
str
Output path for saving video to (by default will be the same folder as the 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.
Returns the full path to the downsampled video!
Parameter
vname : string A string containing the full path of the video.
int
width of output video
int
height of output video.
str
Suffix for output videoname (see example).
str
Output path for saving video to (by default will be the same folder as the video)
str
Default "No", rotates clockwise if "Yes", "Arbitrary" for arbitrary rotation by specified angle.
float
Angle to rotate by in degrees, default 0.0. Negative values rotate counter-clockwise
Examples
Linux/MacOs
deeplabcut.DownSampleVideo('/data/videos/mouse1.avi')
Downsamples the video using default values and saves it in /data/videos as mouse1cropped.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 203 | |
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
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 343 | |
LoadFullMultiAnimalData
Save predicted data as h5 file and metadata as pickle file; 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
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 | |
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).
Returns the full path to the shortened video!
Parameter
videos : string A string containing the full paths of the video.
hours:minutes:seconds
Time formatted in hours:minutes:seconds, where shortened video shall start.
hours:minutes:seconds
Time formatted in hours:minutes:seconds, where shortened video shall end.
str
Suffix for output videoname (see example).
str
Output path for saving video to (by default will be the same folder as the 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 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, 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
config_path : str The path to the config.yaml file. remove_old_bodyparts : bool (default = False) If True, the old bodyparts that are not in the new project will be removed from the dataframe. other_scorer : bool (default = False) If True, the labels will be converted to the new scorer. userfeedback : bool (default = True) If true the user will be asked specifically for each folder in labeled-data if the containing csv shall be converted to hdf format.
Source code in deeplabcut/utils/conversioncode.py
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 | |
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
video_folder : string Absolute path of a folder containing videos and the corresponding h5 data files.
videotype: string, optional (default=.mp4) Only videos with this extension are screened.
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
Convert all h5 output data files in video_folder to NWB format.
Parameters
config : string Absolute path to the project YAML config file.
string
Absolute path of a folder containing videos and the corresponding h5 data files.
string, optional (default=.mp4)
Only videos with this extension are screened.
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
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
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 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 | |
convert2_maDLC
Converts single animal annotation file into a multianimal annotation file, by introducing an individuals column with either the first individual in individuals list in config.yaml or whatever is passed via "forceindividual".
config : string Full path of the config.yaml file as a string.
bool, optional
If this is set to false during automatic mode then frames for all videos are extracted. The user can set this to true, which will result in a dialog, where the user is asked for each video if (additional/any) frames from this video should be extracted. Use this, e.g. if you have already labeled some folders and want to extract data for new videos.
None default
If a string is given that is used in the individuals column.
Examples
Converts mulianimalbodyparts under the 'first individual' in individuals list in config.yaml and uniquebodyparts under 'single'
deeplabcut.convert2_maDLC('/socialrearing-task/config.yaml')
Converts mulianimalbodyparts 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
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 | |
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
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 516 517 518 519 520 521 522 523 | |
convertcsv2h5
Convert (image) annotation files in folder labeled-data from csv to h5. This function 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.
string
Full path of the config.yaml file as a string.
bool, optional
If true the user will be asked specifically for each folder in labeled-data if the containing csv shall be converted to hdf format.
string, optional
If a string is given, then the scorer/annotator in all csv and hdf files that are changed, will be overwritten with this name.
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_config_template
Creates a template for config.yaml file.
This specific order is preserved while saving as yaml file.
Source code in deeplabcut/utils/auxiliaryfunctions.py
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 | |
create_config_template_3d
Creates a template for config.yaml file for 3d project.
This specific order is preserved while saving as yaml file.
Source code in deeplabcut/utils/auxiliaryfunctions.py
create_labeled_video
create_labeled_video(
config: str,
videos: list[str],
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
config : string Full path of the config.yaml file.
list[str]
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.
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
scanned for files with a recognized video extension.
- str or Sequence[str] (e.g. "mp4" or ["mp4", "avi"]):
both file paths and directory contents are filtered by the given
extension(s).
int, optional, default=1
Number of shuffles of training dataset.
int, optional, default=0
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml.
bool, optional, default=False
Boolean variable indicating if filtered output should be plotted rather than
frame-by-frame predictions. Filtered version can be calculated with
deeplabcut.filterpredictions.
bool, optional, default=True
If True, uses openCV (much faster but less customization of video) instead
of matplotlib if False. You can also "save_frames" individually or not in
the matplotlib mode (if you set the "save_frames" variable accordingly).
However, using matplotlib to create the frames it therefore allows much more
flexible (one can set transparency of markers, crop, and easily customize).
bool, optional, default=False
If True, creates each frame individual and then combines into a video.
Setting this to True is relatively slow as it stores all individual frames.
bool, optional, default=False
By default, both video frames and keypoints are visible. If True, only the
keypoints are shown. These clips are an hommage to Johansson movies,
see https://www.youtube.com/watch?v=1F5ICP9SYLU and of course his seminal
paper: "Visual perception of biological motion and a model for its analysis"
by Gunnar Johansson in Perception & Psychophysics 1973.
List[int] or None, optional, default=None
If not None and save_frames=True then the frames corresponding to the
index will be plotted. For example, Frames2plot=[0,11] will plot the first
and the 12th frame.
list[str] or str, optional, default="all"
This selects the body parts that are plotted in the video. If all, then all
body parts from config.yaml are used. If a list of strings that are a subset of
the full list. E.g. ['hand','Joystick'] for the demo
Reaching-Mackenzie-2018-08-30/config.yaml to select only these body parts.
list[str] or str, optional, default="all"
Individuals plotted in the video. By default, all individuals present in the config will be shown.
str, optional, default="mp4v"
Codec for labeled video. For available options, see http://www.fourcc.org/codecs.php. Note that this depends on your ffmpeg installation.
int or None, optional, default=None
Positive number, output frame rate for labeled video (only available for the
mode with saving frames.) If None, which results in the original video
rate.
Path, string or None, optional, default=None
Specifies the destination folder that was used for storing analysis data. If
None, the path of the video file is used.
bool, optional, default=False
If True adds a line connecting the body parts making a skeleton on each
frame. The body parts to be connected and the color of these connecting lines
are specified in the config file.
int, optional, default=0
Number of previous frames whose body parts are plotted in a frame (for displaying history).
bool, optional, default=False
Specifies whether only cropped frame is displayed (with labels analyzed therein), or the original frame with the labels analyzed in the cropped subset.
string, optional, default='bodypart'
Coloring rule. By default, each bodypart is colored differently. If set to 'individual', points belonging to a single individual are colored the same.
str, optional, default=""
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder.
str,
Checkpoint path to the super model
string, optional, default=""
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.
str, optional, default=""
Name of the superanimal model.
float, optional, default=None
Overrides the pcutoff set in the project configuration to plot the trajectories.
skeleton: list, optional, default=[],
string, optional, default="white",
Color for the skeleton
dotsize, int, optional, default=8, Size of label dots tu use
str, optional, default="rainbow",
Colormap to use for the labels
alphavalue: float, optional, default=0.5,
bool, optional, default=False
If True overwrites existing labeled videos.
Union[bool, Callable[[float], float], default=False
If False, all keypoints will be plot with alpha=1. Otherwise, this can be defined as a function f: [0, 1] -> [0, 1] such that the alpha value for a keypoint will be set as a function of its score: alpha = f(score). The default function used when True is f(x) = max(0, (x - pcutoff)/(1 - pcutoff)).
bool, optional, default=True
If using Pytorch and in Top-Down mode, setting this to true will also plot the bounding boxes
bboxes_pcutoff, float, optional, default=None: If plotting bounding boxes, this overrides the bboxes_pcutoff set in the model configuration.
max_workers (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).
additional arguments.
For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Returns
results : list[bool]
``True`` if the video is successfully created for each item in ``videos``.
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
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 714 715 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 | |
create_video_with_all_detections
create_video_with_all_detections(
config,
videos,
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
config : str Absolute path to the config.yaml file
list of str
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.
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
scanned for files with a recognized video extension.
- str or Sequence[str] (e.g. "mp4" or ["mp4", "avi"]):
both file paths and directory contents are filtered by the given
extension(s).
int, optional
Number of shuffles of training dataset. Default is set to 1.
int, optional
Integer specifying which TrainingsetFraction to use. By default the first (note that TrainingFraction is a list in config.yaml).
list of strings, optional
This selects the body parts that are plotted in the video.
Either all, then all body parts from config.yaml are used or
a list of strings that are a subset of the full list.
E.g. ['hand','Joystick'] for the demo Reaching-Mackenzie-2018-08-30/config.yaml
to select only these two body parts.
list[int], optional (default=None)
If passed in, the [x1, x2, y1, y2] crop coordinates are used to shift detections appropriately.
string, optional
Specifies the destination folder that was used for storing analysis data (default is the path of the video).
Union[bool, Callable[[float], float], default=False
If False, all keypoints will be plot with alpha=1. Otherwise, this can be defined as a function f: [0, 1] -> [0, 1] such that the alpha value for a keypoint will be set as a function of its score: alpha = f(score). The default function used when True is f(x) = x.
bool, optional (default=True)
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.
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
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 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 | |
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/utils/deprecation.py
edit_config
Convenience function to edit and save a config file from a dictionary.
Parameters
configname : string String containing the full path of the config file in the project. edits : dict Key–value pairs to edit in config output_name : string, optional (default='') Overwrite the original config.yaml by default. If passed in though, new filename of the edited config.
Examples
config_path = 'my_stellar_lab/dlc/config.yaml'
edits = {'numframes2pick': 5, 'trainingFraction': [0.5, 0.8], 'skeleton': [['a', 'b'], ['b', 'c']]}
deeplabcut.auxiliaryfunctions.edit_config(config_path, edits)
Source code in deeplabcut/utils/auxiliaryfunctions.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
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_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
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_immediate_subdirectories
get_model_folder
get_model_folder(
trainFraction: float, shuffle: int, cfg: dict, modelprefix: str = "", engine: Engine = Engine.TF
) -> Path
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 kwargs: additional arguments. For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Returns tuple of DLCscorer, DLCscorerlegacy (old naming convention)
Source code in deeplabcut/utils/auxiliaryfunctions.py
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 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | |
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
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
eval_pickle_file : string Path to a *_full.pickle from the evaluation-results folder.
list of strings, optional
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.
string, optional
Path where the plot is saved. By default, it is stored as costdist.png.
tuple
Figure size in inches.
Source code in deeplabcut/utils/plotting.py
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 | |
plot_trajectories
plot_trajectories(
config,
videos,
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
config: str Full path of the config.yaml file.
list[str]
Full paths to videos for analysis or a path to the directory, where all the videos with same extension are stored.
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
scanned for files with a recognized video extension.
- str or Sequence[str] (e.g. "mp4" or ["mp4", "avi"]):
both file paths and directory contents are filtered by the given
extension(s).
int, optional, default=1
Integer specifying the shuffle index of the training dataset.
int, optional, default=0
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml.
bool, optional, default=False
Boolean variable indicating if filtered output should be plotted rather than
frame-by-frame predictions. Filtered version can be calculated with
deeplabcut.filterpredictions.
list[str] or str, optional, default="all"
This select the body parts that are plotted in the video.
Either all, then all body parts from config.yaml are used,
or a list of strings that are a subset of the full list.
E.g. ['hand','Joystick'] for the demo Reaching-Mackenzie-2018-08-30/config.yaml
to select only these two body parts.
bool, optional, default=False
If True then plots are also displayed.
string or None, optional, default=None
Specifies the destination folder that was used for storing analysis data. If
None, the path of the video is used.
str, optional, default=""
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder.
string, optional, default=".png"
Specifies the output image format - '.tif', '.jpg', '.svg' and ".png".
int, optional, default=100
Specifies the resolution (in dpi) of saved figures. Note higher resolution figures take longer to generate.
float, optional, default=1.0
Specifies width of line for line and histogram plots.
string, optional, default=""
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.
string, optional, default=None
Overrides the pcutoff set in the project configuration to plot the trajectories.
additional arguments.
For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Returns
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
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 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 | |
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_videos.
Parameters
Returns
result : bool
``True`` if a video is successfully created.
Source code in deeplabcut/utils/make_labeled_video.py
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 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
read_config
Reads structured config file defining a project.
Source code in deeplabcut/utils/auxiliaryfunctions.py
read_inferencecfg
Load inferencecfg or initialize it.
Source code in deeplabcut/utils/auxfun_multianimal.py
read_pickle
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/utils/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:
df: pd.DataFrame Data from tracked .h5 file order: list of str Desired order of individuals
Return:
df: 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.
Returns the full path to the rotated video!
Parameter
vname : string A string containing the full path of the video.
float
Angle to rotate by in degrees. Negative values rotate counter-clockwise.
str
Default "Arbitrary", rotates clockwise if "Yes", "Arbitrary" for arbitrary rotation by specified angle.
str
Suffix for output videoname (see example).
str
Output path for saving video to (by default will be the same folder as the 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
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_config
Write structured config file.
Source code in deeplabcut/utils/auxiliaryfunctions.py
write_config_3d
Write structured 3D config file.