示例#1
0
def make_metrics(proto):
  """Returns a single-element list containing a dictionary of metrics."""
  key, s = proto
  p = results_pb2.Results.FromString(s)
  mesh_path = f"{FLAGS.occnet_dir}{key.replace('test/', '')}.ply"
  log.warning('Mesh path: %s' % mesh_path)
  try:
    mesh = file_util.read_mesh(mesh_path)
    _, synset, mesh_hash = key.split('/')
    if FLAGS.transform:
      ex = example.InferenceExample('test', synset, mesh_hash)
      tx = ex.gaps_to_occnet
      mesh.apply_transform(tx)
    log.info('Succeeded on %s' % mesh_path)
  # pylint:disable=broad-except
  except Exception as e:
    # pylint:enable=broad-except
    log.error(f"Couldn't load {mesh_path}, skipping due to {repr(e)}.")
    return []

  gt_mesh = mesh_util.deserialize(p.gt_mesh)
  dir_out = FLAGS.occnet_dir + '/metrics-out-gt/%s' % key
  if not file_util.exists(dir_out):
    file_util.makedirs(dir_out)
  file_util.write_mesh(f'{dir_out}gt_mesh.ply', gt_mesh)
  file_util.write_mesh(f'{dir_out}occnet_pred.ply', mesh)

  nc, fst, fs2t, chamfer = metrics.all_mesh_metrics(mesh, gt_mesh)
  return [{
      'key': key,
      'Normal Consistency': nc,
      'F-Score (tau)': fst,
      'F-Score (2*tau)': fs2t,
      'Chamfer': chamfer,
  }]
示例#2
0
def make_example(elt):
  """Makes a python object with the example dataset items."""
  if 'shapenet' in elt['dataset'] and 'unseen' not in elt['dataset']:
    return examples.InferenceExample.from_elt(elt)
  elif 'unseen' in elt['dataset']:
    obj = lambda: 0
    # TODO(ldif-user) Set up the input key-value store
    kv_store = None
    k = elt['mesh_identifier'].strip()
    s = kv_store[k]
    p = shapenet_numpy.ShapeNetNSSDodecaSparseLRGMediumSlimPC.FromString(s)
    obj.depth_images = p.depth_renders
    obj.surface_samples_from_dodeca = p.surface_point_samples
    # TODO(ldif-user) Set up the path to the transformation:
    tx_path = 'ROOT_DIR/%s/occnet_to_gaps.txt' % k
    obj.occnet_to_gaps = file_util.read_txt_to_np(tx_path).reshape([4, 4])
    obj.gaps_to_occnet = np.linalg.inv(obj.occnet_to_gaps)
    # TODO(ldif-user) Set up the path to the normalized gt mesh.
    nrm_gt_mesh_path = 'ROOT_DIR/%s/model_normalized.ply' % k
    obj.normalized_gt_mesh = file_util.read_mesh(nrm_gt_mesh_path)
    obj.gt_mesh = obj.normalized_gt_mesh.copy()
    obj.gt_mesh.apply_transform(obj.gaps_to_occnet)
    return obj
  else:
    raise ValueError('Unimplemented.')
示例#3
0
def make_metrics(proto):
  """Builds a dictionary containing proto elements."""
  key, s = proto
  p = results_pb2.Results.FromString(s)
  mesh_path = FLAGS.occnet_dir + key.replace('test/', '') + '.ply'
  log.warning('Mesh path: %s' % mesh_path)
  try:
    mesh = file_util.read_mesh(mesh_path)
    if FLAGS.transform:
      # TODO(ldif-user) Set up the path to the transformation:
      tx_path = 'ROOT_DIR/%s/occnet_to_gaps.txt' % key
      occnet_to_gaps = file_util.read_txt_to_np(tx_path).reshape([4, 4])
      gaps_to_occnet = np.linalg.inv(occnet_to_gaps)
      mesh.apply_transform(gaps_to_occnet)
  # pylint: disable=broad-except
  except Exception as e:
    # pylint: enable=broad-except
    log.error("Couldn't load %s, skipping due to %s." % (mesh_path, repr(e)))
    return []

  gt_mesh = mesh_util.deserialize(p.gt_mesh)
  dir_out = FLAGS.occnet_dir + '/metrics-out-gt/%s' % key
  if not file_util.exists(dir_out):
    file_util.makedirs(dir_out)
  file_util.write_mesh(f'{dir_out}gt_mesh.ply', gt_mesh)
  file_util.write_mesh(f'{dir_out}occnet_pred.ply', mesh)

  nc, fst, fs2t, chamfer = metrics.all_mesh_metrics(mesh, gt_mesh)
  return [{
      'key': key,
      'Normal Consistency': nc,
      'F-Score (tau)': fst,
      'F-Score (2*tau)': fs2t,
      'Chamfer': chamfer,
  }]
示例#4
0
 def gt_mesh(self):
   if self._gt_mesh is None:
     self._gt_mesh = file_util.read_mesh(self.gt_path)
   return self._gt_mesh