# Path: ldif/util/net_util.py
# def twin_inference(inference_fun, observation, element_count,
#                    flat_element_length, model_config):
# def get_normalizer_and_mode(model_config):
# def conv_layer(inputs, depth, model_config):
# def maxpool2x2_layer(inputs):
# def down_layer(inputs, depth, model_config):
# def up_layer(inputs, spatial_dims, depth, model_config):
# def encode(inputs,
#            model_config,
#            conv_layer_depths,
#            fc_layer_depths,
#            name='Encoder'):
# def inputs_to_feature_vector(inputs, feature_length, model_config):
# def decode(z,
#            model_config,
#            spatial_dims,
#            fc_layer_depths,
#            conv_layer_depths,
#            output_dim,
#            name='Decoder'):
# def residual_layer(inputs, num_outputs, model_config):
# 
# 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 functools
import tensorflow as tf
import tensorflow.contrib.layers as contrib_layers
import tensorflow.contrib.slim as slim
import tensorflow_hub as hub
from tensorflow.contrib.slim.nets import resnet_utils
from tensorflow.contrib.slim.nets import resnet_v2 as contrib_slim_resnet_v2
from ldif.util import net_util
from ldif.util.file_util import log

    individual_images = tf.split(
        inputs, num_or_size_splits=inputs.get_shape().as_list()[1], axis=1)
    image_count = len(individual_images)
    assert image_count == model_config.hparams.rc  # just debugging, can remove.
    embeddings = []
    embedding_length = 1023
    for i, image in enumerate(individual_images):
      with tf.variable_scope('mfcnn', reuse=i != 0):
        embedding = net_util.inputs_to_feature_vector(image, embedding_length,
                                                      model_config)
        if model_config.hparams.fua == 't':
          embedding = tf.reshape(
              embedding, [model_config.hparams.bs, 3, embedding_length // 3])
          embedding = tf.pad(embedding, tf.constant([[0, 0], [0, 1], [0, 0]]))
          cam2world_i = observation.cam_to_worlds[:, i, :, :]  # [bs, rc, 4, 4]
          embedding = tf.matmul(cam2world_i, embedding)
          # embedding shape [bs, 4, embedding_length // 3]
          embedding = tf.reshape(embedding[:, :3, :],
                                 [model_config.hparams.bs, embedding_length])
        embeddings.append(embedding)
    if image_count > 1:
      embeddings = tf.ensure_shape(
          tf.stack(embeddings, axis=1),
          [model_config.hparams.bs, image_count, embedding_length])
      embedding = tf.reduce_max(embeddings, axis=1)
    else:
      embedding = embeddings[0]
    # TODO(kgenova) Should be a helper:
    net = embedding

# Path: ldif/util/net_util.py
# def twin_inference(inference_fun, observation, element_count,
#                    flat_element_length, model_config):
# def get_normalizer_and_mode(model_config):
# def conv_layer(inputs, depth, model_config):
# def maxpool2x2_layer(inputs):
# def down_layer(inputs, depth, model_config):
# def up_layer(inputs, spatial_dims, depth, model_config):
# def encode(inputs,
#            model_config,
#            conv_layer_depths,
#            fc_layer_depths,
#            name='Encoder'):
# def inputs_to_feature_vector(inputs, feature_length, model_config):
# def decode(z,
#            model_config,
#            spatial_dims,
#            fc_layer_depths,
#            conv_layer_depths,
#            output_dim,
#            name='Decoder'):
# def residual_layer(inputs, num_outputs, model_config):
# 
# 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/nets/cnn.py
import functools
import tensorflow as tf
import tensorflow.contrib.layers as contrib_layers
import tensorflow.contrib.slim as slim
import tensorflow_hub as hub
from tensorflow.contrib.slim.nets import resnet_utils
from tensorflow.contrib.slim.nets import resnet_v2 as contrib_slim_resnet_v2
from ldif.util import net_util
from ldif.util.file_util import log


    individual_images = tf.split(
        inputs, num_or_size_splits=inputs.get_shape().as_list()[1], axis=1)
    image_count = len(individual_images)
    assert image_count == model_config.hparams.rc  # just debugging, can remove.
    embeddings = []
    embedding_length = 1023
    for i, image in enumerate(individual_images):
      with tf.variable_scope('mfcnn', reuse=i != 0):
        embedding = net_util.inputs_to_feature_vector(image, embedding_length,
                                                      model_config)
        if model_config.hparams.fua == 't':
          embedding = tf.reshape(
              embedding, [model_config.hparams.bs, 3, embedding_length // 3])
          embedding = tf.pad(embedding, tf.constant([[0, 0], [0, 1], [0, 0]]))
          cam2world_i = observation.cam_to_worlds[:, i, :, :]  # [bs, rc, 4, 4]
          embedding = tf.matmul(cam2world_i, embedding)
          # embedding shape [bs, 4, embedding_length // 3]
          embedding = tf.reshape(embedding[:, :3, :],
                                 [model_config.hparams.bs, embedding_length])
        embeddings.append(embedding)
    if image_count > 1:
      embeddings = tf.ensure_shape(
          tf.stack(embeddings, axis=1),
          [model_config.hparams.bs, image_count, embedding_length])
      embedding = tf.reduce_max(embeddings, axis=1)
    else:
      embedding = embeddings[0]
    # TODO(kgenova) Should be a helper:
    net = embedding

    normalizer, normalizer_params = net_util.get_normalizer_and_mode(