How to use TFlite with tensorflowjs?

Hi All

I have to follow this video of @khanhlvg to train a model to detect a custom object but I don’t know how to use this model on the web browser. I have tried this code but unluckily it got the error. Is there anyone who can let me know what is wrong with it.

Here is my code

const model = await tfTask.ObjectDetection.CustomModel.TFLite.load({
                model:
                    'android.tflite',
            });

            // Run inference on an image.
            const img = document.querySelector('img');
            const result = await model.predict(img);
            console.log(result.objects);

            // Clean up.
            model.cleanUp();

And here is the error

Error: Failed to create ObjectDetector: INVALID_ARGUMENT: Output tensor at index 0 is expected to have 3 dimensions, found 2. [tflite::support::TfLiteSupportStatus='400']

Thanks,
Truong

Have you tried the latest version of TFJS - TFLite Task Library (0.0.1-alpha.8)?

If you’re already using the latest version, then it’s unfortunate that the TFJS library is built with an old version of Task Library that doesn’t contain this fix. If that’s the case, please post to this thread and I’ll ask TFJS team if they can release a newer version.

cc: @Jason FYI

I’m using this. Not sure it is 0.0.1-alpha.8 or not

https://cdn.jsdelivr.net/npm/@tensorflow-models/tasks

Yes it’s the latest version. It looks like TFJS team need to publish a newer version of Task library to support the new Object Detection model. I’ll reach out to them and see what we can do.

That is great news for me. Never see any team can support super fast like this. Thank you so much

1 Like