code: def main():
      args = parser.parse_args()
  
      if not args.checkpoint and not args.pretrained:
          args.pretrained = True
  
      amp_autocast = suppress  # do nothing
      if args.amp:
          if not has_native_amp:
              print(
                  "Native Torch AMP is not available (requires torch >= 1.6), using FP32."
              )
          else:
              amp_autocast = torch.cuda.amp.autocast
  
      # create model
      model = geffnet.create_model(
          args.model,
          num_classes=args.num_classes,
          in_chans=3,
          pretrained=args.pretrained,
          checkpoint_path=args.checkpoint,
          scriptable=args.torchscript,
      )
  
      if args.channels_last:
          model = model.to(memory_format=torch.channels_last)
  
      if args.torchscript:
          torch.jit.optimized_execution(True)
          model = torch.jit.script(model)
  
      print(
          "Model %s created, param count: %d"
          % (args.model, sum([m.numel() for m in model.parameters()]))
      )
  
      data_config = resolve_data_config(model, args)
  
      criterion = nn.CrossEntropyLoss()
  
      if not args.no_cuda:
          if args.num_gpu > 1:
              model = torch.nn.DataParallel(
                  model, device_ids=list(range(args.num_gpu))
              ).cuda()
          else:
              model = model.cuda()
          criterion = criterion.cuda()
  
      loader = create_loader(
          Dataset(args.data, load_bytes=args.tf_preprocessing),
          input_size=data_config["input_size"],
          batch_size=args.batch_size,
          use_prefetcher=not args.no_cuda,
          interpolation=data_config["interpolation"],
          mean=data_config["mean"],
          std=data_config["std"],
          num_workers=args.workers,
          crop_pct=data_config["crop_pct"],
          tensorflow_preprocessing=args.tf_preprocessing,
      )
  
      batch_time = AverageMeter()
      losses = AverageMeter()
      top1 = AverageMeter()
      top5 = AverageMeter()
  
      model.eval()
      end = time.time()
      with torch.no_grad():
          for i, (input, target) in enumerate(loader):
              if not args.no_cuda:
                  target = target.cuda()
                  input = input.cuda()
              if args.channels_last:
                  input = input.contiguous(
                      memory_format=torch.channels_last
                  )
  
              # compute output
              with amp_autocast():
                  output = model(input)
                  loss = criterion(output, target)
  
              # measure accuracy and record loss
              prec1, prec5 = accuracy(output.data, target, topk=(1, 5))
              losses.update(loss.item(), input.size(0))
              top1.update(prec1.item(), input.size(0))
              top5.update(prec5.item(), input.size(0))
  
              # measure elapsed time
              batch_time.update(time.time() - end)
              end = time.time()
  
              if i % args.print_freq == 0:
                  print(
                      "Test: [{0}/{1}]\t"
                      "Time {batch_time.val:.3f} ({batch_time.avg:.3f}, {rate_avg:.3f}/s) \t"
                      "Loss {loss.val:.4f} ({loss.avg:.4f})\t"
                      "Prec@1 {top1.val:.3f} ({top1.avg:.3f})\t"
                      "Prec@5 {top5.val:.3f} ({top5.avg:.3f})".format(
                          i,
                          len(loader),
                          batch_time=batch_time,
                          rate_avg=input.size(0) / batch_time.avg,
                          loss=losses,
                          top1=top1,
                          top5=top5,
                      )
                  )
  
      print(
          " * Prec@1 {top1.avg:.3f} ({top1a:.3f}) Prec@5 {top5.avg:.3f} ({top5a:.3f})".format(
              top1=top1,
              top1a=100 - top1.avg,
              top5=top5,
              top5a=100.0 - top5.avg,
          )
      )
  
file_path: gen-efficientnet-pytorch/validate.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import argparse
  import time
  import torch
  import torch.nn
  import torch.nn.parallel
  from contextlib import suppress
  import geffnet
  from data import Dataset, create_loader, resolve_data_config
  from utils import accuracy, AverageMeter
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types