Skip to content

Instantly share code, notes, and snippets.

View V0xP0p's full-sized avatar
🏠
Working from home

Dimitris Karatasios V0xP0p

🏠
Working from home
View GitHub Profile
@f1recracker
f1recracker / focal_loss.py
Last active September 3, 2023 09:11
PyTorch implementation of focal loss that is drop-in compatible with torch.nn.CrossEntropyLoss
# pylint: disable=arguments-differ
import torch
import torch.nn as nn
import torch.nn.functional as F
class FocalLoss(nn.CrossEntropyLoss):
''' Focal loss for classification tasks on imbalanced datasets '''