code: def validate(args):
      def val_loader_func(config, batch_size):
          # Data loading code
          invalidInputError(
              args.data is not None,
              "please set dataset path if you want to using real data",
          )
          valdir = os.path.join(args.data, "val")
          normalize = transforms.Normalize(
              mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
          )
          val_loader = torch.utils.data.DataLoader(
              datasets.ImageFolder(
                  valdir,
                  transforms.Compose(
                      [
                          transforms.Resize(256),
                          transforms.CenterCrop(224),
                          transforms.ToTensor(),
                          normalize,
                      ]
                  ),
              ),
              batch_size=batch_size,
              shuffle=False,
              num_workers=args.workers,
              pin_memory=True,
          )
          return val_loader
  
      def model_creator(config):
          if args.seed is not None:
              import random
  
              random.seed(args.seed)
              torch.manual_seed(args.seed)
          arch = "resnet50"
          if args.hub:
              torch.set_flush_denormal(True)
              model = torch.hub.load(
                  "facebookresearch/WSL-Images", arch
              )
          else:
              # create model
              if args.pretrained:
                  print("=> using pre-trained model '{}'".format(arch))
                  model = models.__dict__[arch](pretrained=True)
              else:
                  print("=> creating model '{}'".format(arch))
                  model = models.__dict__[arch]()
  
          if args.ipex:
              model.train(False)
              print("using ipex model to do inference\n")
              import intel_extension_for_pytorch as ipex
  
              if args.int8:
                  if not args.calibration:
                      from torch.ao.quantization import (
                          MinMaxObserver,
                          PerChannelMinMaxObserver,
                          QConfig,
                      )
  
                      x = torch.randn(
                          args.batch_size, 3, 224, 224
                      ).contiguous(memory_format=torch.channels_last)
                      qconfig = QConfig(
                          activation=MinMaxObserver.with_args(
                              qscheme=torch.per_tensor_symmetric,
                              dtype=torch.qint8,
                          ),
                          weight=PerChannelMinMaxObserver.with_args(
                              dtype=torch.qint8,
                              qscheme=torch.per_channel_symmetric,
                          ),
                      )
                      prepared_model = ipex.quantization.prepare(
                          model, qconfig, x, inplace=True
                      )
                      prepared_model.load_qconf_summary(
                          qconf_summary=args.configure_dir
                      )
                      model = ipex.quantization.convert(prepared_model)
                      model = torch.jit.trace(model, x)
                      model = torch.jit.freeze(model.train(False))
                      y = model(x)
                      print("running int8 evaluation step\n")
              else:
                  # for ipex path, always convert model to channels_last for bf16, fp32.
                  # TODO: int8 path: https://jira.devtools.intel.com/browse/MFDNN-6103
                  model = model.to(memory_format=torch.channels_last)
  
                  if args.bf32:
                      ipex.set_fp32_math_mode(
                          mode=ipex.FP32MathMode.BF32, device="cpu"
                      )
                      print("using bf32 fmath mode\n")
                  if args.bf16:
                      model = ipex.optimize(
                          model, dtype=torch.bfloat16, inplace=True
                      )
                      print("running bfloat16 evaluation step\n")
                  else:
                      model = ipex.optimize(
                          model, dtype=torch.float32, inplace=True
                      )
                      print("running fp32 evaluation step\n")
  
                  if args.jit:
                      x = torch.randn(
                          args.batch_size, 3, 224, 224
                      ).contiguous(memory_format=torch.channels_last)
                      if args.bf16:
                          x = x.to(torch.bfloat16)
                          with torch.cpu.amp.autocast(), torch.no_grad():
                              model = torch.jit.trace(model, x).train(
                                  False
                              )
                      else:
                          with torch.no_grad():
                              model = torch.jit.trace(model, x).train(
                                  False
                              )
                      model = torch.jit.freeze(model)
          else:
              print("using official pytorch model to do inference\n")
  
          model.train(False)
          return model
  
      def optimizer_creator(model, config):
          return None
  
      if args.dummy:
          number_iter = args.steps if args.steps > 0 else 200
      else:
          number_iter = args.steps if args.steps > 0 else None
      if args.calibration:
          number_iter = 100
  
      from bigdl.orca.learn.pytorch import Estimator
      from bigdl.orca.learn.metrics import Accuracy
  
      config = vars(args).copy()
      batch = config.pop("batch_size")
      config[
          "batch"
      ] = batch  # Dummy data needs batch_size in MainCallback
      est = Estimator.from_torch(
          model=model_creator,
          optimizer=optimizer_creator,
          loss=nn.CrossEntropyLoss(),
          metrics=[Accuracy()],
          backend=args.backend,
          config=config,
          workers_per_node=args.workers_per_node,
          use_tqdm=True,
      )
  
      result = est.evaluate(
          data=val_loader_func,
          batch_size=args.batch_size,
          num_steps=number_iter,
          profile=True,
          callbacks=[ResNetPerfCallback()],
      )
      for r in result:
          print("{}: {}".format(r, result[r]))
  
      print("---------")
      print("total number of records:", result["num_samples"])
      print("batch_size for each worker:", args.batch_size)
      num_samples_per_worker = result["num_samples"] / (
          args.workers_per_node * args.num_nodes
      )
      print(
          "num_samples for each worker: around", num_samples_per_worker
      )
      print(
          "num_batches for each worker: around",
          num_samples_per_worker // args.batch_size,
      )
      mean_validation_s = result["profile"]["mean_validation_s"]
      mean_eval_fwd_s = result["profile"]["mean_eval_fwd_s"]
      print("avg_val_time for each worker:", mean_validation_s)
      print("avg_forward_time for each batch:", mean_eval_fwd_s)
      latency = mean_eval_fwd_s / args.batch_size * 1000
      perf = args.batch_size / mean_eval_fwd_s
      print("inference latency %.3f ms" % latency)
      print("Throughput: {:.3f} fps".format(perf))
      print("Accuracy: {top1:.3f} ".format(top1=result["Accuracy"]))
  
file_path: BigDL/python/orca/example/learn/pytorch/resnet50/inference.py
imports: import os
  import argparse
  import torch
  import torch.nn
  import torch.utils.data
  import torchvision.transforms
  import torchvision.datasets
  import torchvision.models
  from bigdl.dllib.utils.log4Error import *
  from bigdl.orca import init_orca_context, stop_orca_context
  from bigdl.orca.learn.pytorch.callbacks import MainCallback
label_desc: Use image node_id 2 for calling a global function with example usage: validate(args) and returns: val_loader, model, None