deeplabcut.post_processing.filtering
Functions:
| Name | Description |
|---|---|
columnwise_spline_interp |
Perform cubic spline interpolation over the columns of data. All gaps of size |
filterpredictions |
Fits frame-by-frame pose predictions. |
columnwise_spline_interp
Perform cubic spline interpolation over the columns of data. All gaps of size lower than or equal to max_gap are filled, and data slightly smoothed.
Parameters
data : array_like 2D matrix of data. max_gap : int, optional Maximum gap size to fill. By default, all gaps are interpolated.
Returns
interpolated data with same shape as data
Source code in deeplabcut/post_processing/filtering.py
filterpredictions
filterpredictions(
config,
video,
video_extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
filtertype="median",
windowlength=5,
p_bound=0.001,
ARdegree=3,
MAdegree=1,
alpha=0.01,
save_as_csv=True,
destfolder=None,
modelprefix="",
track_method="",
return_data=False,
**kwargs
)
Fits frame-by-frame pose predictions.
The pose predictions are fitted with ARIMA model (filtertype='arima') or median filter (default).
Parameters
config : string Full path of the config.yaml file.
string
Full path of the video to extract the frame from. Make sure that this video is already analyzed.
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
The shuffle index of training dataset. The extracted frames will be stored in the labeled-dataset for the corresponding shuffle of training dataset.
int, optional, default=0
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml.
string, optional, default="median".
The filter type - 'arima', 'median' or 'spline'.
int, optional, default=5
For filtertype='median' filters the input array using a local window-size given by windowlength. The array will automatically be zero-padded. https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.medfilt.html. The windowlenght should be an odd number. If filtertype='spline', windowlength is the maximal gap size to fill.
float between 0 and 1, optional, default=0.001
For filtertype 'arima' this parameter defines the likelihood below, below which a body part will be consided as missing data for filtering purposes.
int, optional, default=3
For filtertype 'arima' Autoregressive degree of Sarimax model degree. see https://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html
int, optional, default=1
For filtertype 'arima' Moving Average degree of Sarimax model degree. See https://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html
float, optional, default=0.01
Significance level for detecting outliers based on confidence interval of fitted SARIMAX model.
bool, optional, default=True
Saves the predictions in a .csv file.
string, optional, default=None
Specifies the destination folder for analysis data. If None, the path of
the video is used by default. Note that for subsequent analysis this folder
also needs to be passed.
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=""
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.
bool, optional, default=False
If True, returns a dictionary of the filtered data keyed by video names.
additional arguments.
For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Returns
video_to_filtered_df Dictionary mapping video filepaths to filtered dataframes.
* If no videos exist, the dictionary will be empty.
* If a video is not analyzed, the corresponding value in the dictionary will be
None.
Examples
Arima model:
deeplabcut.filterpredictions( 'C:\myproject\reaching-task\config.yaml', ['C:\myproject\trailtracking-task\test.mp4'], shuffle=3, filterype='arima', ARdegree=5, MAdegree=2, )
Use median filter over 10 bins:
deeplabcut.filterpredictions( 'C:\myproject\reaching-task\config.yaml', ['C:\myproject\trailtracking-task\test.mp4'], shuffle=3, windowlength=10, )
One can then use the filtered rather than the frame-by-frame predictions by calling:
deeplabcut.plot_trajectories( 'C:\myproject\reaching-task\config.yaml', ['C:\myproject\trailtracking-task\test.mp4'], shuffle=3, filtered=True, )
deeplabcut.create_labeled_video( 'C:\myproject\reaching-task\config.yaml', ['C:\myproject\trailtracking-task\test.mp4'], shuffle=3, filtered=True, )
Source code in deeplabcut/post_processing/filtering.py
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 | |