# Path: ldif/inference/util.py
# def parse_xid_str(xidstr):
# def ensure_split_valid(split):
# def ensure_category_valid(category):
# def ensure_synset_valid(synset):
# def ensure_hash_valid(h):
# def parse_xid_to_ckpt(xid_to_ckpt):
# def get_npz_paths(split, category, modifier=''):
# def get_mesh_identifiers(split, category):
# def get_rgb_paths(split, category, modifier=''):
# def rgb_path_to_synset_and_hash(rgb_path):
# def rgb_path_to_npz_path(rgb_path, split, dataset='shapenet-occnet'):
# def parse_npz_path(path):
# def read_png_to_float_npy_with_reraising(path):
# 
# Path: ldif/util/file_util.py
# def readlines(p):
# def readbin(p):
# def writebin(p, s):
# def writetxt(p, s):
# def write_np(path, arr):
# def read_grd(path):
# def read_sif_v1(path, verbose=False):
# def read_lines(p):
# def read_image(p):
# def read_npz(p):
# def read_np(p):
# def read_txt_to_np(p):
# def read_py2_pkl(p):
# def write_mesh(path, mesh):
# def read_mesh(path):
# def read_csv(path):
# def read_normals(path_to_dir, im_count=20, leading='_depth'):
# def write_points(path_ext_optional, points):
# def write_grd(path, volume, world2grid=None):
# def write_depth_image(path, depth_image):
# 
# Path: ldif/util/file_util.py
# def readlines(p):
# def readbin(p):
# def writebin(p, s):
# def writetxt(p, s):
# def write_np(path, arr):
# def read_grd(path):
# def read_sif_v1(path, verbose=False):
# def read_lines(p):
# def read_image(p):
# def read_npz(p):
# def read_np(p):
# def read_txt_to_np(p):
# def read_py2_pkl(p):
# def write_mesh(path, mesh):
# def read_mesh(path):
# def read_csv(path):
# def read_normals(path_to_dir, im_count=20, leading='_depth'):
# def write_points(path_ext_optional, points):
# def write_grd(path, volume, world2grid=None):
# def write_depth_image(path, depth_image):


from absl import app
from absl import flags
from ldif.inference import util as inference_util
from ldif.util import file_util
from ldif.util.file_util import log
import pandas as pd
import tabulate
  xids = inference_util.parse_xid_str(FLAGS.xids)
  log.info(f'XIDS: {xids}')

  names = []
  ious = []
  fscores = []
  chamfers = []
  xid_to_name = {
      1: 'CRS SIF',
      2: 'CRS ldif',
      3: 'CR SIF',
      4: 'CR ldif',
      5: 'CRS PT SIF',
      6: 'CRS PT ldif',
      7: 'CR PT SIF',
      8: 'CR PT ldif'
  }
  for xid in xids:
    path = f'{FLAGS.input_dir}/extracted/XID{xid}_metric_summary-v2.csv'
    df = file_util.read_csv(path)
    log.info(f'XID {xid}:')
    log.info(df)
    mean = df[df['class'].str.contains('mean')]
    names.append(xid_to_name[xid])
    ious.append(float(mean['IoU']))
    fscores.append(float(mean['F-Score (tau)']))
    chamfers.append(float(mean['Chamfer']))
  l = list(zip(names, ious, fscores, chamfers))
  log.info('Start')
  log.info(names)

# Path: ldif/inference/util.py
# def parse_xid_str(xidstr):
# def ensure_split_valid(split):
# def ensure_category_valid(category):
# def ensure_synset_valid(synset):
# def ensure_hash_valid(h):
# def parse_xid_to_ckpt(xid_to_ckpt):
# def get_npz_paths(split, category, modifier=''):
# def get_mesh_identifiers(split, category):
# def get_rgb_paths(split, category, modifier=''):
# def rgb_path_to_synset_and_hash(rgb_path):
# def rgb_path_to_npz_path(rgb_path, split, dataset='shapenet-occnet'):
# def parse_npz_path(path):
# def read_png_to_float_npy_with_reraising(path):
# 
# Path: ldif/util/file_util.py
# def readlines(p):
# def readbin(p):
# def writebin(p, s):
# def writetxt(p, s):
# def write_np(path, arr):
# def read_grd(path):
# def read_sif_v1(path, verbose=False):
# def read_lines(p):
# def read_image(p):
# def read_npz(p):
# def read_np(p):
# def read_txt_to_np(p):
# def read_py2_pkl(p):
# def write_mesh(path, mesh):
# def read_mesh(path):
# def read_csv(path):
# def read_normals(path_to_dir, im_count=20, leading='_depth'):
# def write_points(path_ext_optional, points):
# def write_grd(path, volume, world2grid=None):
# def write_depth_image(path, depth_image):
# 
# Path: ldif/util/file_util.py
# def readlines(p):
# def readbin(p):
# def writebin(p, s):
# def writetxt(p, s):
# def write_np(path, arr):
# def read_grd(path):
# def read_sif_v1(path, verbose=False):
# def read_lines(p):
# def read_image(p):
# def read_npz(p):
# def read_np(p):
# def read_txt_to_np(p):
# def read_py2_pkl(p):
# def write_mesh(path, mesh):
# def read_mesh(path):
# def read_csv(path):
# def read_normals(path_to_dir, im_count=20, leading='_depth'):
# def write_points(path_ext_optional, points):
# def write_grd(path, volume, world2grid=None):
# def write_depth_image(path, depth_image):


# Path: ldif/results/print_from_summary.py
from absl import app
from absl import flags
from ldif.inference import util as inference_util
from ldif.util import file_util
from ldif.util.file_util import log
import pandas as pd
import tabulate

  xids = inference_util.parse_xid_str(FLAGS.xids)
  log.info(f'XIDS: {xids}')

  names = []
  ious = []
  fscores = []
  chamfers = []
  xid_to_name = {
      1: 'CRS SIF',
      2: 'CRS ldif',
      3: 'CR SIF',
      4: 'CR ldif',
      5: 'CRS PT SIF',
      6: 'CRS PT ldif',
      7: 'CR PT SIF',
      8: 'CR PT ldif'
  }
  for xid in xids:
    path = f'{FLAGS.input_dir}/extracted/XID{xid}_metric_summary-v2.csv'
    df = file_util.read_csv(path)
    log.info(f'XID {xid}:')
    log.info(df)
    mean = df[df['class'].str.contains('mean')]
    names.append(xid_to_name[xid])
    ious.append(float(mean['IoU']))
    fscores.append(float(mean['F-Score (tau)']))
    chamfers.append(float(mean['Chamfer']))
  l = list(zip(names, ious, fscores, chamfers))
  log.info('Start')
  log.info(names)

  log.info(ious)