【问题标题】:Logging long tensor values in tensorflow estimator在张量流估计器中记录长张量值
【发布时间】:2018-12-21 12:18:24
【问题描述】:

我已经使用 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 来记录完整的输出?

【问题讨论】:

    标签: python tensorflow logging tensorflow-estimator


    【解决方案1】:

    太有趣了,我发现解决办法是设置np.set_printoptions。

    import numpy as np
    
    np.set_printoptions(threshold=np.nan)
    

    看来tensorflow和numpy是紧密结合的。

    【讨论】:

    • 效果很好。有道理,因为张量也基于 numpy 数组的顶部。非常感谢。
    【解决方案2】:

    试试这个:

        import sys
        import numpy as np
        np.set_printoptions(threshold= sys.maxsize)
    

    【讨论】:

      猜你喜欢
      • 2019-08-02
      • 2018-04-09
      • 1970-01-01
      • 2020-04-09
      • 2023-01-11
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多