MCPcopy Create free account
hub / github.com/ActiveVisionLab/DFNet / normalize_features

Function normalize_features

script/feature/direct_feature_matching.py:102–112  ·  view source on GitHub ↗

Find unit norm of channel wise feature :param: tensor, img tensor (C,H,W)

(tensor, value_range=None, scale_each: bool = False)

Source from the content-addressed store, hash-verified

100 return loss
101
102def normalize_features(tensor, value_range=None, scale_each: bool = False):
103 ''' Find unit norm of channel wise feature
104 :param: tensor, img tensor (C,H,W)
105 '''
106 tensor = tensor.clone() # avoid modifying tensor in-place
107 C,H,W = tensor.size()
108
109 # normlaize the features with l2 norm
110 tensor = tensor.reshape(C, H*W)
111 tensor = torch.nn.functional.normalize(tensor)
112 return tensor
113
114def feature_loss(feature_rgb, feature_target, img_in=True, per_channel=False):
115 ''' Compute Feature MSE Loss

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected