# Path: dltk/core/upsample.py
# def linear_upsample_3d(inputs,
#                        strides=(2, 2, 2),
#                        use_bias=False,
#                        trainable=False,
#                        name='linear_upsample_3d'):
#     """Linear upsampling layer in 3D using strided transpose convolutions. The
#         upsampling kernel size will be automatically computed to avoid
#         information loss.
# 
#     Args:
#         inputs (tf.Tensor): Input tensor to be upsampled
#         strides (tuple, optional): The strides determine the upsampling factor
#             in each dimension.
#         use_bias (bool, optional): Flag to train an additional bias.
#         trainable (bool, optional): Flag to set the variables to be trainable or not.
#         name (str, optional): Name of the layer.
# 
#     Returns:
#         tf.Tensor: Upsampled Tensor
#     """
#     static_inp_shape = tuple(inputs.get_shape().as_list())
#     dyn_inp_shape = tf.shape(inputs)
#     rank = len(static_inp_shape)
# 
#     num_filters = static_inp_shape[-1]
#     strides_5d = [1, ] + list(strides) + [1, ]
#     kernel_size = [2 * s if s > 1 else 1 for s in strides]
# 
#     kernel = get_linear_upsampling_kernel(
#         kernel_spatial_shape=kernel_size,
#         out_filters=num_filters,
#         in_filters=num_filters,
#         trainable=trainable)
# 
#     dyn_out_shape = [dyn_inp_shape[i] * strides_5d[i] for i in range(rank)]
#     dyn_out_shape[-1] = num_filters
# 
#     static_out_shape = [static_inp_shape[i] * strides_5d[i]
#                         if isinstance(static_inp_shape[i], int)
#                         else None for i in range(rank)]
# 
#     static_out_shape[-1] = num_filters
#     tf.logging.info('Upsampling from {} to {}'.format(
#         static_inp_shape, static_out_shape))
# 
#     upsampled = tf.nn.conv3d_transpose(
#         value=inputs,
#         filter=kernel,
#         output_shape=dyn_out_shape,
#         strides=strides_5d,
#         padding='SAME',
#         name='upsample')
# 
#     upsampled.set_shape(static_out_shape)
# 
#     return upsampled
# 
# Path: dltk/core/activations.py
# def leaky_relu(inputs, alpha=0.1):
#     """Leaky ReLu activation function
# 
#     Args:
#         inputs (tf.Tensor): input Tensor
#         alpha (float): leakiness parameter
# 
#     Returns:
#         tf.Tensor: a leaky ReLu activated tensor
#     """
#     return tf.maximum(inputs, alpha * inputs)


import tensorflow as tf
import numpy as np
from dltk.core.upsample import linear_upsample_3d
from dltk.core.activations import leaky_relu
    """
    outputs = {}
    assert len(strides) == len(filters)
    assert len(inputs.get_shape().as_list()) == 5,\
        'inputs are required to have a rank of 5.'

    conv_op = tf.layers.conv3d

    conv_params = {'padding': 'same',
                   'use_bias': use_bias,
                   'kernel_initializer': tf.uniform_unit_scaling_initializer(),
                   'bias_initializer': tf.zeros_initializer(),
                   'kernel_regularizer': None,
                   'bias_regularizer': None}

    x = inputs
    tf.logging.info('Input tensor shape {}'.format(x.get_shape()))

    for res_scale in range(0, len(filters)):
        with tf.variable_scope('disc_unit_{}'.format(res_scale)):

            x = conv_op(inputs=x,
                        filters=filters[res_scale],
                        kernel_size=(3, 3, 3),
                        strides=strides[res_scale],
                        **conv_params)

            x = tf.layers.batch_normalization(
                x, training=mode == tf.estimator.ModeKeys.TRAIN)


# Path: dltk/core/upsample.py
# def linear_upsample_3d(inputs,
#                        strides=(2, 2, 2),
#                        use_bias=False,
#                        trainable=False,
#                        name='linear_upsample_3d'):
#     """Linear upsampling layer in 3D using strided transpose convolutions. The
#         upsampling kernel size will be automatically computed to avoid
#         information loss.
# 
#     Args:
#         inputs (tf.Tensor): Input tensor to be upsampled
#         strides (tuple, optional): The strides determine the upsampling factor
#             in each dimension.
#         use_bias (bool, optional): Flag to train an additional bias.
#         trainable (bool, optional): Flag to set the variables to be trainable or not.
#         name (str, optional): Name of the layer.
# 
#     Returns:
#         tf.Tensor: Upsampled Tensor
#     """
#     static_inp_shape = tuple(inputs.get_shape().as_list())
#     dyn_inp_shape = tf.shape(inputs)
#     rank = len(static_inp_shape)
# 
#     num_filters = static_inp_shape[-1]
#     strides_5d = [1, ] + list(strides) + [1, ]
#     kernel_size = [2 * s if s > 1 else 1 for s in strides]
# 
#     kernel = get_linear_upsampling_kernel(
#         kernel_spatial_shape=kernel_size,
#         out_filters=num_filters,
#         in_filters=num_filters,
#         trainable=trainable)
# 
#     dyn_out_shape = [dyn_inp_shape[i] * strides_5d[i] for i in range(rank)]
#     dyn_out_shape[-1] = num_filters
# 
#     static_out_shape = [static_inp_shape[i] * strides_5d[i]
#                         if isinstance(static_inp_shape[i], int)
#                         else None for i in range(rank)]
# 
#     static_out_shape[-1] = num_filters
#     tf.logging.info('Upsampling from {} to {}'.format(
#         static_inp_shape, static_out_shape))
# 
#     upsampled = tf.nn.conv3d_transpose(
#         value=inputs,
#         filter=kernel,
#         output_shape=dyn_out_shape,
#         strides=strides_5d,
#         padding='SAME',
#         name='upsample')
# 
#     upsampled.set_shape(static_out_shape)
# 
#     return upsampled
# 
# Path: dltk/core/activations.py
# def leaky_relu(inputs, alpha=0.1):
#     """Leaky ReLu activation function
# 
#     Args:
#         inputs (tf.Tensor): input Tensor
#         alpha (float): leakiness parameter
# 
#     Returns:
#         tf.Tensor: a leaky ReLu activated tensor
#     """
#     return tf.maximum(inputs, alpha * inputs)


# Path: dltk/networks/gan/dcgan.py
import tensorflow as tf
import numpy as np
from dltk.core.upsample import linear_upsample_3d
from dltk.core.activations import leaky_relu

    """
    outputs = {}
    assert len(strides) == len(filters)
    assert len(inputs.get_shape().as_list()) == 5,\
        'inputs are required to have a rank of 5.'

    conv_op = tf.layers.conv3d

    conv_params = {'padding': 'same',
                   'use_bias': use_bias,
                   'kernel_initializer': tf.uniform_unit_scaling_initializer(),
                   'bias_initializer': tf.zeros_initializer(),
                   'kernel_regularizer': None,
                   'bias_regularizer': None}

    x = inputs
    tf.logging.info('Input tensor shape {}'.format(x.get_shape()))

    for res_scale in range(0, len(filters)):
        with tf.variable_scope('disc_unit_{}'.format(res_scale)):

            x = conv_op(inputs=x,
                        filters=filters[res_scale],
                        kernel_size=(3, 3, 3),
                        strides=strides[res_scale],
                        **conv_params)

            x = tf.layers.batch_normalization(
                x, training=mode == tf.estimator.ModeKeys.TRAIN)


            x = leaky_relu(x, 0.2)