API Reference
BankSource
Bases: Module
External-bank source: paste pre-staged crops from an instance bank.
The bank tensor ([B, K_bank, 5, h, w] packed as RGB+alpha+class-id)
is set per training step via :meth:set_bank_batch. sample then
multinomial-picks one crop per batch row, places it at the origin of
a target-sized canvas (forming a synthetic source view with
K_source = 1), and draws per-target (scale, translate, hflip)
affine parameters. placement.source_idx = arange(B) so each
target gathers from its own row of the source view.
Pinning K_source = 1 matches v0.3.0 "one paste per target"
semantics; multi-crop-per-target is a future extension. Configurable
placement geometry shares :class:BatchedPlacementConfig knobs with
:class:IntraBatchSource.
Source code in src/segpaste/augmentation/source.py
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 | |
set_bank_batch(bank_batch)
Stage a per-step bank tensor of shape [B, K_bank, 5, h, w].
Source code in src/segpaste/augmentation/source.py
BatchCopyPaste
Bases: Module
Graph-compilable batched copy-paste augmentation.
Source code in src/segpaste/augmentation/batch_copy_paste.py
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 | |
BatchedDenseSample
dataclass
Canonical batched container for dense-label Copy-Paste.
Stacked fields share (H, W) across the batch — LSJ preprocessing is
assumed to have homogenized sample shapes. Ragged fields keep one entry
per sample. B == 0 is valid (empty batches produce zero-length lists
and zero-batch-dim stacked tensors).
Source code in src/segpaste/types/batched_dense_sample.py
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 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 | |
from_padded(padded)
staticmethod
Unpack a :class:PaddedBatchedDenseSample into a ragged batch.
Uses instance_valid as the per-sample gather mask. Reconstructs
tv_tensors.BoundingBoxes in XYXY format (the DenseSample canonical
convention) and unpacks the [B, 4] intrinsics tensor back into
:class:CameraIntrinsics instances.
Source code in src/segpaste/types/batched_dense_sample.py
from_samples(samples)
staticmethod
Stack a list of :class:DenseSample into a :class:BatchedDenseSample.
All samples must share the same active modality set and the same
(H, W). B == 0 yields an empty-but-valid batch.
Source code in src/segpaste/types/batched_dense_sample.py
to_padded(max_instances)
Pack ragged per-sample instance fields into K-padded tensors.
Valid rows are written at slots [0, n_i) for each sample i and
marked True in instance_valid. Padded rows are zero-valued.
Raises if any sample has more than max_instances objects.
Source code in src/segpaste/types/batched_dense_sample.py
to_samples()
Unstack back into per-sample :class:DenseSample objects.
Source code in src/segpaste/types/batched_dense_sample.py
CameraIntrinsics
dataclass
Pinhole camera intrinsics in pixel coordinates.
Required on a :class:DenseSample when any composite is constructed with
metric_depth=True.
Source code in src/segpaste/types/dense_sample.py
DenseSample
dataclass
Canonical per-sample container for dense-label Copy-Paste.
Modality-specific fields are None when their modality is not active.
Use :meth:active_modalities to derive the active set.
Source code in src/segpaste/types/dense_sample.py
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 | |
active_modalities()
Return the set of active modalities for this sample.
Source code in src/segpaste/types/dense_sample.py
to_dict()
Round-trippable dict representation. Omits None fields.
FixedSizeCrop
Bases: Transform
Source code in src/segpaste/augmentation/lsj.py
__init__(output_height, output_width, img_pad_value=0, seg_pad_value=255)
Crops the given image to a fixed size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_height
|
int
|
Desired output height. |
required |
output_width
|
int
|
Desired output width. |
required |
Source code in src/segpaste/augmentation/lsj.py
InstanceBank
Bases: Protocol
Read-only sequence of class-labeled instance crops.
Concrete backends (MemmapBank, LMDBBank, WebDatasetBank)
live under :mod:segpaste._internal.bank until promotion. The
Protocol is the only public name; users construct backends via the
scripts/build_instance_bank.py CLI (PR5) or import the backend
class directly from segpaste._internal.bank.
Implementations must be safe to call from DataLoader workers — i.e.
re-entrant after __init__ and free of un-pickle-able state — so
num_workers > 0 is supported.
Source code in src/segpaste/_internal/bank/protocol.py
class_frequencies
property
int64 [num_classes] count of crops per class (zero-indexed).
crop_class_ids
property
int64 [N] class id per crop. Zero-copy on memmap backends;
loaded once at open. Lets :class:BankSampler build per-crop
weights without an O(N) pass through __getitem__.
crop_size
property
(h, w) after preprocessing — the same for every crop.
has_embeddings
property
Whether BankCrop.embedding is populated for every crop.
version
property
Stable {format}@{sha256[:12]} identifier for cache keys.
InstanceMask
Bases: Mask
Per-instance binary masks. Shape [N, H, W], dtype bool.
Source code in src/segpaste/types/dense_sample.py
IntraBatchSource
Bases: Module
v0.3.0-equivalent source: sample sources from the same batch.
Wraps :class:BatchedPlacementSampler and returns target itself as
the source view. The diagonal-masked multinomial inside the sampler
guarantees source_idx[i] != i for B > 1. Default constructor
matches v0.3.0 defaults; pass a :class:BatchedPlacementConfig for
non-default placement parameters.
Source code in src/segpaste/augmentation/source.py
Modality
Bases: Enum
Dense-sample modalities. IMAGE is always active; the others gate fields.
Source code in src/segpaste/types/dense_sample.py
PaddedBatchedDenseSample
dataclass
Fully-rectangular batched container for graph-compilable augmentation.
Source code in src/segpaste/types/padded_batched_dense_sample.py
PaddingMask
Bases: Mask
Unlike tv_tensor.Mask, PaddingMask is not associated with any object.
It is used to indicate padded parts of an Image. Unlike tv_tensor.Mask, it is is forwarded unchanged by this package reimplementation SanitizeBoundingBoxes.
Source code in src/segpaste/types/data_structures.py
from_tensor(data)
classmethod
Wrap a bool tensor as :class:PaddingMask with the static type preserved.
Mask.__new__ is annotated to return Mask; this factory exists
purely to recover PaddingMask typing without smearing cast at
every call site.
Source code in src/segpaste/types/data_structures.py
PanopticMap
Bases: Mask
Per-pixel panoptic id encoding. Shape [H, W], dtype int64.
Source code in src/segpaste/types/dense_sample.py
PanopticSchema
Bases: Protocol
Panoptic class taxonomy, passed explicitly at composite construction.
Source code in src/segpaste/types/dense_sample.py
PresetConfig
Bases: _FrozenStrict
A registered dataset preset (ADR-0009 §3).
Field additions are allowed (additive-only per ADR-0001 Part (i)); renames or removals are breaking.
Source code in src/segpaste/presets/_base.py
batch_copy_paste = Field(default_factory=BatchCopyPasteConfig)
class-attribute
instance-attribute
The augmentation hyperparameters this preset pins.
description
instance-attribute
One-paragraph human-readable rationale.
name
instance-attribute
Stable identifier; matches the registry key.
sign_off = None
class-attribute
instance-attribute
Audit trail for the local sign-off ritual (ADR-0009 §5).
target_modalities
instance-attribute
Dense-sample modalities this preset expects to see.
RandomResize
Bases: Transform
Source code in src/segpaste/augmentation/lsj.py
__init__(min_scale, max_scale, target_height, target_width)
Randomly resize the input image while preserving aspect ratio.
The final size is obtained by scaling the target height and width with a random factor.
Source code in src/segpaste/augmentation/lsj.py
SanitizeBoundingBoxes
Bases: SanitizeBoundingBoxes
Source code in src/segpaste/augmentation/lsj.py
transform(inpt, params)
Unlike the original SanitizeBoundingBoxes, this transform can also handle PaddingMask and will forward them unchanged.
Source code in src/segpaste/augmentation/lsj.py
SemanticMap
Bases: Mask
Per-pixel semantic class ids. Shape [H, W], dtype int64, ignore = 255.
Source code in src/segpaste/types/dense_sample.py
SourceStrategy
Bases: Protocol
Picks the source view and per-target placement for one forward step.
Implementations may be nn.Module subclasses (so child modules and
buffers register correctly) or plain callables — :func:runtime_checkable
structural typing only requires sample. The return contract is fixed:
source_view row-aligned with target along the batch dim, and
placement.source_idx indexing into source_view.
Source code in src/segpaste/augmentation/source.py
create_coco_dataloader(image_folder, label_path, transforms, batch_size=4, collate_fn=_identity_collate)
Create a COCO DataLoader preconfigured for segpaste pipelines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_folder
|
str
|
Directory containing the COCO image files. |
required |
label_path
|
str
|
Path to the COCO JSON annotations file. |
required |
transforms
|
Transform
|
Transform applied to each sample. |
required |
batch_size
|
int
|
Batch size for the returned DataLoader. |
4
|
collate_fn
|
Any
|
Collate function; defaults to an identity collate that
yields |
_identity_collate
|
Returns:
| Type | Description |
|---|---|
DataLoader[DenseSample]
|
A DataLoader yielding :class: |
Source code in src/segpaste/integrations/coco.py
get_preset(name)
Return the registered preset for name.
Raises:
| Type | Description |
|---|---|
KeyError
|
if name is not registered. |
Source code in src/segpaste/presets/__init__.py
list_presets()
make_large_scale_jittering(output_size, min_scale=0.1, max_scale=2.0, img_pad_value=0, seg_pad_value=255)
Factory function to create a LargeScaleJittering transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_size
|
int or tuple
|
The desired output size (height, width) of the crop. |
required |
min_scale
|
float
|
The minimum scale factor for resizing. |
0.1
|
max_scale
|
float
|
The maximum scale factor for resizing. |
2.0
|
img_pad_value
|
float or int
|
Fill value for image padding. |
0
|
seg_pad_value
|
int
|
Fill value for segmentation mask padding. |
255
|
Returns:
| Type | Description |
|---|---|
Transform
|
A Compose transform implementing Large Scale Jittering. |
Source code in src/segpaste/augmentation/lsj.py
register_preset(config)
Register config under config.name.
Raises:
| Type | Description |
|---|---|
ValueError
|
if |