MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / visualize_conv_activations

Function visualize_conv_activations

examples/basics/mnist-visualizations.py:38–63  ·  view source on GitHub ↗

Visualize activations for convolution layers. Remarks: This tries to place all activations into a square. Args: activation: tensor with the activation [B,H,W,C] name: label for tensorboard Returns: image of almost all activations

(activation, name)

Source from the content-addressed store, hash-verified

36
37
38def visualize_conv_activations(activation, name):
39 """Visualize activations for convolution layers.
40
41 Remarks:
42 This tries to place all activations into a square.
43
44 Args:
45 activation: tensor with the activation [B,H,W,C]
46 name: label for tensorboard
47
48 Returns:
49 image of almost all activations
50 """
51 import math
52 with tf.name_scope('visualize_act_' + name):
53 _, h, w, c = activation.get_shape().as_list()
54 rows = []
55 c_per_row = int(math.sqrt(c))
56 for y in range(0, c - c_per_row, c_per_row):
57 row = activation[:, :, :, y:y + c_per_row] # [?, H, W, 32] --> [?, H, W, 5]
58 cols = tf.unstack(row, axis=3) # [?, H, W, 5] --> 5 * [?, H, W]
59 row = tf.concat(cols, 1)
60 rows.append(row)
61
62 viz = tf.concat(rows, 2)
63 tf.summary.image('visualize_act_' + name, tf.expand_dims(viz, -1))
64
65
66class Model(ModelDesc):

Callers 1

build_graphMethod · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…