tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

React Native Tensorflow with own models not working

Open piroposantosdev opened this issue 1 year ago • 4 comments

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: iPhone 7
  • TensorFlow.js installed from (npm or script link): 4.19.0
  • React Native Version: latest

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);

piroposantosdev avatar Jun 03 '24 18:06 piroposantosdev

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.

gaikwadrahul8 avatar Jun 05 '24 19: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 13 '24 01:06 github-actions[bot]

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

piroposantosdev avatar Jun 14 '24 13:06 piroposantosdev

same issue

girraj96 avatar Sep 04 '24 09:09 girraj96