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

Expand Dims in Flutter-TfLite for Image Classification #68

Closed
MinSiThu opened this issue May 27, 2023 · 2 comments
Closed

Expand Dims in Flutter-TfLite for Image Classification #68

MinSiThu opened this issue May 27, 2023 · 2 comments

Comments

@MinSiThu
Copy link

How to expand_dims in flutter tflite

I am making an image classification app.

My tflite model has input shape = (1,244,244,3)
After reading image from image picker, and load as TensorImage, my image shape is (244,244,3).

When I put the image to run in the interpreter

_model.interpreter.run(inputTensorImage.buffer, outputBuffer.buffer);

Following error occurs.
StateError (Bad state: failed precondition)

How can I change my image dimension (244,244,3) into (1,244,244,3) in flutter-tflite?

@gregorscholz
Copy link
Contributor

Just put the input inside [ ].
You can also see this in the given example here.

@MinSiThu
Copy link
Author

MinSiThu commented May 28, 2023

For other people, who are searching for solution, here is a gist of code.

How to expand dims in flutter-tflite

final imageMatrix = List.generate(
        imageInput.height,
        (y) => List.generate(
          imageInput.width,
          (x) {
            final pixel = imageInput.getPixel(x, y);
            return [pixel.r, pixel.g, pixel.b];
          },
        ),
      );

newMatrix = [imageMatrix];

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

2 participants