Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: null is not an object (evaluating 'TfliteReactNative.loadModel') #34

Open
nitsanasraf opened this issue Jan 6, 2022 · 0 comments

Comments

@nitsanasraf
Copy link

nitsanasraf commented Jan 6, 2022

I am developing an app for ios with react-native CLI, and I am facing a problem loading the model.
I've tried every solution possible on the internet, but it still doesn't work, unfortunately.
Linking is working properly, I've tried manual linking and automatic.
I have my model in src/models.
And in Xcode, it's under MyProject > models.

This is my code:

const initModel = () => {
  const tflite = new Tflite();
  console.log('started initialization of TENSOR FLOW LITE');
  tflite.loadModel(
    {
      model: 'models/model.tflite', // required
      labels: 'models/labels.txt', // required
      numThreads: 1,
      async: false, // defaults to 1
    },
    (err, res) => {
      if (err) {
        console.log(err);
      } else {
        res.runModelOnImage(
          {
            path: pictureUrl, // required
            imageMean: 128.0, // defaults to 127.5
            imageStd: 128.0, // defaults to 127.5
            numResults: 3, // defaults to 5
            threshold: 0.05, // defaults to 0.1
          },
          (err, res) => {
            if (err) console.log(err);
            else setPrediction(res);
          },
        );
      }
    },
  );
};

useEffect(() => {
  initModel();
}, []);

Podfile:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'


target 'ai_app' do
  config = use_native_modules!
  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
    )
    
  pod 'TensorFlowLite', '1.12.0'
  pod 'TfliteReactNative', :path => '../node_modules/tflite-react-native/ios'

  # target 'ai_appTests' do
  #   inherit! :complete
  #   # Pods for testing
  # end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

Metro.config:

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

module.exports = {
  resolver: {
    assetExts: ['tflite', 'txt','png'],
  },
};

Building is successful on Xcode.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant