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

Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:1) with shape [1, 10] to a Java object with shape [1, 10, 4]. #301

Open
GiuseppeTallariti opened this issue Sep 11, 2024 · 0 comments

Comments

@GiuseppeTallariti
Copy link

GiuseppeTallariti commented Sep 11, 2024

I’ve trained a custom TensorFlow Lite model and am using it through the tflite package. However, when I activate the camera, the app crashes after a while. The error message is: E/AndroidRuntime(31106): Caused by: java.lang.IllegalArgumentException: Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:1) with shape [1, 10] to a Java object with shape [1, 10, 4].

I noticed that this is a common issue, as is reported in #180.

If it helps, below is a portion of the code I wrote,

Future<void> initializeCamera() async {
  controller = CameraController(
    widget.cameras[0], ResolutionPreset.low,
    enableAudio: false,
    imageFormatGroup: Platform.isAndroid
        ? ImageFormatGroup.yuv420
        : ImageFormatGroup.bgra8888, // for iOS
  );
  try {
    await controller.initialize();
    if (!mounted) return;

    setState(() {});

    String? res = await Tflite.loadModel(
      model: "assets/ssd_mobilenet_v2_320x320.tflite",
      labels: "assets/labels.txt",
      numThreads: 1,
      isAsset: true,
      useGpuDelegate: false,
    );

    controller.startImageStream((CameraImage img) {
      imageCount++;
      if (imageCount % 10 == 0) {
        imageCount = 0;
        Tflite.detectObjectOnFrame(
          bytesList: img.planes.map((plane) {
            return plane.bytes;
          }).toList(),
          model: "SSDMobileNet",
          imageHeight: img.height,
          imageWidth: img.width,
          imageMean: 127.5,
          imageStd: 127.5,
          rotation: 90,
          threshold: 0.5,
        ).then((value) {
          print('$value');
        });
      }
    });
  }
}
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