【问题标题】:Issues printing an estimator.predict tensor打印 estimator.predict 张量的问题
【发布时间】:2018-02-05 07:30:35
【问题描述】:

我目前正在使用 tf 1.4,我需要帮助查看 tf.contrib.factorization.KMeansClustering 估计器的预测。我当前的代码段如下所示:

km = KMeansClustering(num_clusters=8,initial_clusters=KMeansClustering.KMEANS_PLUS_PLUS_INIT,model_dir=MODEL,relative_tolerance=0.01)

result = km.train(input_fn=lambda: gen_input(body))

input_fn = tf.estimator.inputs.pandas_input_fn(x={'x':tst}, shuffle=False)

y = result.predict(input_fn)

body 和 tst 是 pandas 数据帧。 print(y) 给:

<generator object Estimator.predict at 0x11ebecba0>

并尝试我搜索过的东西,例如调用 print(list(y))print(next(y)) 或遍历 y,例如:

for i in y:
    ...

for i in y.items():
    ...

for i in enumerate(y):
    ...

等,给出错误TypeError: data must be either a numpy array or pandas DataFrame if pandas is installed; got dict。我找不到任何其他方法可以尝试在线打印。谢谢

【问题讨论】:

    标签: python tensorflow tensorflow-estimator


    【解决方案1】:

    您的代码太少,无法确认有什么问题/缺失。此外,至少需要完整的堆栈跟踪。添加更多信息后,这个答案可能会很好。

    您是否期望对pandas_input_fn 的调用返回与您预期不同的内容?它返回一个带有签名()-&gt;(dict of features, target) 的函数,有关详细信息,请参阅docs

    另外,您似乎没有运行 TensorFlow session。在您这样做之前,所有张量、计算(在您的情况下为预测)等都只是图表的一部分,它们只有在运行 TF 会话后才会有值。

    请参阅这些docs 了解更多详情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 2020-12-17
      • 2017-01-14
      • 2019-08-13
      • 1970-01-01
      相关资源
      最近更新 更多