I am trying to move our Tensoflow model from Python+Keras version to Tensorflow Lite with C++ on an embedded platform.
It looks like I don't know how set properly input for interpreter.
Input shape should be (1, 224, 224, 3).
As an input I am taking image with openCV, converting this to CV_BGR2RGB.
std::unique_ptr<tflite::FlatBufferModel> model_stage1 =
tflite::FlatBufferModel::BuildFromFile("model1.tflite");
TFLITE_MINIMAL_CHECK(model_stage1 != nullptr);
// Build the interpreter
tflite::ops::builtin::BuiltinOpResolver resolver_stage1;
std::unique_ptr<Interpreter> interpreter_stage1;
tflite::InterpreterBuilder(*model_stage1, resolver_stage1)(&interpreter_stage1);
TFLITE_MINIMAL_CHECK(interpreter_stage1 != nullptr);
cv::Mat cvimg = cv::imread(imagefile);
if(cvimg.data == NULL) {
printf("=== IMAGE READ ERROR ===\n");
return 0;
}
cv::cvtColor(cvimg, cvimg, CV_BGR2RGB);
uchar* input_1 = interpreter_stage1->typed_input_tensor<uchar>(0);
memcpy( ... );
I have issue with proper setup of memcpy for this uchar type.
When I am doing like this, I have seg fault during working:
memcpy(input_1, cvimg.data, cvimg.total() * cvimg.elemSize());
How should I properly fill input in this case?
cvimg
and set them likeinterpreter_stage1->typed_input_tensor<uchar>(0)[i] = x;
, where i is the index and x the value? – Midvictoriancv::cvtColor(cvimg, cvimg, CV_BGR2RGB);
your cvimg contains them in RGB order just as in your previous comment. – Midvictorian