CoinCheung / pytorch-loss

label-smooth, amsoftmax, partial-fc, focal-loss, triplet-loss, lovasz-softmax. Maybe useful
MIT License
2.17k stars 374 forks source link

How do I design my loss fuction like smoothL1? #3

Closed kelisiya closed 3 years ago

kelisiya commented 4 years ago

I want to design a loss fuction when GT is [0,1] use L2 loss ;[0-1] use L1 loss ; How to achieve it use pytorch? Thanks

CoinCheung commented 4 years ago

I have not seen loss like that, maybe you can implement that directly with pytorch operators.

kelisiya commented 4 years ago

yes, I want to  design a loss use pytorch , but I don't know how to deal when value is 0 or 1 and 0-1 ; I think it's like smoothL1,but I  use pytorch unskilled.

CoinCheung commented 4 years ago

Maybe you can try torch.where to switch between the two losses according to the input conditions.

kelisiya commented 4 years ago

Thanks your reply,but how to del 0 or 1 ? torch don't have logit or ? 

CoinCheung commented 4 years ago

what do you mean by "del 0 or 1" ?

kelisiya commented 4 years ago

Emmm,I want to use L1 loss in label=0 and label=1,use L2 loss in label =[0-1] like 0.5,i dont know how to use torch.where in label =0 and label =1

 ---Original--- From: "CoinCheung"<notifications@github.com> Date: Wed, Jan 8, 2020 19:25 PM To: "CoinCheung/pytorch-loss"<pytorch-loss@noreply.github.com>; Cc: "kelisiya"<402124496@qq.com>;"Author"<author@noreply.github.com>; Subject: Re: [CoinCheung/pytorch-loss] How do I design my loss fuction like smoothL1? (#3)

what do you mean by "del 0 or 1" ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

CoinCheung commented 4 years ago

As far as I know, we do not need to consider single points when we compute loss in practice. You need continuous loss funtions to compute the gradient, it will not be meaningful if your loss function has singular points that cannot compute the graident.

kelisiya commented 4 years ago

《A Late Fusion CNN for Digital Matting》,http://openaccess.thecvf.com/content_CVPR_2019/papers/Zhang_A_Late_Fusion_CNN_for_Digital_Matting_CVPR_2019_paper.pdfthe&nbsp;formula <4>