new_contents: import math
  import numpy as np
  import tensorflow as tf
  import scipy
  
  from tensorflow.python.framework import ops
  
  image_summary = tf.summary.image
  scalar_summary = tf.summary.scalar
  histogram_summary = tf.summary.histogram
  merge_summary = tf.summary.merge
  SummaryWriter = tf.summary.FileWriter
  
  class batch_norm(object):
  	def __init__(self, epsilon=1e-5, momentum=0.9, name='batch_norm'):
  		with tf.variable_scope(name):
  			self.epsilon = epsilon
  			self.momentum = momentum
  			self.name = name
  	def __call__(self, x, train=True):
  		return tf.contrib.layers.batch_norm(x,
  			decay=self.momentum,
  			updates_collections=None,
  			epsilon=self.epsilon,
  			scale=True,
  			is_training=train,
  			scope=self.name)
  
  def conv2d(input_, output_dim, k_h=5, k_w=5, d_h=2, d_w=2, stddev=0.02, name='conv2d'):
  	with tf.variable_scope(name):
  		w = tf.get_variable('w', [k_h, k_w, input_.get_shape()[-1], output_dim],
  			initializer=tf.truncated_normal_initializer(stddev=stddev))
  		conv = tf.nn.conv2d(input_, w, strides=[1, d_h, d_w, 1], padding='SAME')
  		biases = tf.get_variable('biases', [output_dim], initializer=tf.constant_initializer(0.))
  		conv = tf.reshape(tf.nn.bias_add(conv, biases), conv.get_shape())
  		return conv
  
  def deconv2d(input_, output_shape, k_h=5, k_w=5, d_h=2, d_w=2, stddev=0.02, name='deconv2d', with_w=False):
  	with tf.variable_scope(name):
  		w = tf.get_variable('w', [k_h, k_w, output_shape[-1], input_.get_shape()[-1]], 
  			initializer=tf.random_normal_initializer(stddev=stddev))
  
  		deconv = tf.nn.conv2d_transpose(input_, w, output_shape=output_shape,
  			strides=[1, d_h, d_w, 1])
  		biases = tf.get_variable('biases', [output_shape[-1]], initializer=tf.constant_initializer(0.))
  		deconv = tf.reshape(tf.nn.bias_add(deconv, biases), deconv.get_shape())
  
  		if with_w:
  			return deconv, w, biases
  		else:
  			return deconv
  
  def lrelu(x, leak=0.2, name='lrelu'):
  	return tf.maximum(x, leak*x)
  
  def linear(input_, output_size, scope=None, stddev=0.02, bias_start=0., with_w=False):
  	shape = input_.get_shape().as_list()
  
  	with tf.variable_scope(scope or 'Linear'):
  		matrix = tf.get_variable('Matrix', [shape[1], output_size], tf.float32, tf.random_normal_initializer(stddev=stddev))
  		bias = tf.get_variable('bias', [output_size], initializer=tf.constant_initializer(bias_start))
  
  		if with_w:
  			return tf.matmul(input_, matrix) + bias, matrix, bias
  		else:
  			return tf.matmul(input_, matrix) + bias
  
  def save_images(images, size, image_path):
  	return imsave(inverse_transform(images), size, image_path)
  
  def inverse_transform(images):
  	return (images+1.)/2.
  
  def imsave(images, size, path):
  	image = np.squeeze(merge(images, size))
  	return scipy.misc.imsave(path, image)
  
  def merge(images, size):
  	h, w = images.shape[1], images.shape[2]
  	if (images.shape[3] in (3, 4)):
  		c = images.shape[3]
  		img = np.zeros((h*size[0], w*size[1], c))
  		for idx, image in enumerate(images):
  			i = idx % size[1]
  			j = idx // size[1]
  			img[j*h:(j+1)*h, i*w:(i+1)*w, :] = image
  		return img
  	elif images.shape[3] == 1:
  		img = np.zeros((h*size[0], w*size[1]))
  		for idx, image in enumerate(images):
  			i = idx % size[1]
  			j = idx // size[1]
  			img[j*h:(j+1)*h, i*w:(i+1)*w] = image[:, :, 0]
  		return img
  
subject: Create utils.py