mlvbench.tasks.binary_segmentation¶
Binary segmentation task.
BinarySegmentationEvaluator
¶
Bases: Evaluator
Evaluator for binary segmentation tasks.
__init__(patch_size, save_predictions=8)
¶
Initialize the evaluator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patch_size
|
int
|
The patch size of the model, used to reconstruct the spatial layout of patches for visualization. |
required |
save_predictions
|
int
|
The maximum number of samples for which to keep raw
predictions. Samples are taken in the order they are passed to
|
8
|
finalize()
¶
Finalize the evaluation and return summary, results and predictions.
update(batch, prediction, target, weight=None)
¶
Update the evaluator with predictions and targets for a single batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
dict[str, Any]
|
A batch from the dataset. This evaluator expects a list of sample
keys as |
required |
prediction
|
Tensor
|
The prediction from the probe with shape |
required |
target
|
Tensor
|
The target for the task with shape |
required |
weight
|
Tensor | None
|
Optional per-patch weight tensor with shape |
None
|
BinarySegmentationTask
¶
Bases: Task
Binary segmentation task.
Predict whether each patch belongs to the foreground (segmentation > 0).
__init__(patch_size=None)
¶
configure(model)
¶
Configure the task for the given model.
criterion(prediction, target, weight=None)
¶
Loss function for the task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
Tensor
|
Probe output logits with shape |
required |
target
|
Tensor
|
Binary target labels with shape |
required |
weight
|
Tensor | None
|
Optional per-patch weights with shape |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The scalar binary cross-entropy loss, a |
get_evaluator(save_predictions=8)
¶
Return an evaluator for the task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_predictions
|
int
|
The maximum number of samples for which the evaluator keeps raw predictions. Set to 0 to disable. |
8
|
prepare_target(batch)
¶
Prepare the target for the probe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
dict[str, Tensor]
|
A batch from the dataset. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor]
|
A tuple of (target, weights) where target has shape |