gpt4 book ai didi

java - TensorFlow Lite 的 Float32 输出值如何表示图像?

转载 作者:行者123 更新时间:2023-12-01 17:29:11 25 4
gpt4 key购买 nike

问题

我无法从 TensorFlow Lite 推理的输出中获取正确的图像值。

使用bitmapOut.copyPixelsFromBuffer得到错误的值。

例如 - 如果我尝试从 bitmapIn 中采样第一个像素使用getPixel (就在 bitmapIn = getMyInBitmap(); 行之后),我得到的值是 -4718617 。从 bitmapOut 中采样第一个像素(在 bitmapOut.copyPixelsFromBuffer(outBuffer.rewind()); 之后)我得到的值为 1040252927 .

此外,不使用 NormalizeOp 标准化图像,获取全部0值(value)观。所以目前 - 我使用 NormalizeOp ,在推理之后,我将输出一一“非规范化” - 但这需要非常非常长的时间。

如何高效地将单个图像输入 TensorFlow Lite 解释器,并返回单个图像

信息

  • 我正在 Android (Java) 上运行 TensorFlow Lite 推理。
  • TensorFlow Lite 模型采用 RGB 700x700 图像 {1, 700, 700, 3}作为输入,仅给出蓝色 700x700 图像 {1, 700, 700, 1}作为输出。
  • 模型的输入和输出数据类型均为 FLOAT32 .

这是我在图像上应用该推理的代码:

Bitmap bitmapIn, bitmapOut;
ByteBuffer inBuffer, outBuffer;

int[] inShape = tfliteInterpreter.getInputTensor(0).shape()
DataType inDataType = tfliteInterpreter.getInputTensor(0).dataType();
int[] outShape = tfliteInterpreter.getOutputTensor(0).shape()
DataType outDataType = tfliteInterpreter.getOutputTensor(0).dataType();

inTensorImage = new TensorImage(inDataType);
outTensorBuffer = TensorBuffer.createFixedSize(outShape, outDataType);

imageProcessor = new ImageProcessor.Builder()
.add(new NormalizeOp(0.0f, 255.0f))
.build();

bitmapIn = getMyInBitmap();
inTensorImage.load(bitmapIn);
imageProcessor.process(inTensorImage);

inBuffer = inTensorImage.getBuffer();
outBuffer = outTensorBuffer.getBuffer();

tfliteInterpreter.run(inBuffer, outBuffer);

bitmapOut.copyPixelsFromBuffer(outBuffer.rewind());

最佳答案

恐怕“去规范化”是必须具备的,因为它看起来确实是模型在 [0,1] 范围内生成浮点输出(你能帮忙确认一下吗?),而不是在[0-255] 这是“copyPixelsFromBuffer”所期望的。

对于性能问题,您是否有任何数据,例如规范化和非规范化需要多长时间?

关于java - TensorFlow Lite 的 Float32 输出值如何表示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61156528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com