首页 > 解决方案 > 如何使用 TFlite 安卓工作室

问题描述

大家好,关注的人!)。我是机器学习的新手,遇到了一个问题。我有一个预训练的图像分类器神经网络转换为 tflite,我想在 android studio 中使用它。在我的输入中是来自 Camera Photo 的位图。我使用了本指南https://www.tensorflow.org/lite/guide/android。我这样更改的示例代码

try {

            ConvertedModel model = ConvertedModel.newInstance(this);

            // Creates inputs for reference.
            TensorImage image = TensorImage.fromBitmap(Photo_bitMap);

            // Runs model inference and gets result.
            ConvertedModel.Outputs outputs = model.process(image);
            List<Category> probability = outputs.getProbabilityAsCategoryList();
   
            // Releases model resources if no longer used.
            model.close();
            //see probability chance
            System.out.println(probability);
        }
        catch (IOException e) {
           //catch error 
        }

ConvertedModel - IDE 自动找到模型并将其放入。它是我的转换模型,位于 ml 在此处输入图像描述 但作为响应,我打印概率结果并得到一个完全错误的概率,这是我在转换之前没有在预测试中得到的。每次输入相同的图像时,它也会给出相同的概率。例如,我们输入白色图片,对于这个图片的概率在我们输入它的任何时候都是相同的,kile const。

我的概率错误,因为我使用的模型不正确?如果我没有正确使用模型,为什么我得到概率,并且对同一张图片得到相同的概率?如何解决这个问题

标签: javaandroid-studiotensorflowtensorflow-liteimage-classification

解决方案


我的代码是正确的,问题出在我的网络上。我用元数据下载了这个网络,一切正常。


推荐阅读