def test_on_batch(self, batch_ind, batch): logSoftmax = nn.LogSoftmax() outdir = os.path.join(self.output_dir, 'batch%04d' % batch_ind) os.makedirs(outdir, exist_ok=True) self.net_q.eval() self.net_c.eval() # read in X X_list = [None] * self.n_modality for i in range(self.n_modality): X_list[i] = batch[self.modality[i]] X_list[i] = X_list[i].view(X_list[i].shape[0], -1) X_list = [tmp.cuda() for tmp in X_list] # Concatenate X before feeding into Autoencoder X = torch.cat(X_list, dim=1).cuda() y = batch['labels'].cuda() with torch.no_grad(): z = self.net_q(X) pred_logits = self.net_c(z) pred_prob = logSoftmax(pred_logits) eva = reportMetricsMultiClass(y, pred_prob) formatTable(eva, outpath=os.path.join(outdir, 'eva.csv')) output = self.pack_output(pred_prob, batch) np.savez(os.path.join(outdir, 'batch%04d.npz' % batch_ind), **output)
def test_on_batch(self, batch_ind, batch): logSoftmax = nn.LogSoftmax() outdir = os.path.join(self.output_dir, 'batch%04d' % batch_ind) os.makedirs(outdir, exist_ok=True) for i in range(self.n_modality): self.net_q[i].eval() self.net_c.eval() X_list = [None] * self.n_modality z_list = [None] * self.n_modality # read in training data for i in range(self.n_modality): X_list[i] = batch[self.modality[i]] X_list[i] = X_list[i].view(X_list[i].shape[0], -1) X_list = [tmp.cuda() for tmp in X_list] y = batch['labels'].cuda() with torch.no_grad(): for i in range(self.n_modality): z_list[i] = self.net_q[i](X_list[i]) z_combined = torch.cat(z_list, dim=1) pred_logits = self.net_c(z_combined) pred_prob = logSoftmax(pred_logits) eva = reportMetricsMultiClass(y, pred_prob) formatTable(eva, outpath=os.path.join(outdir, 'eva.csv')) output = self.pack_output(pred_prob, batch, z_list) np.savez(os.path.join(outdir, 'batch%04d.npz' % batch_ind), **output)
def test_on_batch(self, batch_ind, batch): logSoftmax = nn.LogSoftmax() outdir = os.path.join(self.output_dir, 'batch%04d' % batch_ind) os.makedirs(outdir, exist_ok=True) self.net_q.eval() self.net_c.eval() X = batch[self.modality].cuda() X = X.view(X.shape[0], -1) y = batch['labels'].cuda() with torch.no_grad(): z = self.net_q(X) pred_logits = self.net_c(z) pred_prob = logSoftmax(pred_logits) eva = reportMetricsMultiClass(y, pred_prob) formatTable(eva, outpath=os.path.join(outdir, 'eva.csv')) output = self.pack_output(pred_prob, batch) np.savez(os.path.join(outdir, 'batch%04d.npz' % batch_ind), **output)