def validate(epoch):
    model.eval()
    top1 = AverageMeter()
    top5 = AverageMeter()
    global best_pred, acclist_train, acclist_val
    is_best = False
    for (batch_idx, (data, target)) in enumerate(val_loader):
        (data, target) = (data.cuda(args.gpu), target.cuda(args.gpu))
        with torch.no_grad():
            output = model(data)
            (acc1, acc5) = accuracy(output, target, topk=(1, 5))
            top1.update(acc1[0], data.size(0))
            top5.update(acc5[0], data.size(0))
    (sum1, cnt1, sum5, cnt5) = torch_dist_sum(args.gpu, top1.sum, top1.count, top5.sum, top5.count)
    if args.eval:
        if (args.gpu == 0):
            top1_acc = (sum(sum1) / sum(cnt1))
            top5_acc = (sum(sum5) / sum(cnt5))
            print(('Validation: Top1: %.3f | Top5: %.3f' % (top1_acc, top5_acc)))
        return
    if (args.gpu == 0):
        top1_acc = (sum(sum1) / sum(cnt1))
        top5_acc = (sum(sum5) / sum(cnt5))
        print(('Validation: Top1: %.3f | Top5: %.3f' % (top1_acc, top5_acc)))
        acclist_val += [top1_acc]
        if (top1_acc > best_pred):
            best_pred = top1_acc
            is_best = True
        state_dict = {'epoch': epoch, 'state_dict': model.module.state_dict(), 'optimizer': optimizer.state_dict(), 'best_pred': best_pred, 'acclist_train': acclist_train, 'acclist_val': acclist_val}
        if args.amp:
            state_dict['amp'] = amp.state_dict()
        encoding.utils.save_checkpoint(state_dict, args=args, is_best=is_best)
def validate(epoch):
    model.eval()
    top1 = AverageMeter()
    top5 = AverageMeter()
    global best_pred, acclist_train, acclist_val
    is_best = False
    for (batch_idx, (data, target)) in enumerate(val_loader):
        (data, target) = (data.cuda(args.gpu), target.cuda(args.gpu))
        with torch.no_grad():
            output = model(data)
            (acc1, acc5) = accuracy(output, target, topk=(1, 5))
            top1.update(acc1[0], data.size(0))
            top5.update(acc5[0], data.size(0))
    (sum1, cnt1, sum5, cnt5) = torch_dist_sum(args.gpu, top1.sum, top1.count, top5.sum, top5.count)
    if args.eval:
        if (args.gpu == 0):
            top1_acc = (sum(sum1) / sum(cnt1))
            top5_acc = (sum(sum5) / sum(cnt5))
            print(('Validation: Top1: %.3f | Top5: %.3f' % (top1_acc, top5_acc)))
        return
    if (args.gpu == 0):
        top1_acc = (sum(sum1) / sum(cnt1))
        top5_acc = (sum(sum5) / sum(cnt5))
        print(('Validation: Top1: %.3f | Top5: %.3f' % (top1_acc, top5_acc)))
        acclist_val += [top1_acc]
        if (top1_acc > best_pred):
            best_pred = top1_acc
            is_best = True
        state_dict = {'epoch': epoch, 'state_dict': model.module.state_dict(), 'optimizer': optimizer.state_dict(), 'best_pred': best_pred, 'acclist_train': acclist_train, 'acclist_val': acclist_val}
        if args.amp:
            state_dict['amp'] = amp.state_dict()
        encoding.utils.save_checkpoint(state_dict, args=args, is_best=is_best)