def _fc(self, x, fan_in, fan_out, layer_name, activation=None, L2=1, use_bias=True,
wmin=None,wmax=None,analysis=False):
show_weight = self.flags.visualize and 'weight' in self.flags.visualize
if wmin is not None or wmax is not None:
use_bias = False
assert wmin is not None and wmax is not None
with tf.variable_scope(layer_name.split('/')[-1]):
w,b = self._get_fc_weights(fan_in, fan_out, layer_name)
if wmin is not None:
wr = wmax-wmin
w = self._activate(w,'sigmoid')*wr+wmin
#w = tf.clip_by_value(w,wmin,wmax)
net = tf.matmul(x,w)
if use_bias:
net = tf.nn.bias_add(net, b)
net = self._activate(net, activation)
if show_weight:
tf.summary.histogram(name='W', values=w, collections=[tf.GraphKeys.WEIGHTS])
if use_bias:
tf.summary.histogram(name='bias', values=b, collections=[tf.GraphKeys.WEIGHTS])
if analysis:
net1 = tf.expand_dims(x,2)*tf.expand_dims(w,0)
#net1 = tf.reshape(net1,[tf.shape(x)[0],fan_in*fan_out])
return net,net1
return net
评论列表
文章目录