code: def gen_mesh(
      res,
      net,
      cuda,
      data,
      save_path,
      thresh=0.5,
      use_octree=True,
      components=False,
  ):
      image_tensor_global = data["img_512"].to(device=cuda)
      image_tensor = data["img"].to(device=cuda)
      calib_tensor = data["calib"].to(device=cuda)
  
      net.filter_global(image_tensor_global)
      net.filter_local(image_tensor[:, None])
  
      try:
          if net.netG.netF is not None:
              image_tensor_global = torch.cat(
                  [image_tensor_global, net.netG.nmlF], 0
              )
          if net.netG.netB is not None:
              image_tensor_global = torch.cat(
                  [image_tensor_global, net.netG.nmlB], 0
              )
      except:
          pass
  
      b_min = data["b_min"]
      b_max = data["b_max"]
      try:
          save_img_path = save_path[:-4] + ".png"
          save_img_list = []
          for v in range(image_tensor_global.shape[0]):
              save_img = (
                  np.transpose(
                      image_tensor_global[v].detach().cpu().numpy(),
                      (1, 2, 0),
                  )
                  * 0.5
                  + 0.5
              )[:, :, ::-1] * 255.0
              save_img_list.append(save_img)
          save_img = np.concatenate(save_img_list, axis=1)
          cv2.imwrite(save_img_path, save_img)
  
          verts, faces, _, _ = reconstruction(
              net,
              cuda,
              calib_tensor,
              res,
              b_min,
              b_max,
              thresh,
              use_octree=use_octree,
              num_samples=50000,
          )
          verts_tensor = (
              torch.from_numpy(verts.T)
              .unsqueeze(0)
              .to(device=cuda)
              .float()
          )
          # if 'calib_world' in data:
          #     calib_world = data['calib_world'].numpy()[0]
          #     verts = np.matmul(np.concatenate([verts, np.ones_like(verts[:,:1])],1), inv(calib_world).T)[:,:3]
  
          color = np.zeros(verts.shape)
          interval = 50000
          for i in range(len(color) // interval + 1):
              left = i * interval
              if i == len(color) // interval:
                  right = -1
              else:
                  right = (i + 1) * interval
              net.calc_normal(
                  verts_tensor[:, None, :, left:right],
                  calib_tensor[:, None],
                  calib_tensor,
              )
              nml = net.nmls.detach().cpu().numpy()[0] * 0.5 + 0.5
              color[left:right] = nml.T
  
          save_obj_mesh_with_color(save_path, verts, faces, color)
      except Exception as e:
          print(e)
  
imports: import sys
  import os
  import time
  import json
  import numpy
  import cv2
  import random
  import torch
  import torch.nn
  from tqdm import tqdm
  from torch.utils.data import DataLoader
  import matplotlib.pyplot
  import matplotlib.cm
  import matplotlib
  from numpy.linalg import inv
  from lib.options import BaseOptions
  from lib.mesh_util import save_obj_mesh_with_color, reconstruction
  from lib.data import EvalWPoseDataset, EvalDataset
  from lib.model import HGPIFuNetwNML, HGPIFuMRNet
  from lib.geometry import index
  from PIL import Image
label_desc: Use image node_id 1 for calling a global function with example usage: gen_mesh(res, net, cuda, data, save_path, thresh, use_octree, components) without return types