def _project(self): input_shape = self._input_shape print("===Projecting===") for i in range(self.num_projections): if self.orthogonal: # project onto orthogonal convolution kernel space self.weight.data = torch.from_numpy( conv_clip_2_norm_numpy(self.weight.data.cpu().numpy(), (self.weight.size(-2) * 2 - 1, self.weight.size(-1) * 2 - 1), clip_to=1, force_same=True)).to( device=self.weight.device, dtype=self.weight.dtype) else: # project onto 1-Lipschitz convolution kernel space self.weight.data = torch.from_numpy( conv_clip_2_norm_numpy(self.weight.data.cpu().numpy(), input_shape, clip_to=1)).to( device=self.weight.device, dtype=self.weight.dtype) self.svs = torch.from_numpy( conv_singular_values_numpy(self.weight.data.cpu().numpy(), input_shape)) print("Projection Result: {}".format(self.lipschitz_constant())) print("===Finished===")
def singular_values(self): svs = torch.from_numpy( conv_singular_values_numpy( self.buffer_weight.detach().cpu().numpy(), self._input_shape ) ).to(device=self.buffer_weight.device) return svs
def singular_values(self): # Implements interface required by LipschitzModuleL2 svs = torch.from_numpy( conv_singular_values_numpy( self.buffer_weight.detach().cpu().numpy(), self._input_shape ) ).to(device=self.buffer_weight.device) return svs
def singular_values(self): return torch.from_numpy( conv_singular_values_numpy(self.weight.data.cpu().numpy(), self._input_shape))