I want to convert th result torch::tensor to cv::Mat using the follow code, but the  resultImg is wrong.I have checked the tensor result.It is right
torch::Tensor out_tensor = module->forward(inputs).toTensor(); assert(out_tensor.device().type() == torch::kCUDA); out_tensor=out_tensor.to(torch::kCPU); out_tensor=out_tensor.squeeze().detach(); out_tensor=out_tensor.permute({1,2,0}); out_tensor=out_tensor.mul(255).clamp(0,255).to(torch::kInt);
cv::Mat resultImg(512, 512,CV_8UC3,(void*)out_tensor.data_ptr());
Of course, I can get the correct image result like this:
for(int y=0;y<512;++y)
for(int x=0;x<512;++x)
for(int c=0;c<3;++c)
{
int val=(*(out_tensor[y][x][c]).data<int>());
testImg.at< cv::Vec3b>(y,x)[c]=val;
}
But this way is too slow.I want to know the efficient method ，any advise is appreciated