serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
779 stars 177 forks source link

How to run a model with Opencv and CHW format? #157

Closed louisme87 closed 1 year ago

louisme87 commented 2 years ago

Hello, I'm using cppflow recently and has some questions. Here is part of my code, and I don't know how to parse the opencv's Mat image to Tensor.

img = imread("123.jpg");
resize(img, resized_img, Size(416, 416), INTER_LINEAR);
vector<uint8_t> img_data;
auto e = begin(img_data);
img_data.insert(e, resized_img.data, resized_img.data + resized_img.total() * 3);
auto input = cppflow::tensor(img_data, { 3, 416, 416 });
input = cppflow::cast(input, TF_UINT8, TF_FLOAT);
input = cppflow::expand_dims(input, 0);
serizba commented 2 years ago

Hi @louisme87

What is exactly your problem? You don't know how to convert cv::Mat to cppflow::tensor?