Metadata-Version: 2.4
Name: sdf-loss
Version: 0.1.1
Summary: Signed Distance Function based loss functions for deep learning semantic segmentation to miss fewer instances.
Author-email: Harald <harald.lykke.joakimsen@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Harald Lykke Joakimsen
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: deep learning,loss function,pytorch,sdf,semantic segmentation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: numpy>=1.20.0
Requires-Dist: scikit-image>=0.19.0
Requires-Dist: scipy>=1.7.0
Requires-Dist: torch>=1.10.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.14.7; extra == 'dev'
Description-Content-Type: text/markdown

# 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:

```bash
pip install sdf-loss
```

Or using uv:

```bash
uv add sdf-loss
```

## Quick Start

```python
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.
