def valid(args, model, writer, test_loader, global_step):
    '\n    :param args: 参数Config\n    :param model:  需验证模型\n    :param writer:  TB写入\n    :param test_loader:  测试数据集\n    :param global_step:  全局step\n    :return:\n    '
    eval_losses = AverageMeter()
    model.eval()
    (all_preds, all_label) = ([], [])
    epoch_iterator = tqdm(test_loader, desc='Validating... (loss=X.X)', bar_format='{l_bar}{r_bar}', dynamic_ncols=True)
    loss_fct = torch.nn.CrossEntropyLoss()
    global_eval_step = 0
    for (step, batch) in enumerate(epoch_iterator):
        global_eval_step += 1
        batch = tuple((t.to(args.device) for t in batch))
        (x, y) = batch
        with torch.no_grad():
            logits = model(x)[0]
            eval_loss = loss_fct(logits, y)
            eval_losses.update(eval_loss.item())
            preds = torch.argmax(logits, dim=(- 1))
        if (len(all_preds) == 0):
            all_preds.append(preds.detach().cpu().numpy())
            all_label.append(y.detach().cpu().numpy())
        else:
            all_preds[0] = np.append(all_preds[0], preds.detach().cpu().numpy(), axis=0)
            all_label[0] = np.append(all_label[0], y.detach().cpu().numpy(), axis=0)
        epoch_iterator.set_description(('Validating... (loss=%2.5f)' % eval_losses.val))
        writer.add_scalar('Train/loss', scalar_value=eval_losses.val, global_step=global_eval_step)
    (all_preds, all_label) = (all_preds[0], all_label[0])
    accuracy = simple_accuracy(all_preds, all_label)
    writer.add_scalar('test/accuracy', scalar_value=accuracy, global_step=global_step)
    return accuracy
:param args: 参数Config
:param model:  需验证模型
:param writer:  TB写入
:param test_loader:  测试数据集
:param global_step:  全局step
:return:
def valid(args, model, writer, test_loader, global_step):
    '\n    :param args: 参数Config\n    :param model:  需验证模型\n    :param writer:  TB写入\n    :param test_loader:  测试数据集\n    :param global_step:  全局step\n    :return:\n    '
    eval_losses = AverageMeter()
    model.eval()
    (all_preds, all_label) = ([], [])
    epoch_iterator = tqdm(test_loader, desc='Validating... (loss=X.X)', bar_format='{l_bar}{r_bar}', dynamic_ncols=True)
    loss_fct = torch.nn.CrossEntropyLoss()
    global_eval_step = 0
    for (step, batch) in enumerate(epoch_iterator):
        global_eval_step += 1
        batch = tuple((t.to(args.device) for t in batch))
        (x, y) = batch
        with torch.no_grad():
            logits = model(x)[0]
            eval_loss = loss_fct(logits, y)
            eval_losses.update(eval_loss.item())
            preds = torch.argmax(logits, dim=(- 1))
        if (len(all_preds) == 0):
            all_preds.append(preds.detach().cpu().numpy())
            all_label.append(y.detach().cpu().numpy())
        else:
            all_preds[0] = np.append(all_preds[0], preds.detach().cpu().numpy(), axis=0)
            all_label[0] = np.append(all_label[0], y.detach().cpu().numpy(), axis=0)
        epoch_iterator.set_description(('Validating... (loss=%2.5f)' % eval_losses.val))
        writer.add_scalar('Train/loss', scalar_value=eval_losses.val, global_step=global_eval_step)
    (all_preds, all_label) = (all_preds[0], all_label[0])
    accuracy = simple_accuracy(all_preds, all_label)
    writer.add_scalar('test/accuracy', scalar_value=accuracy, global_step=global_step)
    return accuracy