# 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
    else:
      im = tf.reshape(
          tf.transpose(inputs, perm=[0, 2, 3, 1, 4]),
          [batch_size, height, width, image_count * channel_count])
    if model_config.hparams.cnna == 'r18':
      raise ValueError('ResNet18 is no longer supported.')
    elif model_config.hparams.cnna == 'r50':
      raise ValueError('r50 network is no longer supported.')
    elif model_config.hparams.cnna == 'k50':
      log.warning('Using a keras based model.')
      resnet = tf.compat.v1.keras.applications.ResNet50V2(
          include_top=False,
          weights=None,
          input_tensor=None,
          input_shape=(height, width, image_count * channel_count),
          pooling=None)
      embedding = resnet(im)
    elif model_config.hparams.cnna == 's50':
      with slim.arg_scope(resnet_utils.resnet_arg_scope()):
        embedding_prenorm, _ = contrib_slim_resnet_v2.resnet_v2_50(
            inputs=im,
            num_classes=2048,
            is_training=model_config.train,
            global_pool=True,
            reuse=tf.AUTO_REUSE,
            scope='resnet_v2_50')
        embedding_prenorm = tf.reshape(embedding_prenorm,
                                       [model_config.hparams.bs, 2048])
        embedding = tf.nn.l2_normalize(embedding_prenorm, axis=1)
    elif model_config.hparams.cnna == 'h50':

# 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

    else:
      im = tf.reshape(
          tf.transpose(inputs, perm=[0, 2, 3, 1, 4]),
          [batch_size, height, width, image_count * channel_count])
    if model_config.hparams.cnna == 'r18':
      raise ValueError('ResNet18 is no longer supported.')
    elif model_config.hparams.cnna == 'r50':
      raise ValueError('r50 network is no longer supported.')
    elif model_config.hparams.cnna == 'k50':
      log.warning('Using a keras based model.')
      resnet = tf.compat.v1.keras.applications.ResNet50V2(
          include_top=False,
          weights=None,
          input_tensor=None,
          input_shape=(height, width, image_count * channel_count),
          pooling=None)
      embedding = resnet(im)
    elif model_config.hparams.cnna == 's50':
      with slim.arg_scope(resnet_utils.resnet_arg_scope()):
        embedding_prenorm, _ = contrib_slim_resnet_v2.resnet_v2_50(
            inputs=im,
            num_classes=2048,
            is_training=model_config.train,
            global_pool=True,
            reuse=tf.AUTO_REUSE,
            scope='resnet_v2_50')
        embedding_prenorm = tf.reshape(embedding_prenorm,
                                       [model_config.hparams.bs, 2048])
        embedding = tf.nn.l2_normalize(embedding_prenorm, axis=1)
    elif model_config.hparams.cnna == 'h50':

      log.warning('TF Hub not tested externally.')