I believe this line of code:
at::Tensor tensor_image = torch::from_blob(img.data, { 3, img.rows, img.cols}, at::kByte);

would interleave the tensor, since OpenCV would load the image in a channels-last memory layout, while you are loading it to a channels-first tensor_image, so you might need to load it as channels-last and permute it afterwards.
While this might be one issue, I don’t know why constant values (torch.ones) would also give other outputs, so there might be another error in the code.