[c++] how to show data image from batch

Hi, I am trying to make a classification with custom image data.

I made a dataloader like as below a input data part.

std::vector<torch::Tensor> process_images(std::vector<std::string> list_images)
{
	std::vector<torch::Tensor> tensor_images;
	for (auto image : list_images)
	{
		cv::Mat img = cv::imread(image);
		cv::resize(img, img, cv::Size(224, 224));

		torch::Tensor tensor_image = torch::from_blob(img.data, { img.rows, img.cols,3 }, at::kByte);
		tensor_image = tensor_image.toType(at::kFloat);
		tensor_image = tensor_image.div_(255);

		tensor_image = tensor_image.permute({ 2, 0, 1 });
		tensor_images.push_back(tensor_image);
	}
	return tensor_images;
}

and in the evaluation part, I wrote code like this.

for (torch::data::Example<torch::Tensor, torch::Tensor>& batch : *data_loader_val) {
	auto data = batch.data.to(device);
	auto targets = batch.target.to(device);

	torch::Tensor outputs = resnet.forward(data);
	data = data.cpu().contiguous();
	data = data.permute({ 0, 2, 3, 1 });
	float* gt = data.data_ptr<float>();

	char name[80];
	std::cout << outputs.sizes()[0] << std::endl;
	for (auto i = 0; i < outputs.sizes()[0]; i++)
	{
		auto gttmp = gt + i * 224 * 224 * 3;
		cv::Mat gtmat(224, 224, CV_32FC3, gttmp);
		cv::cvtColor(gtmat, gtmat, cv::COLOR_BGR2RGB);
		gtmat.convertTo(gtmat, CV_8UC3, 255);

		sprintf_s(name, "gt%d", i);
		cv::imshow(name, gtmat);

		std::cout << targets[i].item<int64_t>() << " ";
	}
	cv::waitkey(0);
}

But I’ve got the image not the color and not the original one. They are cloned one to 9 images.
image

How can I see that properly?

The output looks interleaved, so maybe you need to call contiguous() after permuting the image to channels-last and before creating the OpenCV mats.