def _build(self):
"""Build the linear layer.
Two parameters: weight and bias.
:return: None.
"""
bound = math.sqrt(6.0 / (self._input_size + self._output_size))
w_init = tf.random_uniform(
minval=-bound,
maxval=bound,
shape=(self._input_size, self._output_size),
dtype=D_TYPE,
name='w_init'
)
self._w = tf.Variable(w_init, dtype=D_TYPE, name='w')
if self._with_bias:
b_init = tf.zeros(
shape=(self._output_size,),
dtype=D_TYPE,
name='b_init'
)
self._b = tf.Variable(b_init, dtype=D_TYPE, name='b')
else:
self._b = None
self._batch_norm = BatchNorm('bn', self._output_size) if self._with_batch_norm else None
评论列表
文章目录