python - 在 tensorflow 估计器中记录长张量值

标签 python tensorflow logging tensorflow-estimator

我已经使用 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)

看来tensorflownumpy是紧密结合的。

关于python - 在 tensorflow 估计器中记录长张量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53884698/

相关文章:

machine-learning - 深度学习 - 如何为大型分类集准备训练数据?

python - Tensorflow 预测总是相同的结果

python - 使用多核的 Numpy np.einsum 数组乘法

Python 3.5 不打开 zip 文件

Python - 查找字符串中字符串列表第一次出现的索引位置

tensorflow - Python Keras : An layer output exactly the same thing as input

java - JBoss 在托管事务时提交事务

Grails 日志记录 - 是否有任何现有的解决方案能够记录实际发生调用的文件 + 行?

python - 在 GUI 记录器中添加颜色

python - 使用 vispy/scipy 时无法卡住应用程序