MCPcopy Index your code
hub / github.com/ActiveVisionLab/DFNet / feature_loss

Function feature_loss

script/feature/direct_feature_matching.py:114–136  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

112 return tensor
113
114def 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
138def PoseLoss(args, pose_, pose, device):
139 loss_func = nn.MSELoss()

Callers 2

train_on_feature_batchFunction · 0.85
train_on_batchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected