rhdeck / react-native-coreml

CoreML module for React native
MIT License
36 stars 7 forks source link

Unable to use RNFS to read a file despite providing an absolute path #7

Open syedwshah opened 3 years ago

syedwshah commented 3 years ago

I'm trying to follow the 'Usage' example in this repo: https://github.com/rhdeck/react-native-coreml

So my code is fairly similar:

import {compileModel, classifyTopValue} from 'react-native-coreml';
const NetworkMLModelPath =
  'https://github.com/hollance/MobileNet-CoreML/raw/master/MobileNet.mlmodel';

const coreml = async (pathToImage: string) => {
  const path = 'MobileNetV2.mlmodel';
  try {
    const {promise} = await RNFS.downloadFile({
      fromUrl: NetworkMLModelPath,
      toFile: RNFS.MainBundlePath + path,
    });

    console.log('promise', (await promise).statusCode);

    const modelPath = await compileModel(path);

    // const {label, confidence} = await classifyTopValue(pathToImage, modelPath);
    // console.log('The image is a ' + label + '. I think. ');
  } catch (error) {
    console.log(error);
  }
};

And my output is

 LOG  [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "react-native-coreml").compileModel')]

So my RNFS.downloadFile() seems to have worked since I have a jobId and a statusCode 200, so I wonder why compileModel is going to error. Any help or suggestions would be appreciated!