def weight_variable(shape, name, var_type='normal', const=1):
"""Initializes a tensorflow weight variable.
Args:
shape: An array representing shape of the weight variable
name: A string name given to the variable.
var_type: can be either 'normal', for weights following a Gaussian
distribution around 0, or 'xavier', for the Xavier method
const: Numeric value that controls the range of the weights within
the Xavier method.
Returns: Tensor variable for the weights
"""
if var_type == 'xavier':
""" Xavier initialization of network weights.
Taken from: https://gist.github.com/blackecho/3a6e4d512d3aa8aa6cf9
https://stackoverflow.com/questions/33640581/how-to-do-xavier-initialization-on-tensorflow
"""
assert len(shape) == 2
low = -const * np.sqrt(6.0 / (shape[0] + shape[1]))
high = const * np.sqrt(6.0 / (shape[0] + shape[1]))
initial = tf.random_uniform((shape[0], shape[1]), minval=low, maxval=high)
else:
initial = tf.truncated_normal(shape, stddev=1.0 / math.sqrt(float(shape[0])), dtype=tf.float32)
return tf.Variable(initial, name=name)
multimodal_autoencoder.py 文件源码
python
阅读 32
收藏 0
点赞 0
评论 0
评论列表
文章目录