填充张量的示例代码

Example code for populating a tensor?

本文关键字:代码 张量 填充      更新时间:2023-10-16

我不知道如何填充张量。API没有很好地记录…

我想有一个这样的函数。

std::tuple<std::string, double> CNNLocalizer::runImage()
{
  std::tuple<std::string, double> result;
  result.get<0> = "none";
  result.get<1> = 0.0;
  if (g_got_image_)
  {
    std::string label;
    // create a tensorflow::Tensor with the image information
    tensorflow::TensorShape image_shape;
    image_shape.AddDim(g_img_height_);
    image_shape.AddDim(g_img_width_);
    tensorflow::Tensor input_image(tensorflow::DT_INT8, image_shape);
    // I have no idea how to make this work right now.  Copying data is very confusing..
    for (uint i = 0; i < g_img_height_; i++)
    {
      for (uint j = 0; j < g_img_width_; j++)
      {
        // ??  Populate a matrix or something?
      }
    }
    // Copy the matrix into the tensor?
    // input_image.matrix<float>()() = z;
  }
  return result;
}

知道如何填充张量的矩阵部分吗?我发现一个矩阵()函数,返回某种类型定义的特征张量对象-这是要走的路吗?

任何帮助将不胜感激!谢谢!

您可以使用Tensor::FromProto。否则,您最好使用Tensor::flat<int8>。有CSV或PNG的例子