Compute Feature MSE Loss :param: feature_rgb, [C,H,W] or [C, N_rand] :param: feature_target, [C,H,W] or [C, N_rand] :param: img_in, True: input is feature maps, False: input is rays :param: random, True: randomly using per pixel or per channel cossimilarity loss
(feature_rgb, feature_target, img_in=True, per_channel=False)
| 112 | return tensor |
| 113 | |
| 114 | def feature_loss(feature_rgb, feature_target, img_in=True, per_channel=False): |
| 115 | ''' Compute Feature MSE Loss |
| 116 | :param: feature_rgb, [C,H,W] or [C, N_rand] |
| 117 | :param: feature_target, [C,H,W] or [C, N_rand] |
| 118 | :param: img_in, True: input is feature maps, False: input is rays |
| 119 | :param: random, True: randomly using per pixel or per channel cossimilarity loss |
| 120 | ''' |
| 121 | if img_in: |
| 122 | C,H,W = feature_rgb.size() |
| 123 | fr = feature_rgb.reshape(C, H*W) |
| 124 | ft = feature_target.reshape(C, H*W) |
| 125 | else: |
| 126 | fr = feature_rgb |
| 127 | ft = feature_target |
| 128 | |
| 129 | # cosine loss |
| 130 | if per_channel: |
| 131 | cos = torch.nn.CosineSimilarity(dim=0, eps=1e-6) |
| 132 | else: |
| 133 | cos = torch.nn.CosineSimilarity(dim=1, eps=1e-6) |
| 134 | loss = 1 - cos(fr, ft).mean() |
| 135 | |
| 136 | return loss |
| 137 | |
| 138 | def PoseLoss(args, pose_, pose, device): |
| 139 | loss_func = nn.MSELoss() |
no outgoing calls
no test coverage detected