1

I've build a tensorflow model in Python to make image recognition but i would like to better understand how works my model. I would like to print values between each layers of my model.

I'm using TensorFlow 1.13.1 and Python 3.6.8.

# model with 2 hidden layers
print("Creating model and adding layers...")
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(256, activation='relu'))
model.add(tf.keras.layers.Dense(128, activation='relu')) # would like to know values before this layer
model.add(tf.keras.layers.Dense(2, activation='softmax'))

Thanks in advance,

2 Answers2

0

The best way (even if not exactly lightweight) is to use Tensorboard, which is made exactly for this purpose. You should create an image summary and feed the desired tensor (one of the way to get the desired tensor could be: tensor = model.layers[1].output as stated here).

With tensorboard you can show the weights, activations and whatever measure from your model directly during the training. Please refer to the tutorial in the link above for implementation details.

EdoG
  • 345
  • 1
  • 7
0

If only need to quickly validate some number in the terminal, use can use tf.print in the eager mode which just prints the values of the Tensor.

If you run the graph explicitly in session, use tf.Print. It creates an identity node in a graph and when the computation passes this node, it prints the values you provided.

Jindřich
  • 10,270
  • 2
  • 23
  • 44