Skip to content

React Native Tensorflow with own models not working #8295

Open
@piroposantosdev

Description

@piroposantosdev

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions