Deveco Studio 中的对象检测

问题描述 投票:0回答:0

你好世界!

我正在尝试在 DevEco Studio 中开发对象检测。我是 DevEco Studio 开发的新手。 我已经使用带有 TFLite 的 Android Studio(Android 版本)构建了该程序,还尝试使用 YOLOv5 PyTorch 并成功运行。所以,我也想用DevEco Studio(华为版)来开发

我在DevEco Studio中遇到的一些问题如下:

  1. 来自 TFLite 和 PyTorch 的库无法在 DevEco Studio 中使用,即使它已安装在依赖项中。原因是因为 TFLite 和 PyTorch 上可用的类是仅用于 Android 的类。 DevEco Studio中变量、函数等的命名与Android Studio不同。比如Android Studio中的

    RectF
    在DevEco Studio中写成
    RectFloat

  2. 这次我尝试使用DJL(Deep Java Library) PyTorch。即使安装了 PyTorch,它也无法读取引擎,我得到这样的错误。

[平板电脑] 严重的 ai.djl.engine.EngineException:找不到深度学习引擎。

这是我使用的代码。

private void init(){
        ImageClassificationTranslator translator = ImageClassificationTranslator.builder()
                .addTransform(new RandomResizedCrop(INPUT_SIZE, INPUT_SIZE, 0.6, 1,
                        3. / 4, 4. / 3))
                .addTransform(new ToTensor())
                .addTransform(new Normalize(
                        new float[] {0.5f,0.5f,0.5f},
                        new float[] {0.5f,0.5f,0.5f}))
                .optApplySoftmax(true)
                .optSynset(herbsNames)
                .optTopK(5)
                .build();
        HiLog.debug(LOG_LABEL, "debug process:v---------alue:%{private}s", translator);
        //Engine engine = Engine.getEngine(PtEngine.ENGINE_NAME);
        Model model = Model.newInstance("model", Device.cpu()); //Problem is here
        HiLog.debug(LOG_LABEL, "debug process:v---------alue:%{private}s", model);
        try{
            InputStream inputStream = HerbUtil.class.getClassLoader().getResourceAsStream("yolov5s.pt");
            HiLog.debug(LOG_LABEL, "debug process:v---------alue:%{private}s", inputStream);
            if (inputStream == null){
                throw new RuntimeException("ERROR");
            }
            model.load(inputStream);

            predictor = model.newPredictor(translator);
        } catch (MalformedModelException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
  1. 我在这个开发中使用的是 Android Studio Dolphin 版本。而且 HMS Toolkit 似乎不能在 Dolphin 及以上版本中使用。所以我必须在 DevEco Studio 中完成它。

当这个应用程序在设备上运行时,我不想使用互联网连接,所以我不使用 Docker 或任何其他云服务。在线对象检测会降低检测速度。因为我在做实时对象检测,所以我真的需要速度和准确性。

所以,我的简单问题是:

  1. 是否可以将代码从 Android Studio 转换到 DevEco Studio?尽管它们都使用 Java,但它们的实现方式却大不相同。

  2. DevEco Studio有没有可以用的物体检测工具?

  3. 有没有办法在 DevEco Studio 或华为设备上运行我的 Android 程序?

真的需要你们所有人的意见。我尝试了很多方法,关于 DevEco Studio 的对象检测工具(PyTorch、TFLite 等)的文章几乎不存在。 提前谢谢你。

android-studio pytorch object-detection tensorflow-lite deveco-studio
© www.soinside.com 2019 - 2024. All rights reserved.