Python tensorflow.Varialbe() Examples
The following are 30
code examples of tensorflow.Varialbe().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow
, or try the search function
.
Example #1
Source File: tf_util.py From ASIS with MIT License | 6 votes |
def batch_norm_for_conv2d(inputs, is_training, bn_decay, scope, is_dist=False): """ Batch normalization on 2D convolutional maps. Args: inputs: Tensor, 4D BHWC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope is_dist: true indicating distributed training scheme Return: normed: batch-normalized maps """ if is_dist: return batch_norm_dist_template(inputs, is_training, scope, [0,1,2], bn_decay) else: return batch_norm_template(inputs, is_training, scope, [0,1,2], bn_decay)
Example #2
Source File: tf_util.py From GSPN with MIT License | 6 votes |
def batch_norm_template(inputs, is_training, scope, moments_dims_unused, bn_decay, data_format='NHWC'): """ Batch normalization on convolutional maps and beyond... Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow Args: inputs: Tensor, k-D input ... x C could be BC or BHWC or BDHWC is_training: boolean tf.Varialbe, true indicates training phase scope: string, variable scope moments_dims: a list of ints, indicating dimensions for moments calculation bn_decay: float or float tensor variable, controling moving average weight data_format: 'NHWC' or 'NCHW' Return: normed: batch-normalized maps """ bn_decay = bn_decay if bn_decay is not None else 0.9 return tf.contrib.layers.batch_norm(inputs, center=True, scale=True, is_training=is_training, decay=bn_decay,updates_collections=None, scope=scope, reuse=False, data_format=data_format)
Example #3
Source File: tf_util.py From SpiderCNN with MIT License | 6 votes |
def batch_norm_template_multiGPU(inputs, is_training, scope, moments_dims_unused, bn_decay, data_format='NHWC'): """ Batch normalization on convolutional maps and beyond... Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow Args: inputs: Tensor, k-D input ... x C could be BC or BHWC or BDHWC is_training: boolean tf.Varialbe, true indicates training phase scope: string, variable scope moments_dims: a list of ints, indicating dimensions for moments calculation bn_decay: float or float tensor variable, controling moving average weight data_format: 'NHWC' or 'NCHW' Return: normed: batch-normalized maps """ bn_decay = bn_decay if bn_decay is not None else 0.9 return tf.contrib.layers.batch_norm(inputs, center=True, scale=True, is_training=is_training, decay=bn_decay,updates_collections=None, scope=scope, data_format=data_format)
Example #4
Source File: tf_util.py From ASIS with MIT License | 6 votes |
def batch_norm_for_fc(inputs, is_training, bn_decay, scope, is_dist=False): """ Batch normalization on FC data. Args: inputs: Tensor, 2D BxC input is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope is_dist: true indicating distributed training scheme Return: normed: batch-normalized maps """ if is_dist: return batch_norm_dist_template(inputs, is_training, scope, [0,], bn_decay) else: return batch_norm_template(inputs, is_training, scope, [0,], bn_decay)
Example #5
Source File: tf_util_dgcnn.py From AlignNet-3D with BSD 3-Clause "New" or "Revised" License | 6 votes |
def batch_norm_for_fc(inputs, is_training, bn_decay, scope, is_dist=False): """ Batch normalization on FC data. Args: inputs: Tensor, 2D BxC input is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope is_dist: true indicating distributed training scheme Return: normed: batch-normalized maps """ if is_dist: return batch_norm_dist_template(inputs, is_training, scope, [0,], bn_decay) else: return batch_norm_template(inputs, is_training, scope, [0,], bn_decay)
Example #6
Source File: tf_util.py From reading-frustum-pointnets-code with Apache License 2.0 | 6 votes |
def batch_norm_template(inputs, is_training, scope, moments_dims_unused, bn_decay, data_format='NHWC'): """ Batch normalization on convolutional maps and beyond... Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow Args: inputs: Tensor, k-D input ... x C could be BC or BHWC or BDHWC is_training: boolean tf.Varialbe, true indicates training phase scope: string, variable scope moments_dims: a list of ints, indicating dimensions for moments calculation bn_decay: float or float tensor variable, controling moving average weight data_format: 'NHWC' or 'NCHW' Return: normed: batch-normalized maps """ bn_decay = bn_decay if bn_decay is not None else 0.9 return tf.contrib.layers.batch_norm(inputs, center=True, scale=True, is_training=is_training, decay=bn_decay,updates_collections=None, scope=scope, data_format=data_format)
Example #7
Source File: tf_util_dgcnn.py From AlignNet-3D with BSD 3-Clause "New" or "Revised" License | 6 votes |
def batch_norm_for_conv1d(inputs, is_training, bn_decay, scope, is_dist=False): """ Batch normalization on 1D convolutional maps. Args: inputs: Tensor, 3D BLC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope is_dist: true indicating distributed training scheme Return: normed: batch-normalized maps """ if is_dist: return batch_norm_dist_template(inputs, is_training, scope, [0,1], bn_decay) else: return batch_norm_template(inputs, is_training, scope, [0,1], bn_decay)
Example #8
Source File: tf_util_dgcnn.py From AlignNet-3D with BSD 3-Clause "New" or "Revised" License | 6 votes |
def batch_norm_for_conv2d(inputs, is_training, bn_decay, scope, is_dist=False): """ Batch normalization on 2D convolutional maps. Args: inputs: Tensor, 4D BHWC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope is_dist: true indicating distributed training scheme Return: normed: batch-normalized maps """ if is_dist: return batch_norm_dist_template(inputs, is_training, scope, [0,1,2], bn_decay) else: return batch_norm_template(inputs, is_training, scope, [0,1,2], bn_decay)
Example #9
Source File: tf_util_dgcnn.py From AlignNet-3D with BSD 3-Clause "New" or "Revised" License | 6 votes |
def batch_norm_for_conv3d(inputs, is_training, bn_decay, scope, is_dist=False): """ Batch normalization on 3D convolutional maps. Args: inputs: Tensor, 5D BDHWC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope is_dist: true indicating distributed training scheme Return: normed: batch-normalized maps """ if is_dist: return batch_norm_dist_template(inputs, is_training, scope, [0,1,2,3], bn_decay) else: return batch_norm_template(inputs, is_training, scope, [0,1,2,3], bn_decay)
Example #10
Source File: tf_util.py From ASIS with MIT License | 6 votes |
def batch_norm_for_conv1d(inputs, is_training, bn_decay, scope, is_dist=False): """ Batch normalization on 1D convolutional maps. Args: inputs: Tensor, 3D BLC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope is_dist: true indicating distributed training scheme Return: normed: batch-normalized maps """ if is_dist: return batch_norm_dist_template(inputs, is_training, scope, [0,1], bn_decay) else: return batch_norm_template(inputs, is_training, scope, [0,1], bn_decay)
Example #11
Source File: tf_util.py From SPFN with MIT License | 6 votes |
def batch_norm_template(inputs, is_training, scope, moments_dims_unused, bn_decay, data_format='NHWC'): """ Batch normalization on convolutional maps and beyond... Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow Args: inputs: Tensor, k-D input ... x C could be BC or BHWC or BDHWC is_training: boolean tf.Varialbe, true indicates training phase scope: string, variable scope moments_dims: a list of ints, indicating dimensions for moments calculation bn_decay: float or float tensor variable, controling moving average weight data_format: 'NHWC' or 'NCHW' Return: normed: batch-normalized maps """ bn_decay = bn_decay if bn_decay is not None else 0.9 return tf.contrib.layers.batch_norm(inputs, center=True, scale=True, is_training=is_training, decay=bn_decay,updates_collections=None, scope=scope, data_format=data_format)
Example #12
Source File: tf_util.py From deep-functional-dictionaries with MIT License | 6 votes |
def batch_norm_template(inputs, is_training, scope, moments_dims_unused, bn_decay, data_format='NHWC'): """ Batch normalization on convolutional maps and beyond... Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow Args: inputs: Tensor, k-D input ... x C could be BC or BHWC or BDHWC is_training: boolean tf.Varialbe, true indicates training phase scope: string, variable scope moments_dims: a list of ints, indicating dimensions for moments calculation bn_decay: float or float tensor variable, controling moving average weight data_format: 'NHWC' or 'NCHW' Return: normed: batch-normalized maps """ bn_decay = bn_decay if bn_decay is not None else 0.9 return tf.contrib.layers.batch_norm(inputs, center=True, scale=True, is_training=is_training, decay=bn_decay,updates_collections=None, scope=scope, data_format=data_format)
Example #13
Source File: tf_util.py From Geo-CNN with Apache License 2.0 | 6 votes |
def batch_norm_template(inputs, is_training, scope, moments_dims_unused, bn_decay, data_format='NHWC'): """ Batch normalization on convolutional maps and beyond... Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow Args: inputs: Tensor, k-D input ... x C could be BC or BHWC or BDHWC is_training: boolean tf.Varialbe, true indicates training phase scope: string, variable scope moments_dims: a list of ints, indicating dimensions for moments calculation bn_decay: float or float tensor variable, controling moving average weight data_format: 'NHWC' or 'NCHW' Return: normed: batch-normalized maps """ bn_decay = bn_decay if bn_decay is not None else 0.9 return tf.contrib.layers.batch_norm(inputs, center=True, scale=True, is_training=is_training, decay=bn_decay,updates_collections=None, scope=scope, data_format=data_format)
Example #14
Source File: nn_functions.py From AmusingPythonCodes with MIT License | 6 votes |
def batch_normalization(x, out_shape, phase_train): """Batch normalization on convolutional maps. Args: x: Tensor, 4D Batch-Height-Width-Depth (BHWD) input maps out_shape: integer, depth of input maps phase_train: boolean tf.Varialbe, true indicates training phase Return: normed: batch-normalized maps """ with tf.variable_scope('batch_norm'): beta = tf.Variable(tf.constant(0.0, shape=[out_shape]), name='beta', trainable=True) gamma = tf.Variable(tf.constant(1.0, shape=[out_shape]), name='gamma', trainable=True) batch_mean, batch_var = tf.nn.moments(x, [0, 1, 2], 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
Example #15
Source File: architecture.py From DCNets with MIT License | 5 votes |
def batch_norm(self, x, n_out, phase_train): """ 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 n_out: 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'): gamma = self.get_bias(n_out, 1.0, 'gamma') beta = self.get_bias(n_out, 0.0, 'beta') batch_mean, batch_var = tf.nn.moments(x, [0,1,2], name='moments') ema = tf.train.ExponentialMovingAverage(decay=0.999) 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))) return tf.nn.batch_normalization(x, mean, var, beta, gamma, 1e-3)
Example #16
Source File: tf_util.py From GSPN with MIT License | 5 votes |
def batch_norm_for_fc(inputs, is_training, bn_decay, scope): """ Batch normalization on FC data. Args: inputs: Tensor, 2D BxC input is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope Return: normed: batch-normalized maps """ return batch_norm_template(inputs, is_training, scope, [0,], bn_decay)
Example #17
Source File: architecture.py From DCNets with MIT License | 5 votes |
def xnorm_batch_norm(self, x, phase_train): """ 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 n_out: 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('xnorm_bn'): batch_mean = tf.reduce_mean(x, [0,1,2]) ema = tf.train.ExponentialMovingAverage(decay=0.999) def mean_var_with_update(): ema_apply_op = ema.apply([batch_mean]) with tf.control_dependencies([ema_apply_op]): return tf.identity(batch_mean) mean = tf.cond(phase_train, mean_var_with_update, lambda: (ema.average(batch_mean))) return mean
Example #18
Source File: architecture.py From DCNets with MIT License | 5 votes |
def xnorm_batch_norm(self, x, phase_train): """ 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 n_out: 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('xnorm_bn'): batch_mean = tf.reduce_mean(x, [0,1,2]) ema = tf.train.ExponentialMovingAverage(decay=0.999) def mean_var_with_update(): ema_apply_op = ema.apply([batch_mean]) with tf.control_dependencies([ema_apply_op]): return tf.identity(batch_mean) mean = tf.cond(phase_train, mean_var_with_update, lambda: (ema.average(batch_mean))) return mean
Example #19
Source File: architecture.py From DCNets with MIT License | 5 votes |
def batch_norm(self, x, n_out, phase_train): """ 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 n_out: 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'): gamma = self.get_bias(n_out, 1.0, 'gamma') beta = self.get_bias(n_out, 0.0, 'beta') batch_mean, batch_var = tf.nn.moments(x, [0,1,2], name='moments') ema = tf.train.ExponentialMovingAverage(decay=0.999) 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))) return tf.nn.batch_normalization(x, mean, var, beta, gamma, 1e-3)
Example #20
Source File: architecture.py From DCNets with MIT License | 5 votes |
def xnorm_batch_norm(self, x, phase_train): """ 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 n_out: 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('xnorm_bn'): batch_mean = tf.reduce_mean(x, [0,1,2]) ema = tf.train.ExponentialMovingAverage(decay=0.999) def mean_var_with_update(): ema_apply_op = ema.apply([batch_mean]) with tf.control_dependencies([ema_apply_op]): return tf.identity(batch_mean) mean = tf.cond(phase_train, mean_var_with_update, lambda: (ema.average(batch_mean))) return mean
Example #21
Source File: tf_util.py From Geo-CNN with Apache License 2.0 | 5 votes |
def batch_norm_for_conv1d(inputs, is_training, bn_decay, scope, data_format): """ Batch normalization on 1D convolutional maps. Args: inputs: Tensor, 3D BLC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope data_format: 'NHWC' or 'NCHW' Return: normed: batch-normalized maps """ return batch_norm_template(inputs, is_training, scope, [0,1], bn_decay, data_format)
Example #22
Source File: tf_util.py From SpiderCNN with MIT License | 5 votes |
def batch_norm_template(inputs, is_training, scope, moments_dims, bn_decay): """ Batch normalization on convolutional maps and beyond... Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow Args: inputs: Tensor, k-D input ... x C could be BC or BHWC or BDHWC is_training: boolean tf.Varialbe, true indicates training phase scope: string, variable scope moments_dims: a list of ints, indicating dimensions for moments calculation bn_decay: float or float tensor variable, controling moving average weight Return: normed: batch-normalized maps """ with tf.variable_scope(scope) as sc: num_channels = inputs.get_shape()[-1].value beta = tf.Variable(tf.constant(0.0, shape=[num_channels]), name='beta', trainable=True) gamma = tf.Variable(tf.constant(1.0, shape=[num_channels]), name='gamma', trainable=True) batch_mean, batch_var = tf.nn.moments(inputs, moments_dims, name='moments') decay = bn_decay if bn_decay is not None else 0.9 ema = tf.train.ExponentialMovingAverage(decay=decay) # Operator that maintains moving averages of variables. ema_apply_op = tf.cond(is_training, lambda: ema.apply([batch_mean, batch_var]), lambda: tf.no_op()) # Update moving average and return current batch's avg and var. def mean_var_with_update(): with tf.control_dependencies([ema_apply_op]): return tf.identity(batch_mean), tf.identity(batch_var) # ema.average returns the Variable holding the average of var. mean, var = tf.cond(is_training, mean_var_with_update, lambda: (ema.average(batch_mean), ema.average(batch_var))) normed = tf.nn.batch_normalization(inputs, mean, var, beta, gamma, 1e-3) return normed
Example #23
Source File: architecture.py From MHE with MIT License | 5 votes |
def batch_norm(self, x, n_out, phase_train): """ 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 n_out: 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'): gamma = self.get_bias(n_out, 1.0, 'gamma') beta = self.get_bias(n_out, 0.0, 'beta') batch_mean, batch_var = tf.nn.moments(x, [0,1,2], name='moments') ema = tf.train.ExponentialMovingAverage(decay=0.999) 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))) return tf.nn.batch_normalization(x, mean, var, beta, gamma, 1e-3)
Example #24
Source File: tf_util.py From pointnetvlad with MIT License | 5 votes |
def batch_norm_for_conv3d(inputs, is_training, bn_decay, scope): """ Batch normalization on 3D convolutional maps. Args: inputs: Tensor, 5D BDHWC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope Return: normed: batch-normalized maps """ return batch_norm_template(inputs, is_training, scope, [0,1,2,3], bn_decay)
Example #25
Source File: tf_util.py From pointnetvlad with MIT License | 5 votes |
def batch_norm_for_conv2d(inputs, is_training, bn_decay, scope): """ Batch normalization on 2D convolutional maps. Args: inputs: Tensor, 4D BHWC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope Return: normed: batch-normalized maps """ return batch_norm_template(inputs, is_training, scope, [0,1,2], bn_decay)
Example #26
Source File: tf_util.py From pointnetvlad with MIT License | 5 votes |
def batch_norm_for_conv1d(inputs, is_training, bn_decay, scope): """ Batch normalization on 1D convolutional maps. Args: inputs: Tensor, 3D BLC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope Return: normed: batch-normalized maps """ return batch_norm_template(inputs, is_training, scope, [0,1], bn_decay)
Example #27
Source File: tf_util.py From pointnetvlad with MIT License | 5 votes |
def batch_norm_for_fc(inputs, is_training, bn_decay, scope): """ Batch normalization on FC data. Args: inputs: Tensor, 2D BxC input is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope Return: normed: batch-normalized maps """ return batch_norm_template(inputs, is_training, scope, [0,], bn_decay)
Example #28
Source File: tf_util.py From pointnetvlad with MIT License | 5 votes |
def batch_norm_template(inputs, is_training, scope, moments_dims, bn_decay): """ Batch normalization on convolutional maps and beyond... Ref.: http://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow Args: inputs: Tensor, k-D input ... x C could be BC or BHWC or BDHWC is_training: boolean tf.Varialbe, true indicates training phase scope: string, variable scope moments_dims: a list of ints, indicating dimensions for moments calculation bn_decay: float or float tensor variable, controling moving average weight Return: normed: batch-normalized maps """ with tf.variable_scope(scope) as sc: num_channels = inputs.get_shape()[-1].value beta = tf.Variable(tf.constant(0.0, shape=[num_channels]), name='beta', trainable=True) gamma = tf.Variable(tf.constant(1.0, shape=[num_channels]), name='gamma', trainable=True) batch_mean, batch_var = tf.nn.moments(inputs, moments_dims, name='moments') decay = bn_decay if bn_decay is not None else 0.9 ema = tf.train.ExponentialMovingAverage(decay=decay) # Operator that maintains moving averages of variables. ema_apply_op = tf.cond(is_training, lambda: ema.apply([batch_mean, batch_var]), lambda: tf.no_op()) # Update moving average and return current batch's avg and var. def mean_var_with_update(): with tf.control_dependencies([ema_apply_op]): return tf.identity(batch_mean), tf.identity(batch_var) # ema.average returns the Variable holding the average of var. mean, var = tf.cond(is_training, mean_var_with_update, lambda: (ema.average(batch_mean), ema.average(batch_var))) normed = tf.nn.batch_normalization(inputs, mean, var, beta, gamma, 1e-3) return normed
Example #29
Source File: tf_util.py From Geo-CNN with Apache License 2.0 | 5 votes |
def batch_norm_for_conv2d(inputs, is_training, bn_decay, scope, data_format): """ Batch normalization on 2D convolutional maps. Args: inputs: Tensor, 4D BHWC input maps is_training: boolean tf.Varialbe, true indicates training phase bn_decay: float or float tensor variable, controling moving average weight scope: string, variable scope data_format: 'NHWC' or 'NCHW' Return: normed: batch-normalized maps """ return batch_norm_template(inputs, is_training, scope, [0,1,2], bn_decay, data_format)
Example #30
Source File: nn_layers.py From DeepLoc with BSD 3-Clause "New" or "Revised" License | 5 votes |
def batch_norm_fc(x, n_out, phase_train, scope='bn'): """ Batch normalization on convolutional maps. Args: x: Tensor, 4D BHWD input maps n_out: 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(scope): beta = tf.Variable(tf.constant(0.0, shape=[n_out]), name='beta', trainable=True) gamma = tf.Variable(tf.constant(1.0, shape=[n_out]), 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