def __call__(self, tensor): """ Args: tensor (Tensor): Tensor image of size (C, H, W) to be normalized. Returns: Tensor: Normalized image. """ return F.normalize(tensor, self.mean, self.std)
def forward(self, Z, return_y=False): expd = self.E(Z) comp = torch.stack([C(Z) for C in self.Cs]) clus, y_approx = self.nonlinear(comp) Z = Z + self.eta * (expd - clus) Z = F.normalize(Z) if return_y: return Z, y_approx return Z
def postprocess(self, X): return F.normalize(X)
def __call__(self, image, target): image = F.normalize(image, mean=self.mean, std=self.std) return image, target
def postprocess(self, X): Z = ifft2(X, norm='ortho', dim=(2, 3)) return F.normalize(Z).real
def preprocess(self, X): Z = F.normalize(X) return fft2(Z, norm='ortho', dim=(2, 3))
batch_size=args.batch_size, loss=args.loss, device=device) X_train, y_train, Z_train = F.to_cpu(X_train, y_train, Z_train) utils.save_loss(eval_dir, f'train', net.get_loss()) print('test') Z_test = net.batch_forward(X_test, batch_size=args.batch_size, loss=args.loss, device=device) X_test, y_test, Z_test = F.to_cpu(X_test, y_test, Z_test) utils.save_loss(eval_dir, f'test', net.get_loss()) ## Normalize X_train = F.normalize(X_train.flatten(1)) X_test = F.normalize(X_test.flatten(1)) Z_train = F.normalize(Z_train.flatten(1)) Z_test = F.normalize(Z_test.flatten(1)) # Evaluate evaluate.evaluate(eval_dir, 'knn', Z_train, y_train, Z_test, y_test) #evaluate.evaluate(eval_dir, 'nearsub', Z_train, y_train, Z_test, y_test, num_classes=num_classes, n_comp=10) # Plot plot.plot_loss_mcr(eval_dir, 'train') plot.plot_loss_mcr(eval_dir, 'test') plot.plot_heatmap(eval_dir, 'X_train', X_train, y_train, num_classes) plot.plot_heatmap(eval_dir, 'X_test', X_test, y_test, num_classes) plot.plot_heatmap(eval_dir, 'Z_train', Z_train, y_train, num_classes) plot.plot_heatmap(eval_dir, 'Z_test', Z_test, y_test, num_classes)