Skip to main content

A modular PyTorch loss function library with popular criteria for classification, regression, segmentation, and metric learning.

Project description

torchcriterion

torchcriterion is a modular, extensible library of PyTorch-compatible loss functions ("criteria") for classification, regression, segmentation, and metric learning tasks. It offers a curated collection of both standard and custom loss functions, built with flexibility and composability in mind.


🚀 Features

  • 🧱 Modular architecture for clean API and extension
  • 🧪 Ready-to-use implementations of popular losses
  • 🧩 Supports multi-loss composition and custom scheduling
  • ⚡ Fully compatible with PyTorch’s autograd and GPU acceleration

📦 Installation

pip install torchcriterion  # Coming soon to PyPI

🧰 Supported Losses

Classification

  • CrossEntropyLoss
  • FocalLoss

Regression

  • MSELoss
  • HuberLoss

Segmentation

  • DiceLoss
  • TverskyLoss

Metric Learning

  • TripletLoss
  • ContrastiveLoss

🧪 Example Usage

from torchcriterion import FocalLoss

criterion = FocalLoss(gamma=2.0, alpha=0.25)
loss = criterion(predictions, targets)

📁 Project Structure

torchcriterion/
├── classification/
│   ├── cross_entropy.py
│   ├── focal.py
├── regression/
│   ├── mse.py
│   ├── huber.py
├── segmentation/
│   ├── dice.py
│   ├── tversky.py
├── metric_learning/
│   ├── triplet.py
│   ├── contrastive.py
├── base.py
├── __init__.py

📜 License

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


🙌 Contributing

Pull requests, ideas, and issues are welcome! Feel free to open a PR or start a discussion.


👤 Author

Developed by TransformerTitan — @TransformerTitan


⭐️ Star the Repo

If you find this library useful, please consider starring it to show your support!


🔗 Related Projects

  • torchmetrics — for evaluation metrics
  • timm — for models with built-in loss support

Made with ❤️ and PyTorch

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

torchcriterion-0.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

torchcriterion-0.0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file torchcriterion-0.0.1.tar.gz.

File metadata

  • Download URL: torchcriterion-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.9

File hashes

Hashes for torchcriterion-0.0.1.tar.gz
Algorithm Hash digest
SHA256 59cc8ed6d877050b2c5d9230c276ba30afa11b9f4df3a4868259d8b5703d61ed
MD5 35f0ceab66dc45c54d57e2eb81ce127a
BLAKE2b-256 78898aceb3cc16a7b6e073ec5be752493a8f4daa1dfa8c3708cbd7ee1d0c5fa4

See more details on using hashes here.

File details

Details for the file torchcriterion-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: torchcriterion-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.9

File hashes

Hashes for torchcriterion-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b6ec1302148b6f33ef6d599bbfe43bae69eb15022f33f61a654486e9ee56a961
MD5 5105a3a48c3cf71fee6d057bd93f5b89
BLAKE2b-256 a3a4a2e64c277c94a6f4df9e45df579149476497c9653aebe1ec732c692c8128

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