mrousavy / react-native-fast-tflite

🔥 High-performance TensorFlow Lite library for React Native with GPU acceleration
https://mrousavy.com
MIT License
657 stars 29 forks source link

Unable to load model from local directory #63

Open mashad6 opened 4 months ago

mashad6 commented 4 months ago
Screenshot 2024-05-08 at 3 30 25 PM

// Asset from React Native Bundle loadTensorflowModel(require('assets/my-model.tflite')) When loading from project assets it was working total accurate. But i tried loading from my device local directory like:

// File on the local filesystem loadTensorflowModel('file:///var/mobile/.../my-model.tflite')

it says [Error: TFLite: Invalid source passed! Source should be either a React Native require(..) or a { url: string }object!]

I tried using with loadTensorflowModel('https://tfhub.dev/google/lite-model/object_detection_v1.tflite') but it says JNI error exception, expect http or https but recieve "file://"

I am using "react-native-fast-tflite": "^1.2.0"

Any solution how can i load my model from my device local directory?

mrousavy commented 4 months ago

[Error: TFLite: Invalid source passed! Source should be either a React Native require(..) or a { url: string }object!]

Did you try to pass { url: 'https://...' } as the error suggests? An object with the url key?

mashad6 commented 4 months ago

if I use { url: 'https://'+file_path } error: JNI GetObjectRefType called with pending exception java.net.UnknownHostException: Unable to resolve host "file": No address associated with hostname and if i use { url: file_path }: Error: JNI DETECTED ERROR IN APPLICATION: JNI GetObjectRefType called with pending exception java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but was 'file'

mrousavy commented 3 months ago

Gotcha, yea well this should work and shouldn't be easy to fix. If you fix this, please send a PR. Otherwise I don't have time to fix this now because of other libraries.

lucksp commented 4 days ago

can anyone test this open PR to fix? https://github.com/mrousavy/react-native-fast-tflite/pull/82