Code Monkey home page Code Monkey logo

droploss's People

Contributors

e-271 avatar timy90022 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

droploss's Issues

About the implementation of eq(6)

Hi @timy90022 ๏ผŒ
Thanks for sharing your excellent work.
When I try to understand the implementation of Eq(6), I find a bit difference between the implementation and the Eq(6) in the paper.

 def exclude_func_and_ratio(self):
        # instance-level weight
        bg_ind = self.n_c
        weight = (self.gt_classes != bg_ind)

        gt_classes    = self.gt_classes[weight]
        # exclude_ratio = \mu_{f_j}}
        exclude_ratio = torch.mean((self.freq_info[gt_classes] < self.lambda_).float())
        # weight = E(r)
        weight = weight.float().view(self.n_i, 1).expand(self.n_i, self.n_c)

        return weight, exclude_ratio


    def threshold_func(self):
        # class-level weight
        weight = self.pred_class_logits.new_zeros(self.n_c)
        # weight = T_{lambda}(f_j)
        weight[self.freq_info < self.lambda_] = 1
        weight = weight.view(1, self.n_c).expand(self.n_i, self.n_c)

        # fg = E(r)
        # ratio = \mu_{f_j}
        fg, ratio = self.exclude_func_and_ratio()
        # bg =  1 - E(r)
        bg = 1 - fg
        # random = (1-E(r)) * rand
        random = torch.rand_like(bg) * bg

        random = torch.where(random>ratio, torch.ones_like(random), torch.zeros_like(random))
        # weight = { [ (1-E(r)) * rand > \mu_{f_j} ? 1 : 0 ] + E(r) } * T_{\lambda}(f_j)
        weight = (random + fg) * weight

        return weight


    def drop_loss(self):

        self.n_i, self.n_c = self.pred_class_logits.size()

        def expand_label(pred, gt_classes):
            target = pred.new_zeros(self.n_i, self.n_c + 1)
            target[torch.arange(self.n_i), gt_classes] = 1
            return target[:, :self.n_c]

        target = expand_label(self.pred_class_logits, self.gt_classes)
        # drop_w =  1 - { [ (1-E(r)) * rand > \mu_{f_j} ? 1 : 0 ] + E(r) } * T_{\lambda}(f_j) * (1-y_j)
        # When E(r) = 1, drop_w = 1 - T_{\lambda}(f_j) * (1-y_j)
        # When E(r) = 0, drop_w = 1 - { [ (1-E(r)) * rand > \mu_{f_j} ? 1 : 0 ] } * T_{\lambda}(f_j) * (1-y_j) ????
                        # when rand > \mu_{f_j}, drop_w = 1 - T_{\lambda}(f_j) * (1-y_j)
                        # when rand <= \mu_{f_j}, drop_w = 1
        self.drop_w = 1 - self.threshold_func() * (1 - target)

        self.cls_loss = F.binary_cross_entropy_with_logits(self.pred_class_logits, target,
                                                      reduction='none')
        return torch.sum(self.cls_loss * self.drop_w) / self.n_i
# When E(r) = 0, drop_w = 1 - [ rand > \mu_{f_j} ? 1 : 0 ] *  T_{\lambda}(f_j) * (1-y_j) 
# when rand > \mu_{f_j}, drop_w = 1 - T_{\lambda}(f_j) * (1-y_j)???????
# when rand <= \mu_{f_j}, drop_w = 1

The implementation is inconsistent with the otherwise condition in Eq(6) .

drop_w = 1 - T_{\lambda}(f_j) * (1-y_j)

Could you please explain that?
Is there any misunderstanding about the code?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.