pythontensorflowloggingtensorflow-estimator

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?


Solution

  • 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.