Skip to main content

Signed Distance Function based loss functions for deep learning semantic segmentation to miss fewer instances.

Project description

SDF Loss

Signed Distance Function (SDF) based loss functions for deep learning semantic segmentation.

Overview

This library provides PyTorch loss functions that use Signed Distance Functions to weight pixels based on their distance from object boundaries. This approach puts heavier penalties on false positives and false negatives that are farther from the correct boundary, leading to more accurate segmentation results.

Installation

Install directly from PyPI:

pip install sdf-loss

Or using uv:

uv add sdf-loss

Quick Start

import torch
from sdf_loss import DiSCoLoss

# Initialize the loss function
criterion = DiSCoLoss()

# Your model predictions (logits) and ground truth
pred_logits = model(images)  # Shape: (B, 1, H, W)
target = ground_truth         # Shape: (B, 1, H, W), binary mask

# Compute loss
loss = criterion(pred_logits, target)
loss.backward()

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sdf_loss-0.1.1.tar.gz (73.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sdf_loss-0.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file sdf_loss-0.1.1.tar.gz.

File metadata

  • Download URL: sdf_loss-0.1.1.tar.gz
  • Upload date:
  • Size: 73.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for sdf_loss-0.1.1.tar.gz
Algorithm Hash digest
SHA256 39e6eaff3e0105f5bbc223a787a3e878f81ab2b29b680edd45ef2096bdba9500
MD5 91c736d0f6a0833d663d5d8c45aed093
BLAKE2b-256 5bf5f90b4b6df7735849299b053eca3945849c9d4ed240a9aa85ec0e99377473

See more details on using hashes here.

File details

Details for the file sdf_loss-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sdf_loss-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for sdf_loss-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb561b62cf5a1e6329b66b83b3a1ec41bbef34ac77f1df18fce2b7785af212b5
MD5 52d17ab9b8bab581c09669b30a0d4dc8
BLAKE2b-256 d56e68fd9c4a0d98962dcfe83eb1aaeb8f7861f8587a318011f1879b3d65e07c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page