Metrics

Contents

Metrics#

Segmentation#

LazySlide provides comprehensive segmentation evaluation metrics for both instance segmentation and semantic segmentation tasks.

Here’s how to evaluate segmentation performance using LazySlide’s metrics:

import geopandas as gpd
from shapely.geometry import Polygon
from lazyslide.metrics.segmentation import (
    get_instance_stats,
    get_semantic_stats,
    accuracy,
    mean_iou,
    pq,
)

# Ground truth in geodataframe
gt_polygons = [
    Polygon([(0, 0), (10, 0), (10, 10), (0, 10)]),  # Square 1
    Polygon([(15, 15), (25, 15), (25, 25), (15, 25)])  # Square 2
]
gdf_true = gpd.GeoDataFrame({'geometry': gt_polygons})

# Prediction in geodataframe
pred_polygons = [
    Polygon([(1, 1), (9, 1), (9, 9), (1, 9)]),      # Slightly smaller square 1
    Polygon([(16, 16), (24, 16), (24, 24), (16, 24)]),  # Slightly smaller square 2
    Polygon([(30, 30), (40, 30), (40, 40), (30, 40)])   # False positive
]
gdf_pred = gpd.GeoDataFrame({'geometry': pred_polygons})

# Instance segmentation evaluation
instance_stats = get_instance_stats(gdf_true, gdf_pred, iou_threshold=0.5)

# Semantic segmentation evaluation
semantic_stats = get_semantic_stats(gdf_true, gdf_pred)

# Calculate various metrics
acc = accuracy(semantic_stats)
miou = mean_iou(instance_stats)
pq = pq(instance_stats)

SegmentationStats

Statistics for segmentation evaluation.

get_instance_stats

Compute instance segmentation statistics using Hungarian algorithm matching.

get_semantic_stats

Compute semantic segmentation statistics using area-based overlap.

accuracy

Compute accuracy from segmentation statistics.

precision

Compute precision from segmentation statistics.

recall

Compute recall (sensitivity) from segmentation statistics.

f1_score

Compute F1 score from segmentation statistics.

mean_iou

Compute mean Intersection over Union (mIoU) from segmentation statistics.

dice

Compute Dice coefficient from segmentation statistics.

sensitivity

Compute sensitivity (true positive rate) from segmentation statistics.

specificity

Compute specificity (true negative rate) from segmentation statistics.

pq

Compute Panoptic Quality (PQ) from segmentation statistics.

TopK#