feature_suggestions
sleap.info.feature_suggestions
¶
Module for generating lists of frames using frame features, pca, kmeans, etc.
Classes:
| Name | Description |
|---|---|
FrameGroupSet |
Class for a set of groups of FrameItem objects. |
FrameItem |
Just a simple wrapper for (video, frame_idx), plus method to get image. |
HogVec |
|
ItemStack |
Container for items, each item can "own" one or more rows of data. |
ParallelFeaturePipeline |
Enables easy per-video pipeline parallelization for feature suggestions. |
FrameGroupSet
¶
Bases: object
Class for a set of groups of FrameItem objects.
Each item can have at most one group; each group is represented as an int.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
str
|
Label for the method used to generate group set. |
item_group |
Dict[FrameItem, int]
|
Dictionary which maps each item to its group. |
group_data |
Dict[int, dict]
|
Dictionary of any extra data for each group; keys are group ids, values are dictionaries of data. |
groupset_data |
Dict
|
Dictionary for any data about the entire set of groups. |
Methods:
| Name | Description |
|---|---|
append_to_group |
Adds item to group. |
extend_group_items |
Adds all items in list to group. |
get_item_group |
Returns group that contain item. |
sample |
Returns new FrameGroupSet with groups sampled from current groups. |
Source code in sleap/info/feature_suggestions.py
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 | |
all_items
property
¶
Gets list of all items.
groups
property
¶
Iterate over groups, yielding group and list of items.
append_to_group(group, item)
¶
Adds item to group.
Source code in sleap/info/feature_suggestions.py
266 267 268 269 270 | |
extend_group_items(group, item_list)
¶
Adds all items in list to group.
Source code in sleap/info/feature_suggestions.py
272 273 274 275 | |
get_item_group(item)
¶
Returns group that contain item.
Source code in sleap/info/feature_suggestions.py
277 278 279 | |
sample(per_group, unique_samples=True)
¶
Returns new FrameGroupSet with groups sampled from current groups.
Note that the order of items in the new groups will not match order of items in the groups from which samples are drawn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
per_group
|
int
|
The number of samples to take from each group. |
required |
unique_samples
|
bool
|
Whether to ensure that there are no shared items in the resulting groups. |
True
|
Returns:
| Type | Description |
|---|---|
|
New FrameGroupSet. |
Source code in sleap/info/feature_suggestions.py
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 | |
FrameItem
¶
Bases: object
Just a simple wrapper for (video, frame_idx), plus method to get image.
Source code in sleap/info/feature_suggestions.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
HogVec
¶
Methods:
| Name | Description |
|---|---|
get_brisk_keypoints_as_points |
Returns matrix of brisk keypoints for single image. |
get_hogs |
Returns descriptors and corresponding image for all images. |
get_image_crops |
Returns stack of windows around keypoints on single image. |
get_image_hog |
Returns hog descriptor for all brisk keypoints on single image. |
Source code in sleap/info/feature_suggestions.py
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 | |
get_brisk_keypoints_as_points(img)
¶
Returns matrix of brisk keypoints for single image.
Source code in sleap/info/feature_suggestions.py
211 212 213 214 215 | |
get_hogs(imgs)
¶
Returns descriptors and corresponding image for all images.
Source code in sleap/info/feature_suggestions.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
get_image_crops(img, points)
¶
Returns stack of windows around keypoints on single image.
Source code in sleap/info/feature_suggestions.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
get_image_hog(img)
¶
Returns hog descriptor for all brisk keypoints on single image.
Source code in sleap/info/feature_suggestions.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
ItemStack
¶
Bases: object
Container for items, each item can "own" one or more rows of data.
Attributes:
| Name | Type | Description |
|---|---|---|
items |
List
|
The list of items |
data |
Optional[ndarray]
|
An ndarray with rows of data corresponding to items. |
ownership |
Optional[List[tuple]]
|
List which specifies which rows of data correspond to which items. |
meta |
List
|
List which stores metadata about each operation on stack. |
group_sets |
List[FrameGroupSet]
|
List of GroupSets of items. |
Methods:
| Name | Description |
|---|---|
brisk_bag_of_features |
Transform data using bag of features based on brisk features. |
extend_ownership |
Extends an ownership list with number of rows owned by next item. |
flatten |
Flattens each row of data to 1-d array. |
get_all_items_from_group |
Sets items for Stack to all items from current GroupSet. |
get_item_data |
Returns rows of data which belong to item. |
get_item_data_idxs |
Returns indexes of rows in data which belong to item. |
get_raw_images |
Sets data to raw image for each FrameItem. |
hog_bag_of_features |
Transforms data into bag of features vector of hog descriptors. |
kmeans |
Adds GroupSet using k-means clustering on data. |
make_sample_group |
Adds GroupSet by sampling frames from each video. |
pca |
Transforms data by applying PCA. |
sample_groups |
Adds GroupSet by sampling items from current GroupSet. |
Source code in sleap/info/feature_suggestions.py
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 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 | |
current_groupset
property
¶
Gets current (most recent) group set.
brisk_bag_of_features(brisk_threshold=40, vocab_size=20)
¶
Transform data using bag of features based on brisk features.
Source code in sleap/info/feature_suggestions.py
439 440 441 442 | |
extend_ownership(ownership, row_count)
¶
Extends an ownership list with number of rows owned by next item.
Source code in sleap/info/feature_suggestions.py
390 391 392 393 394 395 396 397 398 | |
flatten()
¶
Flattens each row of data to 1-d array.
Source code in sleap/info/feature_suggestions.py
430 431 432 433 434 435 436 437 | |
get_all_items_from_group()
¶
Sets items for Stack to all items from current GroupSet.
Source code in sleap/info/feature_suggestions.py
512 513 514 515 516 | |
get_item_data(item)
¶
Returns rows of data which belong to item.
Source code in sleap/info/feature_suggestions.py
374 375 376 377 | |
get_item_data_idxs(item)
¶
Returns indexes of rows in data which belong to item.
Source code in sleap/info/feature_suggestions.py
365 366 367 368 369 370 371 372 | |
get_raw_images(scale=0.5)
¶
Sets data to raw image for each FrameItem.
Source code in sleap/info/feature_suggestions.py
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 | |
hog_bag_of_features(brisk_threshold=40, vocab_size=20)
¶
Transforms data into bag of features vector of hog descriptors.
Source code in sleap/info/feature_suggestions.py
444 445 446 447 | |
kmeans(n_clusters)
¶
Adds GroupSet using k-means clustering on data.
Source code in sleap/info/feature_suggestions.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
make_sample_group(videos, samples_per_video, sample_method='stride')
¶
Adds GroupSet by sampling frames from each video.
Source code in sleap/info/feature_suggestions.py
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 | |
pca(n_components)
¶
Transforms data by applying PCA.
Source code in sleap/info/feature_suggestions.py
449 450 451 452 453 454 455 456 457 458 459 460 | |
sample_groups(samples_per_group)
¶
Adds GroupSet by sampling items from current GroupSet.
Source code in sleap/info/feature_suggestions.py
518 519 520 521 522 523 524 | |
ParallelFeaturePipeline
¶
Bases: object
Enables easy per-video pipeline parallelization for feature suggestions.
Create a FeatureSuggestionPipeline with the desired parameters, and
then call ParallelFeaturePipeline.run() with the pipeline and the list
of videos to process in parallel. This will take care of serializing the
videos, running the pipelines in a process pool, and then deserializing
the results back into a single list of SuggestionFrame objects.
Methods:
| Name | Description |
|---|---|
get |
Apply pipeline to single video by idx. Can be called in process. |
make |
Make class object from pipeline and list of videos. |
run |
Runs pipeline on all videos in parallel and returns suggestions. |
tuples_to_suggestions |
Converts serialized data from processes back into SuggestionFrames. |
Source code in sleap/info/feature_suggestions.py
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 | |
get(video_idx)
¶
Apply pipeline to single video by idx. Can be called in process.
Source code in sleap/info/feature_suggestions.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
make(pipeline, videos)
classmethod
¶
Make class object from pipeline and list of videos.
Source code in sleap/info/feature_suggestions.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | |
run(pipeline, videos, parallel=True)
classmethod
¶
Runs pipeline on all videos in parallel and returns suggestions.
Source code in sleap/info/feature_suggestions.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | |
tuples_to_suggestions(tuples, videos)
classmethod
¶
Converts serialized data from processes back into SuggestionFrames.
Source code in sleap/info/feature_suggestions.py
683 684 685 686 687 688 689 690 691 692 | |