Comments (1)
ok, I've analyzed this error. It is because MixupCutmix occasionally transforms the targets tensor into soft one-hot encoding , whereas the current FocalLoss and SmoothCE requires argmax labels.
For FocalLoss it can be easily fixed by this:
class FocalLoss(nn.Module):
def forward(self, outputs: Dict[str, Any], batch: Dict[str, Any], device: torch.device):
outputs = outputs['outputs']
targets = move_to(batch['targets'], device)
num_classes = outputs.shape[-1]
# Need to be one hot encoding
if outputs.shape != targets.shape:
targets = nn.functional.one_hot(targets, num_classes=num_classes)
targets = targets.float().squeeze()
loss = sigmoid_focal_loss(outputs, targets, self.alpha, self.gamma, self.reduction)
loss_dict = {"L": loss.item()}
return loss, loss_dict
For SmoothCE, timm has SoftTargetCrossEntropy
class which is suitable for soft one-hot encoding:
from timm.loss import LabelSmoothingCrossEntropy, SoftTargetCrossEntropy
class SmoothCELoss(nn.Module):
def __init__(self, smoothing: float=0.1, **kwargs):
super(SmoothCELoss, self).__init__(**kwargs)
self.smooth_criterion = LabelSmoothingCrossEntropy()
self.soft_criterion = SoftTargetCrossEntropy()
def forward(self, outputs: Dict[str, Any], batch: Dict[str, Any], device: torch.device):
pred = outputs['outputs']
target = move_to(batch["targets"], device)
if pred.shape == target.shape:
loss = self.soft_criterion(pred, target)
else:
loss = self.smooth_criterion(pred, target.view(-1).contiguous())
loss_dict = {"CE": loss.item()}
return loss, loss_dict
I will make a PR and you can test it out
from theseus.
Related Issues (14)
- Happy Birthday HOT 1
- Question on Segmentation task? HOT 4
- Implement independent Callbacks class HOT 3
- Better logging system HOT 1
- ValueError: Expected x_max/y_max for bbox to be in the range [0.0, 1.0]
- Hyperparamter tuning HOT 1
- To be A+ rank (or highest) on CodeFactor and beyond HOT 5
- Resume error in WandB. HOT 2
- Possible issue with trainer HOT 1
- Multiprocessing
- Add rename for download_from_wandb HOT 2
- About master branch and detection branch HOT 2
- [Wanted] Use Observer pattern for logging
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from theseus.