You can create a new Tensor with desired shape, and just fill it out by iterating for all dims in for loops (to access individual item use operator()
of Eigen's TensorMap
which you can get by tensor<DataType,DIMS>
on Tensor
):
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;
}