The problem with your images may be resolved by changing the way you convert the cv::Mat to a torch::Tensor, e.g.
// Replace this
torch::Tensor tensor_image = torch::from_blob(img.data, { img.rows, img.cols,1}, at::kFloat);
// By this
torch::Tensor tensor_image = torch::from_blob(img.data, { img.rows, img.cols,1}, at::kByte);

Unless your images are somehow stored as float