just in case anyone stumbles upon this, here are convertion functions for you
H - height
W - width
C - channels
torch::Tensor matToTensor(cv::Mat const& src)
{
   torch::Tensor out;
	cv::Mat img_float;
	src.convertTo(img_float, CV_32F);

	out = torch::zeros({ src.rows, src.cols, src.channels() });
   // stride=width*channels
	memcpy(out.data_ptr(), src.data, out.numel() * sizeof(float));
	out = out.permute({ 2, 0, 1 }); // H, W, C --> C, H, W
   return out;
}

// MODIFIES original tensor so that theres no need of clone()
cv::Mat tensorToMat(torch::Tensor t)
{
   cv::Mat img;
   t = t.mul(255).to(torch::kByte).cpu();

   // input needs to be C, H, W
   std::vector<cv::Mat> vm;
   for(auto i : lz::range(t.size(0))){
      auto yo = t[i];
      uchar* data = (uint8_t*)(yo.data_ptr());
      img = cv::Mat(t.size(1), t.size(2), CV_8UC1, data);
   }

   return img.clone(); // needs to clone because the data is taken directly from tensor
}