tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.38k stars 1.92k forks source link

React Native Tensorflow with own models not working #8295

Open piroposantosdev opened 3 months ago

piroposantosdev commented 3 months ago

System information

i'm trying to use my onw model, but when I try to run the app i'm getting this error: TypeError: undefined is not an object (evaluating 'globalThis.expo.NativeModule') and Error loading model: [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "expo-asset").Asset')] i'm using React Native CLI not expo

this is my code:

    const loadModel = async () => {
    try {
        await tf.ready();
        console.log("Tensorflow is ready");
        const modelJson = require("./assets/model.json");
        const modelWeights = require("./assets/group1-shard1of4.bin");
        const modelWeights1 = require("./assets/group1-shard2of4.bin");
        const modelWeights2 = require("./assets/group1-shard3of4.bin");
        const modelWeights3 = require("./assets/group1-shard4of4.bin");
        const model = await tf.loadGraphModel(bundleResourceIO(modelJson, [modelWeights, modelWeights1, modelWeights2, modelWeights3]));
        console.log('Model loaded successfully:', model);
    } catch (error) {
        console.error('Error loading model:', error);
    }
};
loadModel();

This is my metro.config.js:

  const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
  const config = {
  resolver: {
    // Modify assetExts to include 'bin'
    assetExts: ['bin', ...getDefaultConfig(__dirname).resolver.assetExts],
  }
 };

  module.exports = mergeConfig(getDefaultConfig(__dirname), config);
gaikwadrahul8 commented 3 months ago

Hi, @piroposantosdev

I apologize for the delayed response and thank you for bringing this issue to our attention, if possible could you please help us with your Github repo or codepen example along with converted TensorFlow.js models and complete steps to replicate the same behavior from our end to investigate this issue further from our end ?

Thank you from your cooperation and patience.

github-actions[bot] commented 3 months ago

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.

piroposantosdev commented 3 months ago

Hey there, sorry my delay. Maybe i was not clear enough. What i was talking about is that the react native package is not working properly when using a downloaded/generated model. Even trying with yours it's not working, it's always saying TypeError: undefined is not an object (evaluating 'globalThis.expo.NativeModule') and Error loading model: [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "expo-asset").Asset')] i'm using React Native CLI not expo.

I'm using RN newest version, not expo, and when i try a simple code using camera api and tensorflow api and trynna read a local bin files this error occurs

girraj96 commented 3 weeks ago

same issue