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

squeeze TensorBuffer #52

Open
linzissu opened this issue Mar 2, 2022 · 1 comment
Open

squeeze TensorBuffer #52

linzissu opened this issue Mar 2, 2022 · 1 comment

Comments

@linzissu
Copy link

linzissu commented Mar 2, 2022

Hi,
I'm tring to test on my model to encode an image. I got a [1, 400, 400 3] tensorBuffer ("hidden_img" below) after forwarding but I want to squeeze the tensor to [400, 400, 3] before calling TensorImage.fromTensorBuffer( tensorBuffer ). Is there any method to squeeze tensorBuffer like squeeze in numpy. Any suggestions would be appreciated!

  TensorImage encode(TensorImage image, List<double> secret) {
    print("success enter encode! ");

    /// Iutputs List
    var inputs = [image.buffer, secret];

    /// Outputs buffer
    TensorBuffer out_secret = TensorBufferFloat(_outputShapes[0]);
    TensorBuffer hidden_img = TensorBufferFloat(_outputShapes[1]);
    TensorBuffer residual = TensorBufferFloat(_outputShapes[2]);

    /// Outputs map
    Map<int, Object> outputs = {
      0: out_secret.buffer,
      1: hidden_img.buffer,
      2: residual.buffer,
    };
    print(_inputShapes.toString());

    /// run
    _interpreter.runForMultipleInputs(inputs, outputs);

    print("run success!");
    // List<int> shapes = [400, 400, 3];
    // hidden_img.resize(shapes);

    return processOutputImage(TensorImage.fromTensorBuffer(hidden_img));
  }

  TensorImage processOutputImage(TensorImage image) {
    //resize and normalize image
    imageProcessor =
        ImageProcessorBuilder().add(NormalizeOp(0, 1 / 255)).build();
    // add();
    //process image one by one
    TensorImage output_image = imageProcessor.process(image);
    return output_image;
  }
@ralienpp
Copy link

Hey there, @linzissu, did you find a solution to the problem?

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