首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tensorflow-lite -从量化模型输出中获取位图

Tensorflow-lite -从量化模型输出中获取位图
EN

Stack Overflow用户
提问于 2018-12-16 17:47:39
回答 2查看 1.3K关注 0票数 2

我们正在使用tensorflow- tflite在安卓系统中开发语义分割应用程序。使用的'.tflite‘deeplabv3模型的输入类型为(ImageTensor) uint81,300,300,3,输出类型(SemanticPredictions) uint8300,300,300。我们能够成功地运行该模型,并在tflite.run method.But的帮助下获得ByteBuffer格式的输出。我们无法从java.The模型中的此输出中提取图像,该模型使用pascal voc数据集进行训练,并且实际上是从TF模型转换为tflite格式:'mobilenetv2_dm05_coco_voc_trainval’。

这个问题看起来类似于下面的堆栈溢出问题:tensorflow-lite - using tflite Interpreter to get an image in the output

处理浮点数据类型转换的相同问题似乎在github问题中得到了修复:https://github.com/tensorflow/tensorflow/issues/23483

那么,我们如何从UINT8模型的输出中正确地提取分割掩码呢?

EN

回答 2

Stack Overflow用户

发布于 2019-02-23 00:07:17

尝试以下代码:

代码语言:javascript
复制
    /**
     * Converts ByteBuffer with segmentation mask to the Bitmap
     *
     * @param byteBuffer Output ByteBuffer from Interpreter.run
     * @param imgSizeX Model output image width
     * @param imgSizeY Model output image height
     * @return Mono color Bitmap mask
     */
    private Bitmap convertByteBufferToBitmap(ByteBuffer byteBuffer, int imgSizeX, int imgSizeY){
        byteBuffer.rewind();
        byteBuffer.order(ByteOrder.nativeOrder());
        Bitmap bitmap = Bitmap.createBitmap(imgSizeX , imgSizeY, Bitmap.Config.ARGB_4444);
        int[] pixels = new int[imgSizeX * imgSizeY];
        for (int i = 0; i < imgSizeX * imgSizeY; i++)
            if (byteBuffer.getFloat()>0.5)
                pixels[i]= Color.argb(100, 255, 105, 180);
            else
                pixels[i]=Color.argb(0, 0, 0, 0);

        bitmap.setPixels(pixels, 0, imgSizeX, 0, 0, imgSizeX, imgSizeY);
        return bitmap;
    }

它适用于具有单色输出的模型。

票数 1
EN

Stack Overflow用户

发布于 2018-12-16 18:04:03

大致是这样的:

代码语言:javascript
复制
  Byte[][] output = new Byte[300][300];

    Bitmap bitmap = Bitmap.createBitmap(300,300,Bitmap.Config.ARGB_8888);

    for (int row = 0; row < output.length ; row++) {
        for (int col = 0; col < output[0].length ; col++) {
            int pixelIntensity = output[col][row];
            bitmap.setPixel(col,row,Color.rgb(pixelIntensity,pixelIntensity,pixelIntensity));
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53801064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档