Git Product home page Git Product logo

Comments (9)

AyushExel avatar AyushExel commented on July 23, 2024 1

@raedle thanks for the info. for the expo reproduction, here are the steps:

  • Initialize a project using expo init <project_name>
  • Install react-native-pytorch-core expo install react-native-pytorch-core
  • Use any module from pytorch core in App.js. e.g, the ` module
  • Running this app on emulator or even the physical device throws this error, but without pytorch-core components the app runs fine

147419246-61d821e8-9ad4-47e6-8186-fc57f7bde9db

Ohh and btw, I was able to get it working with react-native manual installation, so expo support is not a blocker for me right now. I'm able to experiment without it. I'd be happy to write the steps for setting it up on m1 mac if needed along with the common troubles users might face

from playtorch.

raedle avatar raedle commented on July 23, 2024 1

Thanks, @AyushExel! I could confirm the "Invariant Violation" error on my end with the blank Expo template.

FWIW, ejecting the Expo app (expo eject) and running the React Native app with yarn android works.

@byCedric, do you have an idea? :)

from playtorch.

AyushExel avatar AyushExel commented on July 23, 2024 1

@raedle thanks!
I was probably doing yarn add. Your suggestion fixed the problem!

from playtorch.

raedle avatar raedle commented on July 23, 2024

Hi @AyushExel,

Thanks for leaving the encouraging comment! It is one of our goals to make PyTorch Live the best-in-class ML tool for rapid prototyping, which is why it is important to get feedback from the community (like your feedback) to help us achieve this goal!

There are some issues with M1 chipsets with Android, React Native, Python, and PyTorch. We have solved a few already and will be solving issues as they are reported.

  1. Thanks for the callout on Expo. Expo is on our radar, so it's great to hear that there is interest there. Please let us know how to reproduce the issue that you are facing, so we can have a closer look at it or submit a PR if you find fix ;)

  2. PyTorch Live uses PyTorch Mobile to run on-device inference. Unfortunately, PyTorch (Mobile) doesn't have a JavaScript runtime (or WASM runtime) to load TorchScript models in the browser and run inference on them. There are a few paths to make this probably work (e.g., expose libTorch via WASM or run via local Flask/Python server), but that's currently out of the scope for PyTorch Live project.

I'll keep this issue open until we either fixed the Expo issue or identified it as a #wontfix!

Thanks again, and don't hesitate to reach out!

from playtorch.

chrisklaiber avatar chrisklaiber commented on July 23, 2024

Hi @AyushExel - I wanted to circle back. There have been many updates and major API changes in our 0.2.0 series. One specific change with the just-released 0.2.1 version is a working Expo config plugin to help with configuring a new Expo project. See my comment here, I hope it helps: #73 (comment)

from playtorch.

AyushExel avatar AyushExel commented on July 23, 2024

@chrisklaiber hey thanks for the update. I kinda stopped playing with pytorch after this attempt. But the new release looks promising! I'll start exploring it again! btw I see you guys have added support for YOLOv5. I'm one of the maintainers of the repo, feel free to tag me if there are any issues related to yolov5. Thanks!

from playtorch.

chrisklaiber avatar chrisklaiber commented on July 23, 2024

Thanks for the followup, and thanks for your work on YOLOv5! I'll close this issue out for now, since it appears there is nothing specific left to address. Also, happily, there is now a YOLOv5 tutorial available: https://playtorch.dev/docs/tutorials/snacks/yolov5/

from playtorch.

AyushExel avatar AyushExel commented on July 23, 2024

@chrisklaiber hey! I decided to give it another shot with expo. I upgraded to the latest version of react-native-pytorch-core. Here is my package.json

  "dependencies": {
    "expo": "~47.0.6",
    "expo-status-bar": "~1.4.2",
    "react": "18.1.0",
    "react-dom": "18.1.0",
    "react-native": "0.70.5",
    "react-native-web": "~0.18.9",
    "react-native-pytorch-core": "0.2.2",
    "react-native-safe-area-context": "3.3.2"
  },

And App.ts

import { View } from 'react-native';
import {Camera} from 'react-native-pytorch-core';
export default function App() {

  return (
      <View>
        <Camera />
      </View>
    );

On doing yarn android via expo, I get this error:

 ERROR  Error: PlayTorchJSIModule not found. Maybe try rebuilding the app.
 ERROR  Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
        A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
 ERROR  Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
        A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

from playtorch.

raedle avatar raedle commented on July 23, 2024

Hey @AyushExel, there are a few notable changes since the launch from last year. There are three options now. I listed them below in the order of increased involvement (or my subjective rating of difficulty).

1. Use PlayTorch app

no CLI commands required

Use the PlayTorch app available in Play Store and App Store and build ML demos on the Expo Snack platform (this is what the YOLOv5 tutorial describes step by step: https://playtorch.dev/docs/next/tutorials/snacks/yolov5/).

2. Create Standalone App with Expo

requires CLI commands

  1. Create Expo app with npx create-expo-app my-app
  2. Navigate to app directory cd my-app
  3. Install PlayTorch SDK with npx expo install react-native-pytorch-core (it needs to use npx expo install because it makes sure to run the PlayTorch config plugin in the next step; i.e., yarn add react-native-pytorch-core or npm install react-native-pytorch-core will result in an error similar to what you reported)
  4. Change App.js (see code below)
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import { Camera } from 'react-native-pytorch-core';

export default function App() {
  return (
    <View style={styles.container}>
      <Camera style={StyleSheet.absoluteFill} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Note: style={StyleSheet.absoluteFill} makes sure the camera is full width/height (otherwise it might end up 0,0 width/height.

  1. If .watchmanconfig is missing in the app directory, run echo "{}" > .watchmanconfig (otherwise the next command will err with Error: watchman::CommandValidationError:)
  2. For iOS, we just realized that it is now necessary to add NSCameraUsageDescription to the Info.plist. Add the following to the ios/myapp/Info.plist:
<key>NSCameraUsageDescription</key>
<string>Allow $(PRODUCT_NAME) to use the camera as input for machine learning models.</string>
  1. Run app on Android with npx expo run:android or on iOS with npx expo run:ios (note: use the commands provided here to build the native app from scratch, otherwise Expo will use the Expo Go app, which does not ship with the PlayTorch SDK native code)

image

3. Add PlayTorch SDK to Existing RN App

Instructions for this are on the website in the Add Package to Existing App tutorial

from playtorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.