我已经使用 tensorflow estimator API 构建了一个分类模型。在使用以下代码进行预测时,我正在尝试从打印在日志中的隐藏层获取张量输出。
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])
当我运行代码时,我能够在输出中记录张量,但由于值很长,它被截断了,我只能看到开头和结尾的几个数字。
INFO:tensorflow:DenseOut = [[ 0.61572325 -0.44044942 -0.19232166 ... 0.04 0.605 0.15]]
如何指定 tensorflow 来记录完整的输出?
最佳答案
很有趣,我发现解决方案是设置np.set_printoptions
。
import numpy as np
np.set_printoptions(threshold=np.nan)
看来tensorflow
和numpy
是紧密结合的。
关于python - 在 tensorflow 估计器中记录长张量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53884698/