Coder Social home page Coder Social logo

About the loss calculation about yolov3_pytorch HOT 2 OPEN

bobliu20 avatar bobliu20 commented on June 29, 2024 1
About the loss calculation

from yolov3_pytorch.

Comments (2)

GNAYUOHZ avatar GNAYUOHZ commented on June 29, 2024

Hi, do you test it? can you tell me the result? Thank you

from yolov3_pytorch.

chrisway613 avatar chrisway613 commented on June 29, 2024

Maybe I think you could set

        self.mse_loss = nn.MSELoss()
        self.bce_loss = nn.BCELoss()

to

        self.mse_loss = nn.MSELoss(size_average=False)
        self.bce_loss = nn.BCELoss(size_average=False)

and then calculate losses like this way:

        n_mask = torch.sum(mask)
        n_noobj_mask = torch.sum(noobj_mask)

        loss_x = self.bce_loss(x * mask, tx * mask) / n_mask
        loss_y = self.bce_loss(y * mask, ty * mask) / n_mask
        loss_w = self.mse_loss(w * mask, tw * mask) / n_mask
        loss_h = self.mse_loss(h * mask, th * mask) / n_mask
        loss_conf = self.bce_loss(conf * mask, 1.0 * mask) / n_mask + \
            0.5 * self.bce_loss(conf * noobj_mask, 0.0 * noobj_mask) / n_noobj_mask
        loss_cls = self.bce_loss(pred_cls[mask == 1], tcls[mask == 1]) / n_mask

I think maybe also add the condition when n_mask is zero:
if n_mask:
....
else:
loss_x = torch.zeros(1).cuda()
loss_y = torch.zeros(1).cuda()
loss_w = torch.zeros(1).cuda()
loss_h = torch.zeros(1).cuda()
loss_conf = self.lambda_conf * .5 * self.bce_loss(pred_conf * noobj_mask, noobj_mask * 0.) / n_noobj
loss_cls = torch.zeros(1).cuda()

from yolov3_pytorch.

Related Issues (20)

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.