MCPcopy Create free account
hub / github.com/DIVE128/DMVSNet / binary_cross_entropy_with_logits

Function binary_cross_entropy_with_logits

loss.py:161–187  ·  view source on GitHub ↗
(input, target, weight=None, size_average=None,
                                     reduce=False, reduction='elementwise_mean', pos_weight=None,mask=None)

Source from the content-addressed store, hash-verified

159 return loss
160
161def binary_cross_entropy_with_logits(input, target, weight=None, size_average=None,
162 reduce=False, reduction='elementwise_mean', pos_weight=None,mask=None):
163
164 if not (target.size() == input.size()):
165 raise ValueError("Target size ({}) must be the same as input size ({})".format(target.size(), input.size()))
166
167 max_val = (-input).clamp(min=0)
168
169 if pos_weight is None:
170 ce_loss = input - input * target + max_val + ((-max_val).exp() + (-input - max_val).exp()).log()
171 else:
172 log_weight = 1 + (pos_weight - 1) * target
173 ce_loss = input - input * target + log_weight * (max_val + ((-max_val).exp() + (-input - max_val).exp()).log())
174
175
176 if weight is not None:
177 ce_loss = ce_loss * weight
178 if mask is not None:
179
180 ce_loss = ce_loss[mask.unsqueeze(1).repeat(1,ce_loss.shape[1],1,1)]
181
182 if reduction == False:
183 return ce_loss
184 elif reduction == 'elementwise_mean':
185 return ce_loss.mean()
186 else:
187 return ce_loss.sum()
188def classification_loss_1(prob_volume, depth_values, interval, depth_gt, mask, weight):
189 depth_gt_volume = depth_gt.unsqueeze(1).expand_as(depth_values) # (b, d, h, w)
190

Callers 1

classification_loss_1Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected