Search code examples
neural-networktensorflowpre-trained-model

Visualizing the features of a pretrained network in TensorFlow


For a medical application I am retraining the pretrained Inception-v3 network using TensorFlow.

This network has a final layer:

pool_3:0 (2048 features)

Using TF's classify_image, I figured out which of these features are most important for each sample. So there is an array with the indexes of the top-N features, sorted on weights.

The next step is to visualize the feature vector to better understand the results.

How would I go about doing this? Is TensorBoard capable of this? I am at a bit of a loss. Any suggestion/help is appreciated!


Solution

  • Maybe just printing the N interesting components would help you?

    You can get the pool_3 vector with something like:

    graph = ...   # the session graph (sess.graph) containing Inception model
    features = graph.get_tensor_by_name('inception_v3/pool3:0')  # I don't know the exact name, find it in TensorBoard
    features_values = sess.run(features)
    print features_values[top_N_indices]
    

    If you want to use TensorBoard, you can only plot:

    • scalar features (scalar summaries): you could plot each feature independently with this, using tf.gather(features, [indice])
    • histograms of activation: this will not be very useful I think but you can try it
    • images: you could maybe construct an image to plot containing the interesting features? That would be a bit complex, you can see this previous question, related to this issue and this tutorial