question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the equivalent of Adaptive class weight layer in the original article? The output of this layer should be the input of the softmax here: pred = torch.softmax(logits, dim=1) but none treatment were made for this input.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CoinCheungcommented, Apr 21, 2020

I have just thought of that, if I have not misunderstood what ACW does, it seems that when the logits output of the model is a [N, M] tensor(N samples and each sample has M output values as logits of each class), ACW provides a weight vector of shape [1, M] that should be multiplied into the logits of each sample as the learned remedy for the knowledge learned from the unbalanced dataset. For each row of the [N, M] logits tensor, the weight vector is multiplied to it elementwisely, which I thought should be similar behavior of depthwise convolutions. For example, your model structure might be like this:

class Model(nn.Module):

    def __init__(self):
        self.backbone = some_fcn()
        self.acw = nn.Conv2d(in_chan, out_chan, 1, 1, 0, groups=in_chan)
        self.criteria = dual_focal_loss()

    def forward(self, x):
        feat = self.backbone(x)
        avg_pool = torch.mean(feat, dim=(2,3), keepdim=True)
        logits = self.acw(avg_pool)
        if self.training:
            out = self.criteria(logits)
        else:
            out = avg_pool
        return out

This nn.Conv2d with groups as same as input channels should act similarly as the acw layer.

1reaction
CoinCheungcommented, Apr 19, 2020

Hi, I have no idea if you are still interested in implementing acw layer, but I have just thought that maybe you can use a 1x1 depth-wise convolution layer following the logits, which should work in the same way as the acw layer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dual Focal Loss to address class imbalance in semantic ...
This paper has proposed a novel Dual Focal Loss (DFL) function to address the class imbalance and class weakness problems of semantic ...
Read more >
Dual Focal Loss (DFL) - File Exchange - MATLAB Central
Dual Focal Loss (DFL) function [1] alleviates the class imbalance issue in classification as well as semantic segmentation.
Read more >
Dual Focal Loss to address class imbalance in semantic ...
Focal Loss has proven to be effective at loss balancing by ... In this paper, a novel Dual Focal Loss (DFL) function is...
Read more >
Dual Focal Loss to address class imbalance in semantic ...
This article explores the plethora of traditional machine learning approaches aiming to mitigate the adversarial effects of class imbalance ...
Read more >
[1909.11932] Adaptive Class Weight based Dual Focal Loss ...
In this paper, we propose a Dual Focal Loss (DFL) function, as a replacement for the standard cross entropy (CE) function to achieve...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found