【问题标题】:How to output tensor flow prediction results in .csv?如何在 .csv 中输出张量流预测结果?
【发布时间】:2017-11-15 17:19:00
【问题描述】:

我正在使用 CNN 训练模型。

这是我在模型中的预测部分。

predictions = {
    "classes": tf.argmax(input=logit2, axis=1),
    "probabilities": tf.nn.softmax(logit2, name="softmax_tensor")
}

这是 main 中执行评估的代码。

eval_input_fn = tf.estimator.inputs.numpy_input_fn(
    x={"x": images_test},
    y=test_labels,
    num_epochs=1,
    shuffle=False)
eval_results = model.evaluate(input_fn=eval_input_fn)

我已经训练了我的模型,现在我有一个测试图像名称列表(在 csv 文件的第一列中),我想做出预测并将相应的结果输出到第二列(概率在 0 之间)和1),如何实现这一点,以及在哪里添加代码?

提前致谢。

【问题讨论】:

    标签: tensorflow computer-vision deep-learning


    【解决方案1】:

    Estimator 类有一个 predict function,它将预测作为可迭代对象返回(例如,scroll to the very bottom of this page)。

    所以你可以这样做:

    predictions = model.predict(input_fn=predict_input_fn)
    for p in predictions: 
      # write p['classes'] to the csv
    

    至于写入csv的第二列,看csvpython模块。

    【讨论】:

    • 谢谢!我对预测的类型感到困惑,这清楚了,我让事情变得复杂了。
    • 你知道如何将预测写入文件吗?即使文本文件有效,我在尝试执行 f.write(str(pre['probabilities'])+"\n") 时不断出错,使用 str() 或不使用两者都不起作用。谢谢!!!
    • 尝试写入文本文件时遇到什么错误?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2017-06-22
    • 2017-11-22
    相关资源
    最近更新 更多