【问题标题】:Using ClientSession::Run and ClientSession:FeedType in tensorflow在张量流中使用 ClientSession::Run 和 ClientSession:FeedType
【发布时间】:2017-06-26 08:50:32
【问题描述】:

我是 Tensorflow 和机器学习的新手,我正在尝试使用 C++ API 创建一个单层全连接神经网络来识别 MNIST 数据库中的数字。

在官方文档中,是这样的用例:

Status Run(
  const FeedType & inputs,
  const std::vector< Output > & fetch_outputs,
  std::vector< Tensor > *outputs
) const

FeedType 是std::unordered_map&lt; Output, Input::Initializer, OutputHash &gt; FeedType

我需要输入两个数据集:图像 ([][784]) 和预期结果 ([][10]) 以便对其进行训练。

谁能给我一个应该怎么做的例子?

【问题讨论】:

    标签: c++ tensorflow


    【解决方案1】:

    我在 API 的源代码中找到了解决方案:提供数据应该如下所示:

    ClientSession::FeedType feed;
    Tensor m_tensor(DT_FLOAT, TensorShape({length}));
    //length is an int representing the dimension of the tensor
    for(int i = 0 ; i < length ; i++){
         data[i] = m[i]; //m is where your feed data is
    }
    feed.insert({x, m_tensor}); //x is a placeholder
    

    但是,这是一个可以编译的解决方案,因为我仍然停留在几个方面,我还没有测试它是否也能按预期工作。我为糟糕的格式道歉。

    【讨论】:

    • 我已经编译并运行了它,这个解决方案有效,但我不能保证它是最好的方法。
    猜你喜欢
    • 2016-12-23
    • 2018-06-09
    • 2018-09-16
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多