Find unit norm of channel wise feature :param: tensor, img tensor (C,H,W)
(tensor, value_range=None, scale_each: bool = False)
| 100 | return loss |
| 101 | |
| 102 | def 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 | |
| 114 | def feature_loss(feature_rgb, feature_target, img_in=True, per_channel=False): |
| 115 | ''' Compute Feature MSE Loss |
nothing calls this directly
no outgoing calls
no test coverage detected