tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.25k stars 1.92k forks source link

@tensorflow/tfjs-react-native can't be installed successfully expo 51 #8292

Open JRfan123 opened 4 weeks ago

JRfan123 commented 4 weeks ago

Please make sure that this is a build/installation issue. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:build_template

System information

Describe the problem

image

The conflict between expo camera @ "^ 13.4.4" resulted in installation dependency failure, but after expo 50, a new version of the camera is installed by default, and the new camera is not compatible with the old camera

expo document : https://docs.expo.dev/versions/latest/sdk/camera/

by the way: I want to use the transpose api about the image to handle image


    const imageBuffer = await Image.resolveAssetSource(require("@/assets/images/dogs.jpg")).uri;
    const imageData = await fetch(imageBuffer);
    const imageBlob = await imageData.blob();
    const imageArrayBuffer = await imageBlob.arrayBuffer();
    const imageUint8Array = new Uint8Array(imageArrayBuffer);

    // 将图像转换为 TensorFlow.js 张量并进行预处理
    const imageTensor = decodeJpeg(imageUint8Array);
    const inputImage = tf.transpose(imageTensor, [2, 0, 1]).expandDims(0).div(tf.scalar(255));

Provide the exact sequence of commands / steps that you executed before running into the problem

Any other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

Jersyfi commented 4 weeks ago

@JRfan123 The imports in tfjs-react-native for expo camera are not up to date. With SDK the expo-camera import changed from 'expo-camera' to 'expo-camera/lagacy'. It would be better if the tfjs-react-native would be updated to newer expo versions but at the moment i'll get no progress on this. Maybe you have time to create a pull request for requesting the changes.

JRfan123 commented 4 weeks ago

ok , i will try it

gaikwadrahul8 commented 3 weeks ago

Hi, @JRfan123

I apologize for the delayed response and @Jersyfi thank you for your pointers and I see Expo changelog from official documentation You can find the old versions at expo-camera/legacy and expo-sqlite/legacy during SDK 51, and they will be removed in SDK 52. so following an initial assessment, it appears that updating @tensorflow/tfjs-react-native to support newer Expo versions might be required.

I will raise this issue for discussion in our upcoming internal meeting and provide a status update soon. We are also open to contributions on this matter. Feel free to submit a pull request for our team's review and we will take appropriate action to integrate your contribution if it aligns with our goals.

// Legacy APIs (SDK 50)
import { Camera } from 'expo-camera';

// Legacy APIs (SDK 51): if you import the legacy packages in your app, update
// the imports to the following:
import { Camera } from 'expo-camera/legacy';

Thank you for your cooperation and patience.

Jersyfi commented 3 weeks ago

@gaikwadrahul8 Thank you for seeing the need of updating. It would make sence to update to the newest expo-camera API and also to support the newest expo-gl version and drop the expo-gl-cpp. On Expo SDK 50 the @tensorflow/tfjs-react-native package was running with high performance issues for iOS and Android and not on all devices. I can provide the package.json with the running versions for SDK 50.

{
    // Excluded name, version, private, main & scripts
    },
    "dependencies": {
        "@hookform/resolvers": "^3.3.4",
        "@mediapipe/pose": "^0.5.1675469404", // required
        "@react-native-async-storage/async-storage": "1.21.0", // required
        "@react-native-community/datetimepicker": "7.7.0",
        "@react-native-firebase/app": "^20.0.0",
        "@react-native-firebase/auth": "^20.0.0",
        "@react-native-firebase/firestore": "^20.0.0",
        "@react-native-firebase/functions": "^20.0.0",
        "@react-native-firebase/storage": "^20.0.0",
        "@react-navigation/bottom-tabs": "^6.5.20",
        "@react-navigation/native": "^6.1.17",
        "@react-navigation/native-stack": "^6.9.26",
        "@tensorflow-models/pose-detection": "^2.1.3", // required
        "@tensorflow/tfjs": "^4.19.0", // required
        "@tensorflow/tfjs-backend-webgl": "^4.19.0", // required
        "@tensorflow/tfjs-backend-webgpu": "^4.19.0", // required
        "@tensorflow/tfjs-react-native": "^1.0.0", // required
        "expo": "50.0.19", // required and below SDK 51
        "expo-av": "~13.10.6",
        "expo-build-properties": "~0.11.1",
        "expo-camera": "~14.1.3", // required and below version 15
        "expo-dev-client": "~3.3.12",
        "expo-device": "~5.9.4",
        "expo-file-system": "~16.0.9",
        "expo-gl": "~13.6.0", // required
        "expo-image": "~1.10.6",
        "expo-image-manipulator": "~11.8.0",
        "expo-image-picker": "~14.7.1",
        "expo-keep-awake": "~12.8.2",
        "expo-linear-gradient": "~12.7.2",
        "expo-linking": "~6.2.2",
        "expo-screen-orientation": "~6.4.1",
        "expo-splash-screen": "~0.26.5",
        "expo-status-bar": "~1.11.1",
        "expo-system-ui": "~2.9.4",
        "expo-web-browser": "~12.8.2",
        "lucide-react-native": "^0.378.0",
        "react": "18.2.0",
        "react-hook-form": "^7.51.1",
        "react-native": "0.73.6",
        "react-native-fs": "^2.20.0", // required
        "react-native-gesture-handler": "~2.14.0",
        "react-native-reanimated": "~3.6.2",
        "react-native-safe-area-context": "4.8.2",
        "react-native-screens": "~3.29.0",
        "react-native-svg": "14.1.0",
        "react-native-ui-lib": "^7.22.0",
        "seedrandom": "^3.0.5"
    },
    "devDependencies": {
        "@babel/core": "^7.20.0",
        "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
        "@babel/plugin-proposal-optional-chaining": "^7.21.0",
        "@babel/plugin-transform-arrow-functions": "^7.24.1",
        "@babel/plugin-transform-optional-chaining": "^7.24.1",
        "@babel/plugin-transform-shorthand-properties": "^7.24.1",
        "@babel/plugin-transform-template-literals": "^7.24.1",
        "@babel/preset-env": "^7.24.3",
        "@react-native/babel-preset": "*",
        "@types/react": "~18.2.79",
        "@typescript-eslint/eslint-plugin": "^6.12.0",
        "@typescript-eslint/parser": "^6.12.0",
        "eslint": "^8.45.0",
        "eslint-config-prettier": "^9.0.0",
        "eslint-config-universe": "^12.0.0",
        "eslint-plugin-prettier": "^5.1.3",
        "eslint-plugin-react-native": "^4.1.0",
        "prettier": "3.0.0",
        "typescript": "~5.3.3"
    }
}

@JRfan123 did you get the SDK 51 running on your side? Maybe i can help out with spending some time.

JRfan123 commented 2 weeks ago

@Jersyfi I apologize for the delayed response, I had successfully in my side , and I will try to make a pull request this week

Arijitofficial commented 1 week ago

@Jersyfi I apologize for the delayed response, I had successfully in my side , and I will try to make a pull request this week

Is it merged yet? we are still facing the same issue

EmePin commented 1 week ago

@Jersyfi How did you make it work on SDK 51? and does the apk work for you with eas build -p android --profile preview?

gimhantharuke456 commented 1 week ago

Anyone solved this issue ?

Jersyfi commented 5 days ago

At the moment i can't continue the update to SDK51 but @JRfan123 already made a PR https://github.com/tensorflow/tfjs/pull/8306 that need attention. @gaikwadrahul8 can you please have a look at the changes? I overlooked it even if it is minimalistic but it makes sense with reading the changelog on expo-camera.