dlc_reader.py
PoseEstimation
¶
Class for handling DLC pose estimation files.
Source code in element_deeplabcut/readers/dlc_reader.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 |
|
pkl
property
¶
Pickle file contents
yml
property
¶
json-structured config.yaml file contents
rawdata
property
¶
Raw data from h5 file
data
property
¶
Data from the h5 file, restructured as a dict
df
property
¶
Data as dataframe
body_parts
property
¶
Set of body parts present in data file
reformat_rawdata()
¶
Transform raw h5 data into dict
Source code in element_deeplabcut/readers/dlc_reader.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
read_yaml(fullpath, filename='*')
¶
Return contents of yml in fullpath. If available, defer to DJ-saved version
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fullpath |
str
|
String or pathlib path. Directory with yaml files |
required |
filename |
str
|
Filename, no extension. Permits wildcards. |
'*'
|
Returns:
Type | Description |
---|---|
tuple
|
Tuple of (a) filepath as pathlib.PosixPath and (b) file contents as dict |
Source code in element_deeplabcut/readers/dlc_reader.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
save_yaml(output_dir, config_dict, filename='dj_dlc_config', mkdir=True)
¶
Save config_dict to output_path as filename.yaml. By default, preserves original.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir |
str
|
where to save yaml file |
required |
config_dict |
str
|
dict of config params or element-deeplabcut model.Model dict |
required |
filename |
str
|
default 'dj_dlc_config' or preserve original 'config' Set to 'config' to overwrite original file. If extension is included, removed and replaced with "yaml". |
'dj_dlc_config'
|
mkdir |
bool
|
Optional, True. Make new directory if output_dir not exist |
True
|
Returns:
Type | Description |
---|---|
str
|
path of saved file as string - due to DLC func preference for strings |
Source code in element_deeplabcut/readers/dlc_reader.py
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 |
|
do_pose_estimation(key, video_filepaths, dlc_model, project_path, output_dir, videotype='', gputouse=None, save_as_csv=False, batchsize=None, cropping=None, TFGPUinference=True, dynamic=(False, 0.5, 10), robust_nframes=False, allow_growth=False, use_shelve=False)
¶
Launch DLC's analyze_videos within element-deeplabcut.
Also saves a copy of the current config in the output dir, with ensuring analyzed videos in the video_set. NOTE: Config-specificed cropping not supported when adding to config in this manner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
video_filepaths |
list
|
list of videos to analyze |
required |
dlc_model |
dict
|
element-deeplabcut dlc.Model |
required |
project_path |
str
|
path to project config.yml |
required |
output_dir |
str
|
where to save output BELOW FROM DLC'S DOCSTRING¶ |
required |
videotype |
str, optional, default=""
|
Checks for the extension of the video in case the input to the video is a directory. Only videos with this extension are analyzed. If unspecified, videos with common extensions ('avi', 'mp4', 'mov', 'mpeg', 'mkv') are kept. |
''
|
gputouse |
int or None, optional, default=None
|
Indicates the GPU to use (see number in |
None
|
save_as_csv |
bool, optional, default=False
|
Saves the predictions in a .csv file. |
False
|
batchsize |
int or None, optional, default=None
|
Change batch size for inference; if given overwrites |
None
|
cropping |
list or None, optional, default=None
|
List of cropping coordinates as [x1, x2, y1, y2].
Note that the same cropping parameters will then be used for all videos.
If different video crops are desired, run |
None
|
TFGPUinference |
bool, optional, default=True
|
Perform inference on GPU with TensorFlow code. Introduced in "Pretraining boosts out-of-domain robustness for pose estimation" by Alexander Mathis, Mert Yüksekgönül, Byron Rogers, Matthias Bethge, Mackenzie W. Mathis. Source https://arxiv.org/abs/1909.11229 |
True
|
dynamic |
tuple(bool, float, int) triple (state, detectiontreshold, margin
|
If the state is true, then dynamic cropping will be performed. That means that if an object is detected (i.e. any body part > detectiontreshold), then object boundaries are computed according to the smallest/largest x position and smallest/largest y position of all body parts. This window is expanded by the margin and from then on only the posture within this crop is analyzed (until the object is lost, i.e. <detectiontreshold). The current position is utilized for updating the crop window for the next frame (this is why the margin is important and should be set large enough given the movement of the animal). |
(False, 0.5, 10)
|
robust_nframes |
bool, optional, default=False
|
Evaluate a video's number of frames in a robust manner. This option is slower (as the whole video is read frame-by-frame), but does not rely on metadata, hence its robustness against file corruption. |
False
|
allow_growth |
bool, optional, default=False.
|
For some smaller GPUs the memory issues happen. If |
False
|
use_shelve |
bool, optional, default=False
|
By default, data are dumped in a pickle file at the end of the video analysis. Otherwise, data are written to disk on the fly using a "shelf"; i.e., a pickle-based, persistent, database-like object by default, resulting in constant memory footprint. |
False
|
Source code in element_deeplabcut/readers/dlc_reader.py
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 |
|