tensorflow / tfjs

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

Error: Argument "x" passed to 'conv2d' must be a Tensor or TensorLike, but got 'tensor' #7056

Open zbagdzevicius opened 1 year ago

zbagdzevicius commented 1 year ago

Describe the current behavior on android, type of images.next().value is 'Tensor', not Tensor or TensorLike. It results in error " Error: Argument "x" passed to 'conv2d' must be a Tensor or TensorLike, but got 'tensor' "

Describe the expected behavior should work the same as on iOS

Problem happens only with Hermes JS engine

Standalone code to reproduce the issue

import { dispose, Tensor3D } from "@tensorflow/tfjs";
import { cameraWithTensors } from "@tensorflow/tfjs-react-native";

export const ExampleComponent = () => {
  const handleCameraStream = useCallback(
    (images: IterableIterator<Tensor3D>) => {
      const loop = async () => {
          const tensor = images.next().value;
          detectGesture(tensor); // error happens here, model predict is called inside and specified error occurs
    },
    [isGestureDetectionReady]
  );
  return 
      <TensorCamera
            type={CameraType.front}
            cameraTextureHeight={640}
            cameraTextureWidth={640}
            resizeHeight={640}
            resizeWidth={640}
            onReady={handleCameraStream}
            autorender={true}
          />
}
<TensorCamera
      type={CameraType.front}
      autoFocus={false}
      pictureSize={pictureSize}
      style={{
        position: "absolute",
        left: 50,
        top: 100,
        width: 120,
        height: 120,
        zIndex: 1,
        borderWidth: 1,
        borderColor: "black",
        borderRadius: 0,
      }}
      cameraTextureHeight={640}
      cameraTextureWidth={640}
      resizeHeight={640}
      resizeWidth={640}
      zoom={0}
      onReady={handleCameraStream}
      autorender={true}
    />
zbagdzevicius commented 1 year ago

doesn't work with "jsEngine": "hermes", works with "jsEngine": "jsc"

rthadur commented 1 year ago

hermes is not supported at this time , please refer to the issue . Thank you!

Rhysjc commented 1 year ago

I was experiencing this on the latest version of tfjs regardless of whether hermes was enabled or not. Downgrading to an older version of tfjs (3.7.0) fixed this for me. Seems like v4 of tfjs and tfjs-react-native currently aren't compatible.

gaikwadrahul8 commented 1 year ago

Hi, @zbagdzevicius

Apologize for the delayed response and please refer this comment, It seems like there is package dependancies compatibility issue so could you please try with package dependancies which are mentioned in this official documentation and let us know whether is it working as expected or not ?

If issue still persists please let us know ? Thank you!

"expo": "~44.0.2",
"expo-camera": "^12.1.0",
"expo-file-system": "^13.2.0",
"expo-gl": "^11.1.1",
"expo-gl-cpp": "^11.1.0",
"react": "17.0.1",
"react-native": "~0.64.3",
github-actions[bot] commented 1 year ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

ovidb commented 1 year ago

I tried with the recommended dependencies an it works.

The issue with the suggested version is that support for 44 has been dropped by expo quite a bit of time ago.

The latest currently supported version of expo is 47.

I tried running with specifying "jsEngine": "jsc" in the app.json but that also doesn't work witht the latest expo 49

SadmanYasar commented 12 months ago

doesn't work with "jsEngine": "hermes", works with "jsEngine": "jsc"

This and I had to update all dependencies to the latest versions using yarn upgrade --latest to resolve this issue. So far seems to work with Expo SDK 49. Here is the working repo.

gaikwadrahul8 commented 12 months ago

Hi, @zbagdzevicius

Thank you for opening this issue. Since this issue has been open for a long time, the code/debug information for this issue may not be relevant with the current state of the code base.

The TFJs team is constantly improving the framework by fixing bugs and adding new features. We suggest you try the latest TFJs version with the latest compatible hardware configuration which could potentially resolve the issue. If you are still facing the issue, please create a new GitHub issue with your latest findings, with all the debugging information which could help us investigate.

Please follow the release notes to stay up to date with the latest developments which are happening in the Tensorflow.js space.

Thank you for your support and cooperation.

RachidZianne commented 12 months ago

@SadmanYasar Did you made pose detection work with last expo SDK 49 please help

SadmanYasar commented 12 months ago

@RachidZianne I tried with pose detection model and have it running on Expo SDK 49. Source. However, it is not working as expected. FPS is very low, around 3-4 FPS on my phone. I think there isn't much support for this SDK version.

RachidZianne commented 12 months ago

@SadmanYasar Thanks: as u mentioned it's working as expected but so far I got it working adding on app.json. "jsEngine": "jsc", "assetBundlePatterns": [ "*/" ], "plugins": [ [ "expo-camera", { "cameraPermission": "Allow $(PRODUCT_NAME) to access your camera." } ] ] then I got some poses displaying on the camera :) Hope for next release...

joaops95 commented 11 months ago

Any one got this error when building on android? Could not set unknown property 'classifier' for task ':expo-gl-cpp:androidSourcesJar' of type org.gradle.api.tasks.bundling.Jar.

kenhuang1964 commented 11 months ago

I tried with the recommended dependencies an it works.

The issue with the suggested version is that support for 44 has been dropped by expo quite a bit of time ago.

The latest currently supported version of expo is 47.

I tried running with specifying "jsEngine": "jsc" in the app.json but that also doesn't work witht the latest expo 49

Hey @ovidb were you able to fix this?

babthamotharan commented 3 months ago

What is the procedure to change the "jsEngine" to "jsc"? When I add this in my app.json, my app is crashing. Do I missing any installation or updating?