Equation 13 in the NeRF-W paper. Name abbreviations: c_l: coarse color loss f_l: fine color loss (1st term in equation 13) b_l: beta loss (2nd term in equation 13) s_l: sigma loss (3rd term in equation 13) targets # [N, 3] inputs['rgb_coarse'] # [N, 3
| 17 | |
| 18 | |
| 19 | class NerfWLoss(nn.Module): |
| 20 | """ |
| 21 | Equation 13 in the NeRF-W paper. |
| 22 | Name abbreviations: |
| 23 | c_l: coarse color loss |
| 24 | f_l: fine color loss (1st term in equation 13) |
| 25 | b_l: beta loss (2nd term in equation 13) |
| 26 | s_l: sigma loss (3rd term in equation 13) |
| 27 | targets # [N, 3] |
| 28 | inputs['rgb_coarse'] # [N, 3] |
| 29 | inputs['rgb_fine'] # [N, 3] |
| 30 | inputs['beta'] # [N] |
| 31 | inputs['transient_sigmas'] # [N, 2*N_Samples] |
| 32 | :return: |
| 33 | """ |
| 34 | def __init__(self, coef=1, lambda_u=0.01): |
| 35 | """ |
| 36 | lambda_u: in equation 13 |
| 37 | """ |
| 38 | super().__init__() |
| 39 | self.coef = coef |
| 40 | self.lambda_u = lambda_u |
| 41 | |
| 42 | def forward(self, inputs, targets, use_hier_rgbs=False, rgb_h=None, rgb_w=None): |
| 43 | |
| 44 | ret = {} |
| 45 | ret['c_l'] = 0.5 * ((inputs['rgb_coarse']-targets)**2).mean() |
| 46 | if 'rgb_fine' in inputs: |
| 47 | if 'beta' not in inputs: # no transient head, normal MSE loss |
| 48 | ret['f_l'] = 0.5 * ((inputs['rgb_fine']-targets)**2).mean() |
| 49 | else: |
| 50 | ret['f_l'] = ((inputs['rgb_fine']-targets)**2/(2*inputs['beta'].unsqueeze(1)**2)).mean() |
| 51 | ret['b_l'] = 3 + torch.log(inputs['beta']).mean() # +3 to make it positive |
| 52 | ret['s_l'] = self.lambda_u * inputs['transient_sigmas'].mean() |
| 53 | |
| 54 | for k, v in ret.items(): |
| 55 | ret[k] = self.coef * v |
| 56 | |
| 57 | return ret |
| 58 | |
| 59 | loss_dict = {'color': ColorLoss, |
| 60 | 'nerfw': NerfWLoss} |
nothing calls this directly
no outgoing calls
no test coverage detected