Convert Libtorch torch::Tensor to juce::image and like back

I is use Libtorch for process image, OpenCV very large so try avoid.
This i try make use:

Not able to convert torch::Tensor to juce::image.
I want to read a Video file, split into images on the fly and apply Deep Learning algorithm on image in Libtorch, then turn it back to image JUCE can understand. Anyone is have example make like this?

Thanks you,

Really help is needed. I have this, first to oepncv and then to juce::image (still crash). Any better way?

cv::Mat toOpenCV(at::Tensor out_tensor, int h, int w, int c)
  out_tensor = out_tensor.squeeze().permute({1, 2, 0});
  cout << "out_tensor " << out_tensor << "\n";
  out_tensor = out_tensor.mul(255).clamp(0, 255).to(torch::kU8);
//  out_tensor =;
  cout << "out_tensor " << out_tensor << "\n";
  cv::Mat resultImg(h, w, CV_8UC3);
  // cv::Mat resultImg(h, w, CV_8UC1);  
  std::memcpy((void *), out_tensor.data_ptr(), sizeof(torch::kU8) * out_tensor.numel());
  return resultImg;

juce::Image toJUCEImage(cv::Mat original,int h, int w, int c)
    juce::Image image(juce::Image::RGB, h, w, false);

    const size_t number_of_bytes_to_copy = 3 * w; // times 3 since each pixel contains 3 bytes (RGB)
    juce::Image::BitmapData bitmap_data(image, 0, 0, h,w, juce::Image::BitmapData::ReadWriteMode::writeOnly);
    for (int row_index = 0; row_index < h; row_index ++)
        uint8_t * src_ptr = original.ptr(row_index);
        uint8_t * dst_ptr = bitmap_data.getLinePointer(row_index);

        std::memcpy(dst_ptr, src_ptr, number_of_bytes_to_copy);

    return image;

Is have answer here, if anyone else is needed this: