visualization
orchard.evaluation.visualization
¶
Visualization utilities for model evaluation.
Provides formatted visual reports including training loss/accuracy curves, normalized confusion matrices, and sample prediction grids. Integrated with the PlotContext DTO for aesthetic and technical consistency.
show_predictions(model, loader, device, classes, save_path=None, ctx=None, n=None)
¶
Visualize model predictions on a sample batch.
Coordinates data extraction, model inference, grid layout generation, and image post-processing. Highlights correct (green) vs. incorrect (red) predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Trained model to evaluate. |
required |
loader
|
DataLoader[Any]
|
DataLoader providing evaluation samples. |
required |
device
|
device
|
Target device for inference. |
required |
classes
|
list[str]
|
Human-readable class label names. |
required |
save_path
|
Path | None
|
Output file path. If None, displays interactively. |
None
|
ctx
|
PlotContext | None
|
PlotContext with layout and normalization settings. |
None
|
n
|
int | None
|
Number of samples to display. Defaults to |
None
|
Source code in orchard/evaluation/visualization.py
plot_training_curves(train_losses, val_accuracies, out_path, ctx)
¶
Plot training loss and validation accuracy on a dual-axis chart.
Saves the figure to disk and exports raw numerical data as .npz
for reproducibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_losses
|
Sequence[float]
|
Per-epoch training loss values. |
required |
val_accuracies
|
Sequence[float]
|
Per-epoch validation accuracy values. |
required |
out_path
|
Path
|
Destination file path for the saved figure. |
required |
ctx
|
PlotContext
|
PlotContext with architecture and evaluation settings. |
required |
Source code in orchard/evaluation/visualization.py
plot_confusion_matrix(all_labels, all_preds, classes, out_path, ctx)
¶
Generate and save a row-normalized confusion matrix plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_labels
|
NDArray[Any]
|
Ground-truth label array. |
required |
all_preds
|
NDArray[Any]
|
Predicted label array. |
required |
classes
|
list[str]
|
Human-readable class label names. |
required |
out_path
|
Path
|
Destination file path for the saved figure. |
required |
ctx
|
PlotContext
|
PlotContext with architecture and evaluation settings. |
required |