Skip to content

Instantly share code, notes, and snippets.

@Voyz
Voyz / gist:6d5619c86b326432b49d7d9c08c88240
Last active April 11, 2018 21:29
visualise features for tensorflow
# feature - the tensor you want to visualise in shape [num_examples, dimX, dimY, channels]. If dims are provided, the feature tensor can be flattened. Eg shape: [20, 7, 7, 16]
# grid - the dimensions of a grid on which the features will be displayed. Expects a touple (x,y) where x * y have to equal to channels of the feature. Eg, for 16 channels, grid=[4,4]
# dims (optional) - dimensions of each feature. Eg. for feature [20, 7, 7, 16], dims=[7,7] (although in non-flattened tensor the dims can be ommited)
# max_outputs - number of examples to draw
def visualise_feature(feature, grid, dims=None, max_outputs=10):
with tf.name_scope('Visualize_filters') as scope:
original_shape = feature.get_shape().as_list()
original_len = len(original_shape)