Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging long tensor values in tensorflow estimator

I have built a classification model using tensorflow estimator API. I am trying to get tensor outputs from hidden layes printed in logs while prediction using below code.

model = tf.estimator.DNNLinearCombinedClassifier(
        model_dir=model_dir,
        linear_feature_columns=wide_columns,
        dnn_feature_columns=deep_columns,
        dnn_hidden_units=hidden_units,
        config=run_config)
tensors_to_log = {"DenseOut": "dnn/logits/BiasAdd"}
logging_hook = tf.train.LoggingTensorHook(tensors=tensors_to_log, every_n_iter=1)
predictions = model.predict(train_input_fn, hooks=[logging_hook])

When i run the code I am able to get the tensors logged in output but since the value is very long it is truncated and i can only see few numbers in begining and end.

INFO:tensorflow:DenseOut = [[ 0.61572325 -0.44044942 -0.19232166 ...  0.04 0.605 0.15]]

How can I specify tensorflow to log the complete output?

like image 755
Ankit Goyal Avatar asked Aug 06 '26 03:08

Ankit Goyal


1 Answers

So interesting, I found that the solution was to set np.set_printoptions.

import numpy as np

np.set_printoptions(threshold=np.nan)

It seems that tensorflow and numpy are closely integrated.

like image 102
giser_yugang Avatar answered Aug 07 '26 18:08

giser_yugang