code: def main():
      args = argsparser()
      config_parser = ConfigParser(args)
      args = config_parser.parser()
  
      random.seed(args.seed)
      np.random.seed(args.seed)
      paddle.seed(args.seed)
      paddle.device.set_device(args.device)
  
      # build model
      model = get_model(args.method)(
          arch=args.backbone,
          pretrained=True,
          k=args.k,
          method=args.method,
      )
      model.init_projection()
      model.eval()
  
      result = []
      assert args.category in mvtec.CLASS_NAMES + [
          "all",
          "textures",
          "objects",
      ]
      if args.category == "all":
          class_names = mvtec.CLASS_NAMES
      elif args.category == "textures":
          class_names = mvtec.textures
      elif args.category == "objects":
          class_names = mvtec.objects
      else:
          class_names = [args.category]
      csv_columns = [
          "category",
          "Image_AUROC",
          "Pixel_AUROC",
          "PRO_score",
      ]
      csv_name = os.path.join(
          args.save_path + f"/{args.method}_{args.backbone}_{args.k}",
          "{}_seed{}.csv".format(args.category, args.seed),
      )
      for i, class_name in enumerate(class_names):
          print(
              "Training model {}/{} for {}".format(
                  i + 1, len(class_names), class_name
              )
          )
          # build datasets
          train_dataset = mvtec.MVTecDataset(
              args.data_path,
              class_name=class_name,
              is_train=True,
              resize=args.resize,
              cropsize=args.crop_size,
          )
          train_dataloader = DataLoader(
              train_dataset,
              batch_size=args.batch_size,
              num_workers=args.num_workers,
          )
          train(args, model, train_dataloader, class_name)
          if args.do_eval:
              test_dataset = mvtec.MVTecDataset(
                  args.data_path,
                  class_name=class_name,
                  is_train=False,
                  resize=args.resize,
                  cropsize=args.crop_size,
              )
              test_dataloader = DataLoader(
                  test_dataset,
                  batch_size=args.test_batch_size,
                  num_workers=args.num_workers,
              )
              result.append(
                  [
                      class_name,
                      *val(args, model, test_dataloader, class_name),
                  ]
              )
              if args.category in ["all", "textures", "objects"]:
                  pd.DataFrame(result, columns=csv_columns).set_index(
                      "category"
                  ).to_csv(csv_name)
          model.reset_stats()
      if args.do_eval:
          result = pd.DataFrame(result, columns=csv_columns).set_index(
              "category"
          )
          if not args.eval_PRO:
              del result["PRO_score"]
          if args.category in ["all", "textures", "objects"]:
              result.loc["mean"] = result.mean(numeric_only=True)
          print(result)
          print("Evaluation result saved at{}:".format(csv_name))
          result.to_csv(csv_name)
  
file_path: PaddleSeg/contrib/QualityInspector/tools/uad/patchcore/train.py
imports: import os
  import sys
  import time
  import random
  import argparse
  import datetime
  import numpy
  import pandas
  from tqdm import tqdm
  import paddle
  from paddle.io import DataLoader
  import qinspector.uad.datasets.mvtec
  from qinspector.uad.models.patchcore import get_model
  from qinspector.uad.utils.utils import str2bool
  from qinspector.cvlib.uad_configs import ConfigParser
  from val import val
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types