tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone

Home Page:https://tensorflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Android Tensorflow lite cannot use models from path, gives "TFLite failed to load model with error" error.

burntato opened this issue · comments

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

tf 2.8

Custom code

Yes

OS platform and distribution

Linux Ubuntu 23.04

Mobile device

Android 10 device and Emulated android 10 device

Python version

3.9

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

I am currently trying to make a different version of tensorflow lite android(java) app that can classify images from here https://github.com/tensorflow/examples/tree/master/lite/examples/image_classification/android_java

the changes that I made is that I added a button to upload a file(tensorflow lite model) to the app, and then the app will use that file as the model.

I'm having difficulties on trying to use the model, the file upload section is able to upload and rename it just fine, but somehow even if the file is there it still gives

2024-05-05 02:13:33.449 26003-26003 CameraFragment org....examples.imageclassification D Received URI: content://com.android.providers.downloads.documents/document/msf%3A25
2024-05-05 02:13:33.466 26003-26003 CameraFragment org....examples.imageclassification D File extension: .tflite
2024-05-05 02:13:33.599 26003-26003 CameraFragment org....examples.imageclassification D File path: /data/user/0/org.tensorflow.lite.examples.imageclassification/files/model.tflite
2024-05-05 02:13:33.599 26003-26003 CameraFragment org....examples.imageclassification D File exists
2024-05-05 02:13:33.607 26003-26003 ImageClassifierHelper org....examples.imageclassification E TFLite failed to load model with error: /data/user/0/org.tensorflow.lite.examples.imageclassification/files/model.tflite
2024-05-05 02:13:33.607 26003-26003 System.err org....examples.imageclassification W java.io.FileNotFoundException: /data/user/0/org.tensorflow.lite.examples.imageclassification/files/model.tflite

so I went ahead and checked the folder where the file is supposedly located, funny enough that the file is actually there
image

the check above is done on an emulator.

So is tensorflow just unable to load a model from path or it has to be inside the asset folder? I've been scourging the internet for answer and no luck here.

steps to reproduce the issue is to clone the android app, change gradle-wrapper.properties distributionUrl to 7.3.3 version add permission to read external storage in AndroidManifest file and change ImageClassifierHelper.java, CameraFragment.java, and info_bottom_sheet.xml to the file I attatched below. I also attatched the stings.xml for the buttons on info_bottom_sheet.xml.

information about the model I'm using, the model itself is a custom image classification model trained to detect legos(for now), it works well if I just put it in assets.

For now I've put the files necessary on a gdrive below.

Standalone code to reproduce the issue

https://drive.google.com/drive/folders/1GAHRJSuib45A-mAwpq-Wyx1J3nF7Ur2d

Relevant log output

2024-05-05 02:13:33.449 26003-26003 CameraFragment          org....examples.imageclassification  D  Received URI: content://com.android.providers.downloads.documents/document/msf%3A25
2024-05-05 02:13:33.466 26003-26003 CameraFragment          org....examples.imageclassification  D  File extension: .tflite
2024-05-05 02:13:33.599 26003-26003 CameraFragment          org....examples.imageclassification  D  File path: /data/user/0/org.tensorflow.lite.examples.imageclassification/files/model.tflite
2024-05-05 02:13:33.599 26003-26003 CameraFragment          org....examples.imageclassification  D  File exists
2024-05-05 02:13:33.607 26003-26003 ImageClassifierHelper   org....examples.imageclassification  E  TFLite failed to load model with error: /data/user/0/org.tensorflow.lite.examples.imageclassification/files/model.tflite
2024-05-05 02:13:33.607 26003-26003 System.err              org....examples.imageclassification  W  java.io.FileNotFoundException: /data/user/0/org.tensorflow.lite.examples.imageclassification/files/model.tflite