1

I followed the TensorFlow docs for how to open a saved model from a file: std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile("./models/converted_model.tflite");

My C++ code can not find the TFLite model file. I put it in the /src/main/cpp/ and tried to reference it. I got the error E/tflite: Could not open 'converted_model.tflite'.

This may be a really silly question but I am trying to hackathon a tensorflow lite model on an android app in native C++. I'm unfamiliar with both Android dev and C++ dev so there are many gaps in my knowledge where this could just be an obvious issue.

I am fairly confident that my problem is not with the TFLite C++ API.

directory set up

I have confirmed in python that my .tflite model file is valid and works correctly. Therefore it leads me to believe that there must be a special process for accessing files in C++ on android NDK and I can not simply use relative path from the location of the C++ file where I am trying to access the file.

My C files which I include, such as the TF Lite C++ api is located in the same folder, so I assumed that I would be able to easily reference the path to the model file.

Would really appreciate it if someone could point me in the right direction!

  • Maybe https://stackoverflow.com/questions/1992953/file-operations-in-android-ndk will be helpful for your issue. – Jae sung Chung Apr 26 '21 at 00:08
  • 1
    On Android the src code will be compiled into `.so` and data assets like the `.tflite` file should exist in the `assets` directory. See: https://github.com/googlesamples/mlkit/tree/master/android/vision-quickstart/app/src/main/assets – Morrison Chang Apr 26 '21 at 00:13

0 Answers0