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)
| 36 | |
| 37 | |
| 38 | def 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 | |
| 66 | class Model(ModelDesc): |
no test coverage detected
searching dependent graphs…