Python Packages
Collection
4 items
β’
Updated
β’
1
A lightweight library of advanced PyTorch loss functions β ready to plug into your training loop.
Designed for deep learning practitioners who want more than just MSE and CrossEntropy.
Available on PyPI: torchlosses
Naga Adithya Kaushik (GenAIDevTOProd) https://medium.com/@GenAIDevTOProd/from-loss-functions-to-training-utilities-building-pytorch-packages-from-scratch-91e884d14001
pip install torchlosses
## Usage
import torch
from torchlosses import FocalLoss, DiceLoss
# Focal Loss for classification
inputs = torch.randn(4, 5, requires_grad=True) # logits for 5 classes
targets = torch.randint(0, 5, (4,))
criterion = FocalLoss()
loss = criterion(inputs, targets)
print("Focal Loss:", loss.item())
# Dice Loss for segmentation
inputs = torch.randn(4, 1, 8, 8)
targets = torch.randint(0, 2, (4, 1, 8, 8))
criterion = DiceLoss()
loss = criterion(inputs, targets)
print("Dice Loss:", loss.item())