exercise/fm_dssm.py
def batch_normalization(x, phase_train, out_size):
	"""
    Batch normalization on convolutional maps.
    Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow
    Args:
        x:           Tensor, 4D BHWD input maps
        out_size:    integer, depth of input maps
        phase_train: boolean tf.Varialbe, true indicates training phase
        scope:       string, variable scope
    Return:
        normed:      batch-normalized maps
    """

	with tf.variable_scope('bn'):
		beta = tf.Variable(tf.constant(0.0, shape=[out_size]), name='beta', trainable=True)
		gamma = tf.Variable(tf.constant(1.0, shape=[out_size]), name='gamma', trainable=True)
		batch_mean, batch_var = tf.nn.moments(x, [0], name='moments')
		ema = tf.train.ExponentialMovingAverage(decay=0.5)

		def mean_var_with_update():
			ema_apply_op = ema.apply([batch_mean, batch_var])
			with tf.control_dependencies([ema_apply_op]):
				return tf.identity(batch_mean), tf.identity(batch_var)

		mean, var = tf.cond(phase_train, mean_var_with_update, lambda: (ema.average(batch_mean), ema.average(batch_var)))
		normed = tf.nn.batch_normalization(x, mean, var, beta, gamma, 1e-3)
	return normed

    Batch normalization on convolutional maps.
    Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow
    Args:
        x:           Tensor, 4D BHWD input maps
        out_size:    integer, depth of input maps
        phase_train: boolean tf.Varialbe, true indicates training phase
        scope:       string, variable scope
    Return:
        normed:      batch-normalized maps
    
Batch normalization on convolutional maps.
Batch normalization on convolutional maps .
def batch_normalization(x, phase_train, out_size):
	with tf.variable_scope('bn'):
		beta = tf.Variable(tf.constant(0.0, shape=[out_size]), name='beta', trainable=True)
		gamma = tf.Variable(tf.constant(1.0, shape=[out_size]), name='gamma', trainable=True)
		batch_mean, batch_var = tf.nn.moments(x, [0], name='moments')
		ema = tf.train.ExponentialMovingAverage(decay=0.5)
		def mean_var_with_update():
			ema_apply_op = ema.apply([batch_mean, batch_var])
			with tf.control_dependencies([ema_apply_op]):
				return tf.identity(batch_mean), tf.identity(batch_var)
		mean, var = tf.cond(phase_train, mean_var_with_update, lambda: (ema.average(batch_mean), ema.average(batch_var)))
		normed = tf.nn.batch_normalization(x, mean, var, beta, gamma, 1e-3)
	return normed
def batch_normalization ( x , phase_train , out_size ) : with tf . variable_scope ( 'bn' ) : beta = tf . Variable ( tf . constant ( 0.0 , shape = [ out_size ] ) , name = 'beta' , trainable = True ) gamma = tf . Variable ( tf . constant ( 1.0 , shape = [ out_size ] ) , name = 'gamma' , trainable = True ) batch_mean , batch_var = tf . nn . moments ( x , [ 0 ] , name = 'moments' ) ema = tf . train . ExponentialMovingAverage ( decay = 0.5 ) def mean_var_with_update ( ) : ema_apply_op = ema . apply ( [ batch_mean , batch_var ] ) with tf . control_dependencies ( [ ema_apply_op ] ) : return tf . identity ( batch_mean ) , tf . identity ( batch_var ) mean , var = tf . cond ( phase_train , mean_var_with_update , lambda : ( ema . average ( batch_mean ) , ema . average ( batch_var ) ) ) normed = tf . nn . batch_normalization ( x , mean , var , beta , gamma , 1e-3 ) return normed
Batch normalization on convolutional maps.
Batch normalization on convolutional maps .
"""
    Batch normalization on convolutional maps.
    Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow
    Args:
        x:           Tensor, 4D BHWD input maps
        out_size:    integer, depth of input maps
        phase_train: boolean tf.Varialbe, true indicates training phase
        scope:       string, variable scope
    Return:
        normed:      batch-normalized maps
    """
x
Tensor, 4D BHWD input maps
Tensor 4D BHWD input maps
phase_train
boolean tf.Varialbe, true indicates training phase
boolean tf . Varialbe true indicates training phase
out_size
integer, depth of input maps
integer depth of input maps
scope
string, variable scope
string variable scope