Open pkesseli opened 7 months ago
Hi, @pkesseli
I apologize for the delayed response and could you please help us with your Github repo or sample code snippet (along with TensorFlow Lite model (.tflite file)
) with complete steps to replicate the same behavior from our end ? Thank you for your cooperation and patience.
Hi @gaikwadrahul8,
Thanks for your response. I created a minimal repro that you can download here: https://1drv.ms/f/s!AgTGrw38VMRagvcARXTu4TVM12H8BQ?e=pGg5TE
Steps to reproduce:
npm install
npm run dev
If you browse http://localhost:3000 and look at the development console, you should see the following output:
Starting model creation...
model.ts:17 features: {"simd":true,"multiThreading":false}
tflite_web_api_client.js:2710 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_malloc')
at $jscomp.generator.Engine_.eval [as program_] (tflite_web_api_client.js:2710:245)
at $jscomp.generator.Engine_.nextStep_ (tflite_web_api_client.js:31:105)
at $jscomp.generator.Engine_.next_ (tflite_web_api_client.js:27:234)
at $jscomp.generator.Generator_.next (tflite_web_api_client.js:32:73)
at b (tflite_web_api_client.js:33:73)
eval @ tflite_web_api_client.js:2710
$jscomp.generator.Engine_.nextStep_ @ tflite_web_api_client.js:31
$jscomp.generator.Engine_.next_ @ tflite_web_api_client.js:27
next @ tflite_web_api_client.js:32
b @ tflite_web_api_client.js:33
Apologies, the link expired today. Renewed it by another two weeks.
Created a link for direct download that will last a year: https://1drv.ms/u/s!AgTGrw38VMRagvcBOf-wIlvCf49Y1A
Hi, @pkesseli
I sincerely apologize for the delayed response and thank you for sharing the workable link and now I'm able to replicate the same behaviour from my end also so we'll have to dig more into this issue and will update you soon. thank you for bringing this issue to our attention.
I also tried to replicate the same issue with latest version @tensorflow/tfjs-tflite@0.0.1-alpha.10
with peer dependency @tensorflow/tfjs@4.9.0
but I'm getting this error message Module not found: Can't resolve './tflite_web_api_client'
Thank you for your understanding and patience.
Hello everyone i am using tensor flow lite version @tensorflow/tfjs-tflite@0.0.1-alpha.9 with peer dependency @tensorflow/tfjs@4.9.0.
also i am trying to load model like: const tfliteModel = await tflite.loadTFLiteModel('assets/models/litemodal.tflite'); console.log(tfliteModel)
But getting error:
please help
I had the exact same issue as @pkesseli, to the line. I was loading the libraries from a worker module environment (though I think the module environment was the key here)
When trying to run tflite.loadModel, I observed no network requests to load the tflite_web_api_cc.js modules, and other files in the remote wasm folder, nor when manually specifying tflite.setWasmPath()
, neither specifying the remote path nor specifying a local path with the same files hosted seem to work.
I know the model works because I use the same exact model with the same exact library files, to the version, when loaded directly from cdn in a script tag. I'm guessing the libraries by default assume loading from CDN as I've had other errors in the past working with tfjs-lite from npm, but I have never had issues using tflite-tfjs when loading from cdn.
An unelegant workaround that I found was to create a worker that can load the scripts directly from CDN, that seems to work
Parent:
const worker = new Worker(new URL(`@/my_path/tfjs_worker.js', import.meta.url));
worker.postMessage('Ping from parent');
Worker
importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core');
importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-cpu');
importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-tflite@0.0.1-alpha.10')
self.onmessage = async function(event) {
const url = 'http://localhost:port/self/hosted/path';
tflite.setWasmPath('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-tflite@0.0.1-alpha.10/wasm/')
const model = await tflite.loadTFLiteModel(url)
console.log(model)
};
The above seems to work for me. It doesn't work if you don't specify the remote setWasmPath
If it's helpful for debugging, I was using a vite build system for a vue application, and the tfjs versions were:
I also tried @tensorflow/tfjs-tflite: 0.0.1-alpha.9 and that also had the same issue
Thank you @sb2702 . I am able to successfully load model after setWasmPath
tflite.setWasmPath('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-tflite@0.0.1-alpha.10/wasm/')
Thanks @mittalmohit, that does resolve my issue. However, as mentioned above, due to issue https://github.com/tensorflow/tfjs/issues/7893 I was forced to use @tensorflow/tfjs-tflite@0.0.1-alpha.9. Did you actually get @tensorflow/tfjs-tflite@0.0.1-alpha.10 to work? If so, how did you fix https://github.com/tensorflow/tfjs/issues/7893?
System information
I encountered this issue https://github.com/tensorflow/tfjs/issues/7893 when using @tensorflow/tfjs-tflite@0.0.1-alpha.10. So I regressed to @tensorflow/tfjs-tflite@0.0.1-alpha.9, as suggested in the issue. As a consequence of this downgrade, I had to use @tensorflow/tfjs@3.20.0, as illustrated in https://github.com/tensorflow/tfjs/issues/7789.
With this setup, I tried to load a
.tfilte
model as follows:The output is the following:
The referenced line is the following:
Perhaps this is a result of using a woefully outdated TensorFlow.js version, so my question would be:
Thanks for any suggestions you can provide!