
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
unified-focal-loss-pytorch
Advanced tools
An implementation of loss functions from "Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medical image segmentation"
An implementation of loss functions from “Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medical image segmentation”
Extended for multiclass classification and to allow passing an ignore index.
Note: This implementation is not tested against the original implementation. It varies from the original implementation based on my own interpretation of the paper.
pip install unified-focal-loss-pytorch
import torch
import torch.nn.functional as F
from unified_focal_loss import AsymmetricUnifiedFocalLoss
loss_fn = AsymmetricUnifiedFocalLoss(
delta=0.7,
gamma=0.5,
ignore_index=2,
)
logits = torch.tensor([
[[0.1000, 0.4000],
[0.2000, 0.5000],
[0.3000, 0.6000]],
[[0.7000, 0.0000],
[0.8000, 0.1000],
[0.9000, 0.2000]]
])
# Shape should be (batch_size, num_classes, ...)
probs = F.softmax(logits, dim=1)
# Shape should be (batch_size, ...). Not one-hot encoded.
targets = torch.tensor([
[0, 1],
[2, 0],
])
loss = loss_fn(probs, targets)
print(loss)
# >>> tensor(0.6737)
See API docs.
See LICENSE.
FAQs
An implementation of loss functions from "Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medical image segmentation"
We found that unified-focal-loss-pytorch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.