code: def evaluate(net, test_loader, dev, per_cat_verbose=False):
      category_list = sorted(list(shapenet.seg_classes.keys()))
      eye_mat = np.eye(16)
      net.eval()
  
      cat_miou = {}
      for k in shapenet.seg_classes.keys():
          cat_miou[k] = [0, 0]
      miou = 0
      count = 0
      per_cat_miou = 0
      per_cat_count = 0
  
      with torch.no_grad():
          with tqdm.tqdm(test_loader, ascii=True) as tq:
              for data, label, cat in tq:
                  num_examples = data.shape[0]
                  data = data.to(dev, dtype=torch.float)
                  label = label.to(dev, dtype=torch.long)
                  cat_ind = [category_list.index(c) for c in cat]
                  cat_tensor = torch.tensor(eye_mat[cat_ind]).to(
                      dev, dtype=torch.float
                  )
                  cat_tensor = cat_tensor.view(num_examples, 16, 1)
                  logits = net(data, cat_tensor)
                  _, preds = logits.max(1)
  
                  cat_miou = mIoU(
                      preds.cpu().numpy(),
                      label.view(num_examples, -1).cpu().numpy(),
                      cat,
                      cat_miou,
                      shapenet.seg_classes,
                  )
                  for _, v in cat_miou.items():
                      if v[1] > 0:
                          miou += v[0]
                          count += v[1]
                          per_cat_miou += v[0] / v[1]
                          per_cat_count += 1
                  tq.set_postfix(
                      {
                          "mIoU": "%.5f" % (miou / count),
                          "per Category mIoU": "%.5f"
                          % (per_cat_miou / per_cat_count),
                      }
                  )
      print(
          "[Test] mIoU: %.5f, per Category mIoU: %.5f"
          % (miou / count, per_cat_miou / per_cat_count)
      )
      if per_cat_verbose:
          print("-" * 60)
          print("Per-Category mIoU:")
          for k, v in cat_miou.items():
              if v[1] > 0:
                  print("%s mIoU=%.5f" % (k, v[0] / v[1]))
              else:
                  print("%s mIoU=%.5f" % (k, 1))
          print("-" * 60)
      return miou / count, per_cat_miou / per_cat_count
  
file_path: dgl/examples/pytorch/pointcloud/pct/train_partseg.py
imports: import argparse
  import time
  from functools import partial
  import dgl
  import numpy
  import provider
  import torch
  import torch.optim
  import tqdm
  from pct import PartSegLoss, PointTransformerSeg
  from ShapeNet import ShapeNet
  from torch.utils.data import DataLoader
label_desc: Use image node_id 4 for calling a global function with example usage: evaluate(net, test_loader, dev, per_cat_verbose) and returns: unknown,  unknown