code: def visualize_conv_activations(activation, name):
      """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
      """
      import math
  
      with tf.name_scope("visualize_act_" + name):
          _, h, w, c = activation.get_shape().as_list()
          rows = []
          c_per_row = int(math.sqrt(c))
          for y in range(0, c - c_per_row, c_per_row):
              row = activation[
                  :, :, :, y : y + c_per_row
              ]  # [?, H, W, 32] --> [?, H, W, 5]
              cols = tf.unstack(
                  row, axis=3
              )  # [?, H, W, 5] --> 5 * [?, H, W]
              row = tf.concat(cols, 1)
              rows.append(row)
  
          viz = tf.concat(rows, 2)
      tf.summary.image("visualize_act_" + name, tf.expand_dims(viz, -1))
  
file_path: tensorpack/examples/basics/mnist-visualizations.py
imports: from tensorpack import tfv1
  from tensorpack import *
  from tensorpack.dataflow import dataset
label_desc: Use image node_id 2 for calling a global function with example usage: visualize_conv_activations(activation, name) without return types