打印权重与展示权重

layer1 = tf.layers.dense(inputs=x,
                         units=256,
                         activation=tf.nn.relu,
                         bias_initializer=tf.constant_initializer(0),
                         kernel_initializer=tf.truncated_normal_initializer(stddev=0.01),
                         kernel_regularizer = tf.contrib.layers.l1_regularizer(0.0003),
                         name= 'layer1'
                         )
with tf.variable_scope("layer1", reuse=True):
    w = tf.get_variable("kernel")
    b = tf.get_variable("bias")
    w = w.eval()
    b = b.eval()

需要先给网络层定义一个变量空间,然后使用tf.variable_scope获取该变量空间里面的变量。

通过图片显示权重:

from PIL import Image
img = Image.fromarray((w-w.min())/(w.max()-w.min())* 255.0)
img.show()

猜你喜欢

转载自www.cnblogs.com/Chen-rd/p/9171847.html