tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

[tfjs-react-native] Is there any way to speed up the performance of tfjs_graph_model

Open bergkamp opened this issue 2 years ago • 1 comments

I had converted saved_model to tfjs_graph_model, the model.predict process cost 90 seconds with tfjs-react-native. Is there any way to speed up the performance?

OS Platform: M1 pro

Converted from this model

tensorflowjs_converter \
    --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    --signature_name=serving_default \
    --saved_model_tags=serve \
    /home/operator/light_paprika_SavedModel \
    /home/operator/light_paprika_tfjs

code

const shinkaiModel = require("./models/light_paprika_tfjs/group1-shard1of1.bin");
const shinkaiModelJson = require("./models/light_paprika_tfjs/model.json");
const loadCartoonModel = async (inputImg) => {
        await tf.ready();
        let start = Date.now();
        const cartoonModel = await tf.loadGraphModel(bundleResourceIO(shinkaiModelJson,shinkaiModel));
        console.log("model loaded ",Date.now()-start); //554 ms
        const imgTensor = await imgToTensor(inputImg);
        console.log("img tensor ",Date.now()-start); //661 ms
        const res = await cartoonModel.predict(imgTensor);
        console.log("predict", Date.now()-start); //94951 ms
        const img = await tensorToImg(res, inputImg.width, inputImg.height);
        setImgCartoon({ uri: img });
    }

Thanks

bergkamp avatar Jul 04 '22 03:07 bergkamp

It seems that something strange happened. Try to use tensorflow-lite as a Native Module in your RN project.

weishengkui avatar Sep 21 '22 15:09 weishengkui

Hi, @bergkamp

Apologize for the delayed response and we're re-visiting our older issues and checking whether those issues got resolved or not as of now so May I know are you still looking for the solution or your issue got resolved ?

If issue still persists please let us know ? May I know model size and on which backend are you executing the code like CPU, GPU, WASM or WebGL please ?

If possible please help us which version of react-native and expo are you using if possible please help us with package.json file

Could you please confirm if this issue is resolved for you ? Please feel free to close the issue if it is resolved ? Thank you!

gaikwadrahul8 avatar Jun 19 '23 15:06 gaikwadrahul8

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Jun 27 '23 02:06 github-actions[bot]

This issue was closed due to lack of activity after being marked stale for past 7 days.

github-actions[bot] avatar Jul 05 '23 02:07 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Jul 05 '23 02:07 google-ml-butler[bot]