code: def vis(model, test_dataloader, device, split, opt):
      linsize = opt.linsize
      torch.cuda.empty_cache()
      if opt.dataset == "Inaturalist":
          if opt.iter > 0:
              with open(opt.cluster_path, "rb") as clusterf:
                  (
                      path2idx,
                      global_features,
                      global_pred_labels,
                      gt_labels,
                      masks,
                  ) = pkl.load(clusterf)
                  gt_labels = gt_labels + len(
                      np.unique(global_pred_labels)
                  )
                  idx2path = {v: k for k, v in path2idx.items()}
          else:
              with open(
                  os.path.join(opt.source_path, "train_set1.txt")
              ) as f:
                  filelines = f.readlines()
                  paths = [x.strip() for x in filelines]
                  Lin_paths = paths[:linsize]
                  masks = np.zeros(len(paths))
                  masks[: len(Lin_paths)] = 0
                  masks[len(Lin_paths) :] = 2
  
      _ = model.eval()
      path2ids = {}
  
      with torch.no_grad():
          ### For all test images, extract features
          target_labels, feature_coll = [], []
          final_iter = tqdm(
              test_dataloader, desc="Computing Evaluation Metrics..."
          )
          image_paths = [
              x[0] for x in test_dataloader.dataset.image_list
          ]
          for i in range(len(image_paths)):
              path2ids[image_paths[i]] = i
          for idx, inp in enumerate(final_iter):
              input_img, target = inp[-1], inp[0]
              target_labels.extend(target.numpy().tolist())
              out = model(input_img.to(device), feature=True)
              feature_coll.extend(out.cpu().detach().numpy().tolist())
          # pdb.set_trace()
          target_labels = np.hstack(target_labels).reshape(-1)
          feature_coll = np.vstack(feature_coll).astype("float32")
  
      if (opt.dataset == "Inaturalist") and "all_train" in split:
          if opt.iter > 0:
              predicted_features = np.zeros_like(feature_coll)
              path2ids_new = {}
              target_labels_new = np.zeros_like(target_labels)
              for i in range(len(idx2path.keys())):
                  path = idx2path[i]
                  idxx = path2ids[path]
                  path2ids_new[path] = i
                  predicted_features[i] = feature_coll[idxx]
                  target_labels_new[i] = target_labels[idxx]
  
              path2ids = path2ids_new
              feature_coll = predicted_features
              target_labels = target_labels_new
              gtlabels = target_labels
              lastuselected = np.where(masks == 1)
              masks[lastuselected] = 0
              print(len(np.where(masks == 0)[0]))
          else:
              predicted_features = np.zeros_like(feature_coll)
              path2ids_new = {}
              target_labels_new = np.zeros_like(target_labels)
              for i in range(len(paths)):
                  path = paths[i]
                  idxx = path2ids[opt.source_path + "/" + path]
                  path2ids_new[opt.source_path + "/" + path] = i
                  predicted_features[i] = feature_coll[idxx]
                  target_labels_new[i] = target_labels[idxx]
  
              path2ids = path2ids_new
              feature_coll = predicted_features
              target_labels = target_labels_new
              gtlabels = target_labels
  
      if "all_train" not in split:
          print("all_train not in split.")
          gtlabels = target_labels
  
      output_feature_path = os.path.join(
          opt.source_path, split + "_inat_features.pkl"
      )
      print("Dump features into {}.".format(output_feature_path))
      with open(output_feature_path, "wb") as f:
          pkl.dump(
              [path2ids, feature_coll, target_labels, gtlabels, masks],
              f,
          )
  
      print(target_labels.max())
      print("target_labels:", target_labels.shape)
      print("feature_coll:", feature_coll.shape)
  
imports: import warnings
  import csv
  import datetime
  import os
  import pickle
  import faiss
  import matplotlib.pyplot
  import numpy
  import torch
  from PIL import Image
  from sklearn import metrics
  from torch import nn
  from tqdm import tqdm
  import pdb
label_desc: Use image node_id 13 for calling a global function with example usage: vis(model, test_dataloader, device, split, opt) without return types