本文整理汇总了Python中tflib.param方法的典型用法代码示例。如果您正苦于以下问题:Python tflib.param方法的具体用法?Python tflib.param怎么用?Python tflib.param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tflib
的用法示例。
在下文中一共展示了tflib.param方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Layernorm
# 需要导入模块: import tflib [as 别名]
# 或者: from tflib import param [as 别名]
def Layernorm(name, norm_axes, inputs):
mean, var = tf.nn.moments(inputs, norm_axes, keep_dims=True)
# Assume the 'neurons' axis is the first of norm_axes. This is the case for fully-connected and BCHW conv layers.
n_neurons = inputs.get_shape().as_list()[norm_axes[0]]
offset = lib.param(name+'.offset', np.zeros(n_neurons, dtype='float32'))
scale = lib.param(name+'.scale', np.ones(n_neurons, dtype='float32'))
# Add broadcasting dims to offset and scale (e.g. BCHW conv data)
offset = tf.reshape(offset, [-1] + [1 for i in xrange(len(norm_axes)-1)])
scale = tf.reshape(scale, [-1] + [1 for i in xrange(len(norm_axes)-1)])
result = tf.nn.batch_normalization(inputs, mean, var, offset, scale, 1e-5)
return result
示例2: Layernorm
# 需要导入模块: import tflib [as 别名]
# 或者: from tflib import param [as 别名]
def Layernorm(name, norm_axes, inputs):
mean, var = tf.nn.moments(inputs, norm_axes, keep_dims=True)
# Assume the 'neurons' axis is the first of norm_axes. This is the case for fully-connected and BCHW conv layers.
n_neurons = inputs.get_shape().as_list()[norm_axes[0]]
offset = lib.param(name+'.offset', np.zeros(n_neurons, dtype='float32'))
#offset = np.zeros(n_neurons, dtype='float32')
scale = lib.param(name+'.scale', np.ones(n_neurons, dtype='float32'))
#scale = np.ones(n_neurons, dtype='float32')
# Add broadcasting dims to offset and scale (e.g. BCHW conv data)
offset = tf.reshape(offset, [-1] + [1 for i in range(len(norm_axes)-1)])
scale = tf.reshape(scale, [-1] + [1 for i in range(len(norm_axes)-1)])
result = tf.nn.batch_normalization(inputs, mean, var, offset, scale, 1e-5)
return result
示例3: Batchnorm
# 需要导入模块: import tflib [as 别名]
# 或者: from tflib import param [as 别名]
def Batchnorm(name, axes, inputs, is_training=None, stats_iter=None, update_moving_stats=True, fused=True, labels=None, n_labels=None):
"""conditional batchnorm (dumoulin et al 2016) for BCHW conv filtermaps"""
if axes != [0,2,3]:
raise Exception('unsupported')
#pdb.set_trace()
mean, var = tf.nn.moments(inputs, axes, keep_dims=True)
shape = mean.get_shape().as_list() # shape is [1,n,1,1]
offset_m = lib.param(name+'.offset', np.zeros([n_labels,shape[1]], dtype='float32'))
scale_m = lib.param(name+'.scale', np.ones([n_labels,shape[1]], dtype='float32'))
moving_mean_m = lib.param(name+'.moving_mean', np.zeros([n_labels,shape[1]], dtype='float32'), trainable=False)
moving_variance_m = lib.param(name+'.moving_variance', np.ones([n_labels,shape[1]], dtype='float32'), trainable=False)
offset = tf.nn.embedding_lookup(offset_m, labels)
scale = tf.nn.embedding_lookup(scale_m, labels)
result = tf.nn.batch_normalization(inputs, mean, var, offset[:,:,None,None], scale[:,:,None,None], 1e-5)
return result
示例4: Layernorm
# 需要导入模块: import tflib [as 别名]
# 或者: from tflib import param [as 别名]
def Layernorm(name, norm_axes, inputs):
mean, var = tf.nn.moments(inputs, norm_axes, keep_dims=True)
# Assume the 'neurons' axis is the first of norm_axes. This is the case for fully-connected and BCHW conv layers.
n_neurons = inputs.get_shape().as_list()[norm_axes[0]]
offset = lib.param(name+'.offset', np.zeros(n_neurons, dtype='float32'))
scale = lib.param(name+'.scale', np.ones(n_neurons, dtype='float32'))
# Add broadcasting dims to offset and scale (e.g. BCHW conv data)
offset = tf.reshape(offset, [-1] + [1 for i in xrange(len(norm_axes)-1)])
scale = tf.reshape(scale, [-1] + [1 for i in xrange(len(norm_axes)-1)])
result = tf.nn.batch_normalization(inputs, mean, var, offset, scale, 1e-5)
return result
# not working yet
示例5: Layernorm_cond
# 需要导入模块: import tflib [as 别名]
# 或者: from tflib import param [as 别名]
def Layernorm_cond(name, norm_axes, inputs, labels, n_labels):
mean, var = tf.nn.moments(inputs, norm_axes, keep_dims=True)
# Assume the 'neurons' axis is the first of norm_axes. This is the case for fully-connected and BCHW conv layers.
n_neurons = inputs.get_shape().as_list()[norm_axes[0]]
offset_m = lib.param(name+'.offset', np.zeros([n_labels,n_neurons], dtype='float32'))
scale_m = lib.param(name+'.scale', np.ones([n_labels,n_neurons], dtype='float32'))
offset = tf.nn.embedding_lookup(offset_m, labels)
scale = tf.nn.embedding_lookup(scale_m, labels)
# Add broadcasting dims to offset and scale (e.g. BCHW conv data)
offset = tf.reshape(offset, [-1] + [1 for i in xrange(len(norm_axes)-1)])
scale = tf.reshape(scale, [-1] + [1 for i in xrange(len(norm_axes)-1)])
result = tf.nn.batch_normalization(inputs, mean, var, offset, scale, 1e-5)
return result
示例6: Layernorm
# 需要导入模块: import tflib [as 别名]
# 或者: from tflib import param [as 别名]
def Layernorm(name, norm_axes, inputs):
mean, var = tf.nn.moments(inputs, norm_axes, keep_dims=True)
# Assume the 'neurons' axis is the first of norm_axes. This is the case for fully-connected and BCHW conv layers.
n_neurons = inputs.get_shape().as_list()[norm_axes[0]]
offset = lib.param(name+'.offset', np.zeros(n_neurons, dtype='float32'))
scale = lib.param(name+'.scale', np.ones(n_neurons, dtype='float32'))
# Add broadcasting dims to offset and scale (e.g. BCHW conv data)
offset = tf.reshape(offset, [-1] + [1 for i in range(len(norm_axes)-1)])
scale = tf.reshape(scale, [-1] + [1 for i in range(len(norm_axes)-1)])
result = tf.nn.batch_normalization(inputs, mean, var, offset, scale, 1e-5)
return result
示例7: Batchnorm
# 需要导入模块: import tflib [as 别名]
# 或者: from tflib import param [as 别名]
def Batchnorm(name, axes, inputs, is_training=None, stats_iter=None, update_moving_stats=True, fused=True, labels=None, n_labels=None):
"""conditional batchnorm (dumoulin et al 2016) for BCHW conv filtermaps"""
if axes != [0,2,3]:
raise Exception('unsupported')
mean, var = tf.nn.moments(inputs, axes, keep_dims=True)
shape = mean.get_shape().as_list() # shape is [1,n,1,1]
offset_m = lib.param(name+'.offset', np.zeros([n_labels,shape[1]], dtype='float32'))
scale_m = lib.param(name+'.scale', np.ones([n_labels,shape[1]], dtype='float32'))
offset = tf.nn.embedding_lookup(offset_m, labels)
scale = tf.nn.embedding_lookup(scale_m, labels)
result = tf.nn.batch_normalization(inputs, mean, var, offset[:,:,None,None], scale[:,:,None,None], 1e-5)
return result