predict
sleap_nn.predict
¶
Entry point for running inference.
Functions:
Name | Description |
---|---|
frame_list |
Converts 'n-m' string to list of ints. |
run_inference |
Entry point to run inference on trained SLEAP-NN models. |
frame_list(frame_str)
¶
Converts 'n-m' string to list of ints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame_str
|
str
|
string representing range |
required |
Returns:
Type | Description |
---|---|
Optional[List[int]]
|
List of ints, or None if string does not represent valid range. |
Source code in sleap_nn/predict.py
run_inference(data_path=None, input_labels=None, input_video=None, model_paths=None, backbone_ckpt_path=None, head_ckpt_path=None, max_instances=None, max_width=None, max_height=None, ensure_rgb=None, input_scale=None, ensure_grayscale=None, anchor_part=None, only_labeled_frames=False, only_suggested_frames=False, batch_size=4, queue_maxsize=8, video_index=None, video_dataset=None, video_input_format='channels_last', frames=None, crop_size=None, peak_threshold=0.2, integral_refinement='integral', integral_patch_size=5, return_confmaps=False, return_pafs=False, return_paf_graph=False, max_edge_length_ratio=0.25, dist_penalty_weight=1.0, n_points=10, min_instance_peaks=0, min_line_scores=0.25, return_class_maps=False, return_class_vectors=False, make_labels=True, output_path=None, device='auto', tracking=False, tracking_window_size=5, min_new_track_points=0, candidates_method='fixed_window', min_match_points=0, features='keypoints', scoring_method='oks', scoring_reduction='mean', robust_best_instance=1.0, track_matching_method='hungarian', max_tracks=None, use_flow=False, of_img_scale=1.0, of_window_size=21, of_max_levels=3, post_connect_single_breaks=False)
¶
Entry point to run inference on trained SLEAP-NN models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_path
|
Optional[str]
|
(str) Path to |
None
|
input_labels
|
Optional[Labels]
|
(sio.Labels) Labels object to run inference on. This is an alternative to specifying the data_path. |
None
|
input_video
|
Optional[Video]
|
(sio.Video) Video to run inference on. This is an alternative to specifying the data_path. If both input_labels and input_video are provided, input_labels are used. |
None
|
model_paths
|
Optional[List[str]]
|
(List[str]) List of paths to the directory where the best.ckpt and training_config.yaml are saved. |
None
|
backbone_ckpt_path
|
Optional[str]
|
(str) To run inference on any |
None
|
head_ckpt_path
|
Optional[str]
|
(str) Path to |
None
|
max_instances
|
Optional[int]
|
(int) Max number of instances to consider from the predictions. |
None
|
max_width
|
Optional[int]
|
(int) Maximum width the image should be padded to. If not provided, the values from the training config are used. Default: None. |
None
|
max_height
|
Optional[int]
|
(int) Maximum height the image should be padded to. If not provided, the values from the training config are used. Default: None. |
None
|
input_scale
|
Optional[float]
|
(float) Scale factor to apply to the input image. If not provided, the values from the training config are used. Default: None. |
None
|
ensure_rgb
|
Optional[bool]
|
(bool) True if the input image should have 3 channels (RGB image). If input has only one
channel when this is set to |
None
|
ensure_grayscale
|
Optional[bool]
|
(bool) True if the input image should only have a single channel. If input has three channels (RGB) and this
is set to True, then we convert the image to grayscale (single-channel)
image. If the source image has only one channel and this is set to False, then we retain the single channel input. If not provided, the
values from the training config are used. Default: |
None
|
anchor_part
|
Optional[str]
|
(str) The node name to use as the anchor for the centroid. If not
provided, the anchor part in the |
None
|
only_labeled_frames
|
bool
|
(bool) |
False
|
only_suggested_frames
|
bool
|
(bool) |
False
|
batch_size
|
int
|
(int) Number of samples per batch. Default: 4. |
4
|
queue_maxsize
|
int
|
(int) Maximum size of the frame buffer queue. Default: 8. |
8
|
video_index
|
Optional[int]
|
(int) Integer index of video in .slp file to predict on. To be used with an .slp path as an alternative to specifying the video path. |
None
|
video_dataset
|
Optional[str]
|
(str) The dataset for HDF5 videos. |
None
|
video_input_format
|
str
|
(str) The input_format for HDF5 videos. |
'channels_last'
|
frames
|
Optional[list]
|
(list) List of frames indices. If |
None
|
crop_size
|
Optional[int]
|
(int) Crop size. If not provided, the crop size from training_config.yaml is used. Default: None. |
None
|
peak_threshold
|
Union[float, List[float]]
|
(float) Minimum confidence threshold. Peaks with values below
this will be ignored. Default: 0.2. This can also be |
0.2
|
integral_refinement
|
Optional[str]
|
(str) If |
'integral'
|
integral_patch_size
|
int
|
(int) Size of patches to crop around each rough peak as an integer scalar. Default: 5. |
5
|
return_confmaps
|
bool
|
(bool) If |
False
|
return_pafs
|
bool
|
(bool) If |
False
|
return_class_vectors
|
bool
|
If |
False
|
return_paf_graph
|
bool
|
(bool) If |
False
|
max_edge_length_ratio
|
float
|
(float) The maximum expected length of a connected pair of points as a fraction of the image size. Candidate connections longer than this length will be penalized during matching. Default: 0.25. |
0.25
|
dist_penalty_weight
|
float
|
(float) A coefficient to scale weight of the distance penalty as a scalar float. Set to values greater than 1.0 to enforce the distance penalty more strictly.Default: 1.0. |
1.0
|
n_points
|
int
|
(int) Number of points to sample along the line integral. Default: 10. |
10
|
min_instance_peaks
|
Union[int, float]
|
Union[int, float] Minimum number of peaks the instance should have to be considered a real instance. Instances with fewer peaks than this will be discarded (useful for filtering spurious detections). Default: 0. |
0
|
min_line_scores
|
float
|
(float) Minimum line score (between -1 and 1) required to form a match between candidate point pairs. Useful for rejecting spurious detections when there are no better ones. Default: 0.25. |
0.25
|
return_class_maps
|
bool
|
If |
False
|
make_labels
|
bool
|
(bool) If |
True
|
output_path
|
Optional[str]
|
(str) Path to save the labels file if |
None
|
device
|
str
|
(str) Device on which torch.Tensor will be allocated. One of the
('cpu', 'cuda', 'mps', 'auto').
Default: "auto" (based on available backend either cuda, mps or cpu is chosen). If |
'auto'
|
tracking
|
bool
|
(bool) If True, runs tracking on the predicted instances. |
False
|
tracking_window_size
|
int
|
Number of frames to look for in the candidate instances to match with the current detections. Default: 5. |
5
|
min_new_track_points
|
int
|
We won't spawn a new track for an instance with fewer than this many points. Default: 0. |
0
|
candidates_method
|
str
|
Either of |
'fixed_window'
|
min_match_points
|
int
|
Minimum non-NaN points for match candidates. Default: 0. |
0
|
features
|
str
|
Feature representation for the candidates to update current detections.
One of [ |
'keypoints'
|
scoring_method
|
str
|
Method to compute association score between features from the
current frame and the previous tracks. One of [ |
'oks'
|
scoring_reduction
|
str
|
Method to aggregate and reduce multiple scores if there are
several detections associated with the same track. One of [ |
'mean'
|
robust_best_instance
|
float
|
If the value is between 0 and 1 (excluded), use a robust quantile similarity score for the track. If the value is 1, use the max similarity (non-robust). For selecting a robust score, 0.95 is a good value. |
1.0
|
track_matching_method
|
str
|
Track matching algorithm. One of |
'hungarian'
|
max_tracks
|
Optional[int]
|
Meaximum number of new tracks to be created to avoid redundant tracks. (only for local queues candidate) Default: None. |
None
|
use_flow
|
bool
|
If True, |
False
|
optical flow shifts. Default
|
|
required | |
of_img_scale
|
float
|
Factor to scale the images by when computing optical flow. Decrease
this to increase performance at the cost of finer accuracy. Sometimes
decreasing the image scale can improve performance with fast movements.
Default: 1.0. (only if |
1.0
|
of_window_size
|
int
|
Optical flow window size to consider at each pyramid scale
level. Default: 21. (only if |
21
|
of_max_levels
|
int
|
Number of pyramid scale levels to consider. This is different
from the scale parameter, which determines the initial image scaling.
Default: 3. (only if |
3
|
post_connect_single_breaks
|
bool
|
If True and |
False
|
Returns:
Type | Description |
---|---|
Returns |
Source code in sleap_nn/predict.py
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 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 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 |
|