将向量<张量流::张量>转换为张量的张量
Converting a vector<tensorflow::Tensor> to tensor of tensors
假设我有一个图像张量的向量,每个图像张量的维度为[frames,height,width,num_channels],我想取该向量并将其转换为[num_tracks(向量的大小(,frames,high,widght,num_cannels]的一个更大的张量。使用tensorflow最简单的方法是什么::Tensorapi?这是为了构造图的输入张量,而不是在图执行本身中。
谢谢!
您可以创建一个具有所需形状的新张量,并通过迭代循环中的所有dims来填充它(要访问单个项目,请使用Eigen的TensorMap
的operator()
,您可以通过Tensor
上的tensor<DataType,DIMS>
获得(:
tensorflow::Tensor concat(const std::vector<tensorflow::Tensor>& in){
int frames = in[0].dim_size(0);
int height = in[0].dim_size(1);
int width = in[0].dim_size(2);
int num_channels = in[0].dim_size(3);
int num_tracks = in.size();
tensorflow::Tensor res(DT_FLOAT,tensorflow::TensorShape{num_tracks,frames,height,width,num_channels});
auto& resMap = res.tensor<float,5>();
for (int nt = 0; nt < num_tracks; ++nt) {
auto& inFrame = in[nt];
auto& inMap = inFrame.tensor<float,4>(); // Eigen's TensorMap which has operator()(Indices...)
for (int f = 0; f < frames; ++f) {
for (int r = 0; r < height; ++r) {
for (int c = 0; c < width; ++c) {
for (int ch = 0; ch < num_channels; ++ch) {
resMap(nt,f,r,c,ch) = inMap(f,r,c,ch);
}
}
}
}
}
return res;
}
相关文章:
- 使用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++的最佳方法是什么?
- 微调张量流对象检测预训练模型
- 将可变大小的 TensorFlow 张量转换为 std::vector(C++)
- 如何将张量转换为图像数组
- 如何将CVPixelBufferRef转换为张量