tflite_flutter_helper
tflite_flutter_helper copied to clipboard
squeeze TensorBuffer
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;
}
Hey there, @linzissu, did you find a solution to the problem?