def validation(self, epoch, lr, *args, **kwargs):
    val_stats = Statistics()
    self.mi_model.eval()
    num_samples = len(self.val_loader)
    with torch.no_grad():
        epoch_start_time = time.time()
        for (batch_id, batch) in enumerate(self.val_loader):
            (words, true_diag_labels) = batch
            true_diag_labels = true_diag_labels.to(device=self.device)
            pred_diag_labels = prediction(words=words, cnn_model=self.base_feature_extractor, mi_model=self.mi_model, max_bsz_cnn_gpu0=self.max_bsz_cnn_gpu0, num_gpus=self.num_gpus, device=self.device)
            loss = self.criteria(pred_diag_labels, true_diag_labels)
            top1_acc = accuracy(pred_diag_labels, true_diag_labels, topk=(1,))
            val_stats.update(loss=loss.item(), acc=top1_acc[0].item())
            if (((batch_id % self.opts.log_interval) == 0) and (batch_id > 0)):
                val_stats.output(epoch=epoch, batch=batch_id, n_batches=num_samples, start=epoch_start_time, lr=lr)
    gc.collect()
    avg_acc = val_stats.avg_acc()
    avg_loss = val_stats.avg_loss()
    print_log_message('* Validation Stats')
    print_log_message('* Loss: {:5.2f}, Mean Acc: {:3.2f}'.format(avg_loss, avg_acc))
    return (avg_acc, avg_loss)
def validation(self, epoch, lr, *args, **kwargs):
    val_stats = Statistics()
    self.mi_model.eval()
    num_samples = len(self.val_loader)
    with torch.no_grad():
        epoch_start_time = time.time()
        for (batch_id, batch) in enumerate(self.val_loader):
            (words, true_diag_labels) = batch
            true_diag_labels = true_diag_labels.to(device=self.device)
            pred_diag_labels = prediction(words=words, cnn_model=self.base_feature_extractor, mi_model=self.mi_model, max_bsz_cnn_gpu0=self.max_bsz_cnn_gpu0, num_gpus=self.num_gpus, device=self.device)
            loss = self.criteria(pred_diag_labels, true_diag_labels)
            top1_acc = accuracy(pred_diag_labels, true_diag_labels, topk=(1,))
            val_stats.update(loss=loss.item(), acc=top1_acc[0].item())
            if (((batch_id % self.opts.log_interval) == 0) and (batch_id > 0)):
                val_stats.output(epoch=epoch, batch=batch_id, n_batches=num_samples, start=epoch_start_time, lr=lr)
    gc.collect()
    avg_acc = val_stats.avg_acc()
    avg_loss = val_stats.avg_loss()
    print_log_message('* Validation Stats')
    print_log_message('* Loss: {:5.2f}, Mean Acc: {:3.2f}'.format(avg_loss, avg_acc))
    return (avg_acc, avg_loss)