crops
sleap_nn.inference.ops.crops
¶
Bbox creation + image cropping helpers used by inference.
Two responsibilities:
crop_bboxes— vectorized patch extraction around a set of bboxes. Used by integral peak refinement and top-down stage 2 crop pickup.- Re-export
make_centered_bboxesfrom the data layer so callers in the inference path import from one place. The data layer keeps owning the function (the training pipeline uses it too).
PR 5 of #508 rewrote :func:crop_bboxes to remove the per-peak unfold
formulation that the legacy TorchScript ONNX exporter rejected. The new
implementation:
- pads the image with zeros (matching old out-of-bounds behavior)
- gathers crops via
advanced indexingon the padded tensor - lowers cleanly to ONNX
- matches the previous integer-indexing behavior bit-exactly when bbox top-lefts are integer-aligned (which is the case for both call sites: integer peaks → make_centered_bboxes returns integer bboxes; centroid- driven crops floor the top-left)
Functions:
| Name | Description |
|---|---|
crop_bboxes |
Crop bounding boxes from a batch of images. |
crop_bboxes(images, bboxes, sample_inds, crop_size=None)
¶
Crop bounding boxes from a batch of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Tensor
|
|
required |
bboxes
|
Tensor
|
|
required |
sample_inds
|
Tensor
|
|
required |
crop_size
|
Optional[Tuple[int, int]]
|
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
|
Notes
Bbox top-lefts are floored to the integer grid before extraction,
matching the prior .to(torch.long) behavior. Out-of-image
sample positions are zero-padded.
See Also
:func:make_centered_bboxes.
Source code in sleap_nn/inference/ops/crops.py
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 | |