Hi, there. I am trying to implement the cpp example in the docs/how_to/deploy.md, by running the compiled modules using TVM c++ API, and facing the error regarding the input data.
In the example, it loads the binary input data by
DLTensor* x;
int in_ndim = 4;
int64_t in_shape[4] = {1, 3, 224, 224};
TVMArrayAlloc(in_shape, in_ndim, dtype_code, dtype_bits, dtype_lanes, device_type, device_id, &x);
// load image data saved in binary
std::ifstream data_fin("cat.bin", std::ios::binary);
data_fin.read(static_cast<char*>(x->data), 3 * 224 * 224 * 4);
In my case, I won’t use binary data, but the Mat data from opencv instead (I don’t find the “cat.bin” from the project either). Here is the way I do:
cv::Mat img = cv::imread("test.jpg");
cv::Mat resized_img;
cv::resize(img, resized_img, cv::Size(224,224));
memcpy(static_cast<unsigned char*>(x->data), resized_img.data, 3*224*224);
Since the resized_img.data
is in uchar*
format, x->data
was converted to uchar*
as well.
But it gives ‘Segmentation fault (core dumped)’ error while running the memcpy
command.
Here are my two questions:
- For the cat.bin data, why the data length is
3*224*224*4
? More specific, what does the fourth dimension ‘4’ represent here? (generally,3 (channels) * 224 (width) * 224 (height) * 1 (sizeof(uchar/char))
, right?) - What’s the correct way to set the x->data if using the image data from Mat format?
Thanks!