# Path: network/Util.py
# def conv2d(x, W, strides=(1, 1), padding="SAME"):
# def conv3d(x, W, strides=(1, 1), padding="SAME"):
# def conv2d_transpose(x, W, strides=(1, 1), padding="SAME"):
# def conv2d_dilated(x, W, dilation, padding="SAME"):
# def create_batch_norm_vars(n_out, tower_setup, scope_name="bn"):
# def get_activation(act_str):
# def prepare_input(inputs):
# def apply_dropout(inp, dropout):
# def max_pool(x, shape, strides=None, padding="SAME"):
# def max_pool3d(x, shape, strides=None, padding="SAME"):
# def bootstrapped_ce_loss(raw_ce, fraction, n_valid_pixels_per_im):
#   def bootstrapped_ce_for_one_img(args):
# def class_balanced_ce_loss(raw_ce, targets, n_classes):
#   def class_balanced_ce_for_one_img(args):


import tensorflow as tf
from network.Util import smart_shape
RNNCell = tf.nn.rnn_cell.RNNCell
LSTMStateTuple = tf.nn.rnn_cell.LSTMStateTuple


def _conv2d(x, W, strides=None):
  if strides is None:
    strides = [1, 1]
  return tf.nn.conv2d(x, W, strides=[1] + strides + [1], padding="SAME")


def dynamic_conv_rnn(cell, inputs, sequence_length=None, initial_state=None,
                     dtype=None, parallel_iterations=None, swap_memory=False,
                     time_major=False, scope=None):
  # inputs should have shape (time, batch, height, width, feature)

# Path: network/Util.py
# def conv2d(x, W, strides=(1, 1), padding="SAME"):
# def conv3d(x, W, strides=(1, 1), padding="SAME"):
# def conv2d_transpose(x, W, strides=(1, 1), padding="SAME"):
# def conv2d_dilated(x, W, dilation, padding="SAME"):
# def create_batch_norm_vars(n_out, tower_setup, scope_name="bn"):
# def get_activation(act_str):
# def prepare_input(inputs):
# def apply_dropout(inp, dropout):
# def max_pool(x, shape, strides=None, padding="SAME"):
# def max_pool3d(x, shape, strides=None, padding="SAME"):
# def bootstrapped_ce_loss(raw_ce, fraction, n_valid_pixels_per_im):
#   def bootstrapped_ce_for_one_img(args):
# def class_balanced_ce_loss(raw_ce, targets, n_classes):
#   def class_balanced_ce_for_one_img(args):


# Path: network/layer_implementations/ConvLSTMCell.py
import tensorflow as tf
from network.Util import smart_shape

RNNCell = tf.nn.rnn_cell.RNNCell
LSTMStateTuple = tf.nn.rnn_cell.LSTMStateTuple


def _conv2d(x, W, strides=None):
  if strides is None:
    strides = [1, 1]
  return tf.nn.conv2d(x, W, strides=[1] + strides + [1], padding="SAME")


def dynamic_conv_rnn(cell, inputs, sequence_length=None, initial_state=None,
                     dtype=None, parallel_iterations=None, swap_memory=False,
                     time_major=False, scope=None):
  # inputs should have shape (time, batch, height, width, feature)

  input_shape = smart_shape(inputs)