# Path: ldif/datasets/process_element.py
# def load_example_dict(example_directory, log_level=None):
# def _float_feature(value):
# def _bytes_feature(value):
# def make_tf_example(d):
# def full_featurespec():
# def parse_tf_example(example_proto):
# def _example_dict_tf_func_wrapper(mesh_orig_path):
# def parse_example(filename):
# 
# Path: ldif/scripts/make_example.py
# def remove_png_dir(d):
# def write_depth_and_normals_npz(dirpath, path_out):
# def mesh_to_example(codebase_root_dir, mesh_path, dirpath, skip_existing, log_level):
# 
# 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/path_util.py
# def get_path_to_ldif_root():
# def get_path_to_ldif_parent():
# def package_to_abs(path):
# def gaps_path():
# def test_data_path():
# def util_test_data_path():
# def create_test_output_dir():
# 
# 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):


import glob
import random
import os
import tqdm
import tensorflow as tf
from absl import app
from absl import flags
from joblib import Parallel, delayed
from ldif.datasets import process_element
from ldif.scripts import make_example
from ldif.util import file_util
from ldif.util import path_util
from ldif.util.file_util import log

flags.DEFINE_string('log_level', 'INFO',
    'One of VERBOSE, INFO, WARNING, ERROR. Sets logs to print '
    'only at or above the specified level.')

flags.DEFINE_boolean(
    'optimize', True, 'Whether to create an optimized tfrecords '
    'dataset. This will substantially improve IO throughput, at '
    'the expense of approximately doubling disk usage and adding '
    'a moderate amount of additional dataset creation time. '
    'Recommended unless disk space is very tight or data is stored '
    'on a local NVMe drive or similar.')

flags.DEFINE_boolean(
    'trample_optimized', True, 'Whether to erase and re-create '
    'optimized files. Set True if changes have been made to the '
    'dataset since the last time meshes2dataset was run; set '
    'False to complete optimization if it was halted midway.')

flags.DEFINE_boolean(
    'optimize_only', False, 'Whether to skip dataset creation '
    'and only write tfrecords files.')


def process_one(f, mesh_directory, dataset_directory, skip_existing, log_level):
  """Processes a single mesh, adding it to the dataset."""
  relpath = f.replace(mesh_directory, '')
  assert relpath[0] == '/'
  relpath = relpath[1:]
  split, synset = relpath.split('/')[:2]

# Path: ldif/datasets/process_element.py
# def load_example_dict(example_directory, log_level=None):
# def _float_feature(value):
# def _bytes_feature(value):
# def make_tf_example(d):
# def full_featurespec():
# def parse_tf_example(example_proto):
# def _example_dict_tf_func_wrapper(mesh_orig_path):
# def parse_example(filename):
# 
# Path: ldif/scripts/make_example.py
# def remove_png_dir(d):
# def write_depth_and_normals_npz(dirpath, path_out):
# def mesh_to_example(codebase_root_dir, mesh_path, dirpath, skip_existing, log_level):
# 
# 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/path_util.py
# def get_path_to_ldif_root():
# def get_path_to_ldif_parent():
# def package_to_abs(path):
# def gaps_path():
# def test_data_path():
# def util_test_data_path():
# def create_test_output_dir():
# 
# 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: meshes2dataset.py
import glob
import random
import os
import tqdm
import tensorflow as tf
from absl import app
from absl import flags
from joblib import Parallel, delayed
from ldif.datasets import process_element
from ldif.scripts import make_example
from ldif.util import file_util
from ldif.util import path_util
from ldif.util.file_util import log


flags.DEFINE_string('log_level', 'INFO',
    'One of VERBOSE, INFO, WARNING, ERROR. Sets logs to print '
    'only at or above the specified level.')

flags.DEFINE_boolean(
    'optimize', True, 'Whether to create an optimized tfrecords '
    'dataset. This will substantially improve IO throughput, at '
    'the expense of approximately doubling disk usage and adding '
    'a moderate amount of additional dataset creation time. '
    'Recommended unless disk space is very tight or data is stored '
    'on a local NVMe drive or similar.')

flags.DEFINE_boolean(
    'trample_optimized', True, 'Whether to erase and re-create '
    'optimized files. Set True if changes have been made to the '
    'dataset since the last time meshes2dataset was run; set '
    'False to complete optimization if it was halted midway.')

flags.DEFINE_boolean(
    'optimize_only', False, 'Whether to skip dataset creation '
    'and only write tfrecords files.')


def process_one(f, mesh_directory, dataset_directory, skip_existing, log_level):
  """Processes a single mesh, adding it to the dataset."""
  relpath = f.replace(mesh_directory, '')
  assert relpath[0] == '/'
  relpath = relpath[1:]
  split, synset = relpath.split('/')[:2]

  log.verbose(f'The split is {split} and the synset is {synset}')