import tensorflow as tf
import Model_hyperparameters as p
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from IPython.display import display
from seaborn import color_palette
import cv2
def batch_norm(inputs,training, data_format):
    """Performs a batch normalization using a standard set of parameters."""
    return tf.layers.batch_normalization(inputs=inputs,axis=1 if data_format=='channels_first' else 3,
                                         momentum= p._BATCH_NORM_DECAY,epsilon=p._BATCH_NORM_EPSILON,scale=True,training=training)

def fixed_padding(inputs,kernel_size,data_format):
    """ResNet implementation of fixed padding.

        Pads the input along the spatial dimensions independently of input size.

        Args:
            inputs: Tensor input to be padded.
            kernel_size: The kernel to be used in the conv2d or max_pool2d.
            data_format: The input format.
        Returns:
            A tensor with the same format as the input.
        """
    pad_total = kernel_size-1
    pad_beg = pad_total // 2
    pad_end = pad_total - pad_beg

    if data_format == 'chennels_first':
        padded_inputs = tf.pad(inputs, [[0, 0], [0, 0],
                                        [pad_beg, pad_end],
                                        [pad_beg, pad_end]])
    else:
        padded_inputs = tf.pad(inputs, [[0, 0], [pad_beg, pad_end],
                                        [pad_beg, pad_end], [0, 0]])
    return padded_inputs

def conv2d_fixed_padding(inputs,filters,kernel_size,data_format,strides=1):
    """Strided 2-D convolution with explicit padding."""
    if strides > 1:
        inputs = fixed_padding(inputs,kernel_size,data_format)
        return tf.layers.conv2d(inputs,filters,kernel_size,strides,padding=('SAME' if strides == 1 else 'VALID'),
                                use_bias=False,data_format = data_format)
