0

I'm following the Tensorflow Get Started tutorial at https://www.tensorflow.org/get_started/get_started_for_beginners (I am new to Tensorflow, apologies for lack of knowledge).

I created the neural network as per the tutorial and it runs correctly, now I would like to print out the tensor values at every layer during training. Is there an easy way to do this?

Here is the code:

# Fetch the data
(train_x, train_y), (test_x, test_y) = iris_data.load_data()

# Feature columns describe how to use the input.
my_feature_columns = []
for key in train_x.keys():
    my_feature_columns.append(tf.feature_column.numeric_column(key=key))

# Build 2 hidden layer DNN with 10, 10 units respectively.
classifier = tf.estimator.DNNClassifier(
    feature_columns=my_feature_columns,
    # Two hidden layers of 10 nodes each.
    hidden_units=[10, 10],
    # The model must choose between 3 classes.
    n_classes=3)

# Train the Model.
classifier.train(
    input_fn=lambda:iris_data.train_input_fn(train_x, train_y,
                                             args.batch_size),
    steps=args.train_steps)

# Evaluate the model.
....

Ideally, I would like to get the value of the hidden layers after every epoch. Any insight is greatly appreciated.

Alan Wang
  • 153
  • 2
  • 9
  • Hint: tensor values make sense only in session, when there's some input – Maxim Feb 08 '18 at 18:45
  • call `print([(node.name, sess.run(node.values())) for node in sess.graph.get_operations()])` to all tensors – Patwie Feb 08 '18 at 20:12
  • My confusion comes from the fact that there is no Session being created in the example code, instead it simply creates a classifier and trains the classifier with a chosen dataset. To clarify, I wish to get the output of each layer in the neural network during training, not after. – Alan Wang Feb 11 '18 at 06:52
  • Your question is still not well constructed. Lay out the problem before the sharing the code. Beyond the ["How to ask"](https://stackoverflow.com/help/how-to-ask) advice, you also need to start by stating the question in a way that focuses on what gap remains _after_ your research. Then describe your strategy thus far, code setup + conditions, and the errors/issues. Also state 'obvious' context that you already know, so that people understand what you have tried. See also [1](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/), [2](https://stackoverflow.com/help/mcve) – New Alexandria Feb 11 '18 at 18:40

0 Answers0