deeplabcut.refine_training_dataset.stitch
Classes:
| Name | Description |
|---|---|
Tracklet |
|
Functions:
| Name | Description |
|---|---|
stitch_tracklets |
Stitch sparse tracklets into full tracks via a graph-based, minimum-cost flow |
Tracklet
Methods:
| Name | Description |
|---|---|
__add__ |
Join this tracklet to another one. |
__contains__ |
Test whether tracklets temporally overlap. |
__gt__ |
Test whether this tracklet follows the other one. |
__init__ |
Create a Tracklet object. |
__lt__ |
Test whether this tracklet precedes the other one. |
box_overlap_with |
Calculate the overlap between each Tracklet's bounding box. |
calc_rate_of_turn |
Calculate the rate of turn (or angular velocity) of either the |
calc_velocity |
Calculate the linear velocity of either the |
contains_duplicates |
Evaluate whether the Tracklet contains duplicate time indices. |
distance_to |
Calculate the Euclidean distance between this Tracklet and another. |
dynamic_dissimilarity_with |
Compute a dissimilarity score between Hankelets. This metric efficiently |
dynamic_similarity_with |
Evaluate the complexity of the tracklets' underlying dynamics from the rank |
estimate_rank |
Estimate the (low) rank of a noisy matrix via hard thresholding of singular |
immediately_follows |
Test whether this Tracklet follows another within a tolerance of |
motion_affinity_with |
Evaluate the motion affinity of this Tracklet' with another one. |
shape_dissimilarity_with |
Calculate the dissimilarity in shape between this Tracklet and another. |
time_gap_to |
Return the time gap separating this Tracklet to another. |
Attributes:
| Name | Type | Description |
|---|---|---|
centroid |
Return the instantaneous 2D position of the Tracklet centroid. |
|
end |
Return the time at which the tracklet ends. |
|
identity |
Return the average predicted identity of all Tracklet detections. |
|
is_continuous |
Test whether there are gaps in the time indices. |
|
likelihood |
Return the average likelihood of all Tracklet detections. |
|
start |
Return the time at which the tracklet starts. |
|
xy |
Return the x and y coordinates. |
Source code in deeplabcut/refine_training_dataset/stitch.py
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 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 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 | |
centroid
property
Return the instantaneous 2D position of the Tracklet centroid.
For Tracklets longer than 10 frames, the centroid is automatically smoothed using an exponential moving average. The result is cached for efficiency.
__add__
__contains__
__gt__
__init__
Create a Tracklet object.
Parameters
data : ndarray 3D array of shape (nframes, nbodyparts, 3 or 4), where the last dimension is for x, y, likelihood and, optionally, identity. inds : array-like Corresponding time frame indices.
Source code in deeplabcut/refine_training_dataset/stitch.py
__lt__
box_overlap_with
Calculate the overlap between each Tracklet's bounding box.
Source code in deeplabcut/refine_training_dataset/stitch.py
calc_rate_of_turn
Calculate the rate of turn (or angular velocity) of either the head or
tail of the Tracklet, computed over the last or first three frames,
respectively.
Source code in deeplabcut/refine_training_dataset/stitch.py
calc_velocity
Calculate the linear velocity of either the head or tail of the Tracklet,
computed over the last or first three frames, respectively.
If norm, return the absolute
speed rather than a 2D vector.
Source code in deeplabcut/refine_training_dataset/stitch.py
contains_duplicates
Evaluate whether the Tracklet contains duplicate time indices.
If return_indices, also return the indices of the duplicates.
Source code in deeplabcut/refine_training_dataset/stitch.py
distance_to
Calculate the Euclidean distance between this Tracklet and another.
If the Tracklets overlap in time, this is the mean distance over those frames. Otherwise, it is the distance between the head/tail of one to the tail/head of the other.
Source code in deeplabcut/refine_training_dataset/stitch.py
dynamic_dissimilarity_with
Compute a dissimilarity score between Hankelets. This metric efficiently captures the degree of alignment of the subspaces spanned by the columns of both matrices.
See Li et al., 2012. Cross-view Activity Recognition using Hankelets.
Source code in deeplabcut/refine_training_dataset/stitch.py
dynamic_similarity_with
Evaluate the complexity of the tracklets' underlying dynamics from the rank of their Hankel matrices, and assess whether they originate from the same track. The idea is that if two tracklets are part of the same track, they can be approximated by a low order regressor. Conversely, tracklets belonging to different tracks will require a higher order regressor.
See Dicle et al., 2013. The Way They Move: Tracking Multiple Targets with Similar Appearance.
Source code in deeplabcut/refine_training_dataset/stitch.py
estimate_rank
Estimate the (low) rank of a noisy matrix via hard thresholding of singular values.
See Gavish & Donoho, 2013. The optimal hard threshold for singular values is 4/sqrt(3)
Source code in deeplabcut/refine_training_dataset/stitch.py
immediately_follows
Test whether this Tracklet follows another within a tolerance ofmax_gap
frames.
motion_affinity_with
Evaluate the motion affinity of this Tracklet' with another one.
This evaluates whether the Tracklets could realistically be reached by one another, knowing the time separating them and their velocities. Return 0 if the Tracklets overlap.
Source code in deeplabcut/refine_training_dataset/stitch.py
shape_dissimilarity_with
Calculate the dissimilarity in shape between this Tracklet and another.
Source code in deeplabcut/refine_training_dataset/stitch.py
time_gap_to
Return the time gap separating this Tracklet to another.
Source code in deeplabcut/refine_training_dataset/stitch.py
stitch_tracklets
stitch_tracklets(
config_path,
videos,
video_extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
n_tracks=None,
animal_names: list[str] | None = None,
min_length=10,
split_tracklets=True,
prestitch_residuals=True,
max_gap=None,
weight_func=None,
destfolder=None,
modelprefix="",
track_method="",
output_name="",
transformer_checkpoint="",
save_as_csv=False,
**kwargs
)
Stitch sparse tracklets into full tracks via a graph-based, minimum-cost flow optimization problem.
Parameters
config_path : str Path to the main project config.yaml file.
list
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
An integer specifying the shuffle index of the training dataset used for training the network. The default is 1.
int, optional
Integer specifying which TrainingsetFraction to use. By default the first (note that TrainingFraction is a list in config.yaml).
int, optional
Number of tracks to reconstruct. By default, taken as the number of individuals defined in the config.yaml. Another number can be passed if the number of animals in the video is different from the number of animals the model was trained on.
list, optional
If you want the names given to individuals in the labeled data file, you can
specify those names as a list here. If given and n_tracks is None, n_tracks
will be set to len(animal_names). If n_tracks is not None, then it must be
equal to len(animal_names). If it is not given, then animal_names will
be loaded from the individuals in the project config.yaml file.
int, optional
Tracklets less than min_length frames of length
are considered to be residuals; i.e., they do not participate
in building the graph and finding the solution to the
optimization problem, but are rather added last after
"almost-complete" tracks are formed. The higher the value,
the lesser the computational cost, but the higher the chance of
discarding relatively long and reliable tracklets that are
essential to solving the stitching task.
Default is 10, and must be 3 at least.
bool, optional
By default, tracklets whose time indices are not consecutive integers
are split in shorter tracklets whose time continuity is guaranteed.
This is for example very powerful to get rid of tracking errors
(e.g., identity switches) which are often signaled by a missing
time frame at the moment they occur. Note though that for long
occlusions where tracker re-identification capability can be trusted,
setting split_tracklets to False is preferable.
bool, optional
Residuals will by default be grouped together according to their temporal proximity prior to being added back to the tracks. This is done to improve robustness and simultaneously reduce complexity.
int, optional
Maximal temporal gap to allow between a pair of tracklets. This is automatically determined by the TrackletStitcher by default.
callable, optional
Function accepting two tracklets as arguments and returning a scalar that must be inversely proportional to the likelihood that the tracklets belong to the same track; i.e., the higher the confidence that the tracklets should be stitched together, the lower the returned value.
string, optional
Specifies the destination folder for analysis data (default is the path of the video). Note that for subsequent analysis this folder also needs to be passed.
string, optional
Specifies the tracker used to generate the pose estimation data. 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
Name of the output h5 file. By default, tracks are automatically stored into the same directory as the pickle file and with its name.
bool, optional
Whether to write the tracks to a CSV file too (False by default).
additional arguments.
For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Returns
A TrackletStitcher object
Source code in deeplabcut/refine_training_dataset/stitch.py
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 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 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 | |