How torch::from_blob return a tensor from a batch images? I just put image tensor to a vector one by one, but call forward, an exception is thrown. My code is as follows:
std::vectortorch::jit::IValue input_tensor;
for (auto file : files)
{
Mat img = imread(file);
if (img.empty())
{
GNLOG(GN_WARNING) << “Can’t read image data from file”;
continue;
}
cv::cvtColor(img, img, COLOR_BGR2RGB);
cv::Size scale(kIMAGE_SIZE, kIMAGE_SIZE);
cv::resize(img, img, scale);

// convert [unsigned int] to [float]
img.convertTo(img, CV_32FC3, 1.0f / 255.0f);

auto img_tensor = torch::from_blob(
		img.data, {1, kIMAGE_SIZE, kIMAGE_SIZE, kCHANNELS});
img_tensor = img_tensor.permute({0, 3, 1, 2});
img_tensor[0][0] = img_tensor[0][0].sub_(0.4914).div_(0.2023);
img_tensor[0][1] = img_tensor[0][1].sub_(0.4822).div_(0.1994);
img_tensor[0][2] = img_tensor[0][2].sub_(0.4465).div_(0.2010);

img_tensor = img_tensor.to(device_type_);
input_tensor.push_back(img_tensor);

}
torch::Tensor out_tensor = model_->forward(input_tensor).toTensor();