填充张量的示例代码
Example code for populating a tensor?
我不知道如何填充张量。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的例子
相关文章:
- 使用Pybind11向Python公开Eigen::张量
- C++中的张量流对象检测
- 在官方张量流 resnet50 模型上运行 tflite 精度工具
- PyTorch C++将数据转换为张量失败
- 如何使用 c++ 更改张量流中的per_process_gpu_memory_fraction?
- 编译 GPU 的张量流示例自定义操作
- 在 Torch C++ API 中,如何快速写入张量的内部数据?
- 如何在C++中将一个特征张量乘以另一个特征张量的标量和?
- C++ ABI 兼容性问题/张量流
- 如何从内存缓冲区加载张量流图
- PyTorch C++ 前端向前返回多个张量
- 从 std::向量值创建张量<Tensor>
- 张量流错误 此文件需要编译器和库支持 ISO C++ 2011 标准
- 如何将自定义特征张量类存储到 std::vector 中?
- CUDA 高效的 nd-array(张量)切片
- 部署在张量流中训练的神经网络来火炬C++的最佳方法是什么?
- 微调张量流对象检测预训练模型
- 如何在张量流内核代码中更改变量类型张量中的值
- 张量流内核代码修改
- 填充张量的示例代码