code: def gen_mesh(
      sess,
      feed_dict,
      latent_holder,
      point_holder,
      latent,
      occ,
      batch_val,
      hparams,
      idx=0,
  ):
      """Generating meshes given a trained NASA model."""
      scale = 1.1  # Scale of the padded bbox regarding the tight one.
      level_set = hparams.level_set
      latent_val = sess.run(latent, feed_dict)
      mesh_extractor = mise.MISE(32, 3, level_set)
      points = mesh_extractor.query()
      gt_verts = batch_val["vert"].reshape([-1, 3])
      gt_bbox = np.stack(
          [gt_verts.min(axis=0), gt_verts.max(axis=0)], axis=0
      )
      gt_center = (gt_bbox[0] + gt_bbox[1]) * 0.5
      gt_scale = (gt_bbox[1] - gt_bbox[0]).max()
  
      while points.shape[0] != 0:
          orig_points = points
          points = points.astype(np.float32)
          points = (
              np.expand_dims(points, axis=0) / mesh_extractor.resolution
              - 0.5
          ) * scale
          points = points * gt_scale + gt_center
          n_points = points.shape[1]
          values = []
          for i in range(
              0, n_points, 100000
          ):  # Add this to prevent OOM due to points overload.
              feed_dict[latent_holder] = latent_val
              feed_dict[point_holder] = np.expand_dims(
                  points[:, i : i + 100000], axis=1
              )
              value = sess.run(occ[:, idx], feed_dict)
              values.append(value)
          values = np.concatenate(values, axis=1)
          values = values[0, :, 0].astype(np.float64)
          mesh_extractor.update(orig_points, values)
          points = mesh_extractor.query()
      value_grid = mesh_extractor.to_dense()
  
      try:
          value_grid = np.pad(
              value_grid, 1, "constant", constant_values=-1e6
          )
          (
              verts,
              faces,
              normals,
              unused_var,
          ) = measure.marching_cubes_lewiner(
              value_grid, min(level_set, value_grid.max())
          )
          del normals
          verts -= 1
          verts /= np.array(
              [
                  value_grid.shape[0] - 3,
                  value_grid.shape[1] - 3,
                  value_grid.shape[2] - 3,
              ],
              dtype=np.float32,
          )
          verts = scale * (verts - 0.5)
          verts = verts * gt_scale + gt_center
          faces = np.stack(
              [faces[..., 1], faces[..., 0], faces[..., 2]], axis=-1
          )
          mesh = trimesh.Trimesh(vertices=verts, faces=faces)
          return mesh
      except:  # pylint: disable=bare-except
          return None
  
imports: from os import path
  import numpy
  from skimage import measure
  import tensorflow.compat.v1
  from tensorflow_graphics.projects.cvxnet.lib.libmise import mise
  from tensorflow_graphics.projects.nasa.lib import datasets
  from tensorflow_graphics.projects.nasa.lib import models
  import tensorflow_probability
  from tqdm import trange
  import trimesh
label_desc: Use image node_id 2 for calling a global function with example usage: gen_mesh(sess, feed_dict, latent_holder, point_holder, latent, occ, batch_val, hparams, idx) and returns: mesh, None