集成Google Teachable Machine模型到Java应用程序

huangapple 未分类评论66阅读模式
标题翻译

Integrate Google Teachable Machine Model to Java application

问题

我在 https://teachablemachine.withgoogle.com 上创建了一个图像模型,用于将简单的标准化图标分类,因为我在我的应用程序中需要这个功能,但我未能将其导入到我的 Java 应用程序中。我尝试了从 .h5 导入,通过 Deeplearning4j(不受支持)到与 Tensorflow 和 savedModel 的奋斗。其他导出格式包括 Tensorflow.js 和 Tensorflow Lite。

我尝试在 Python 中手动训练模型,但由于我目前的深度学习技能有限,这个过程过于复杂,而且效果也不如 Teachable Machine 好。

我的程序必须从图像中对已知的GHS图标进行分类(https://en.wikipedia.org/wiki/Globally_Harmonized_System_of_Classification_and_Labelling_of_Chemicals)。

我该怎么办?是否有另一种方法可以集成模型,或者在这种简单情况下是否有比深度学习更简单的方法?

英文翻译

I made an image model with https://teachablemachine.withgoogle.com, which classifies simple
standardized pictograms as I need this in my application but I didn't manage to import it to my java application. I tried everything from .h5 import via Deeplearning4j (unsupported) to fighting around with Tensorflow and savedModel. Other export-formats are Tensorflow.js and Tensorflow Lite.

My attempt to train a model manually in python was too complex for my current deeplearning skills and never worked as good as the teachable machine.

My program has to classify the known GHS-pictograms from images (https://en.wikipedia.org/wiki/Globally_Harmonized_System_of_Classification_and_Labelling_of_Chemicals)

What should I do? Is there another way to integrate the model or maybe is there a simpler way than deeplearning for this simple thing?

答案1

得分: 0

首先,将您的模型导出为SavedModel格式。
集成Google Teachable Machine模型到Java应用程序

然后您可以使用机器学习库来读取它。

例如:

示例代码(取自此处):

Criteria<Image, Classifications> criteria =
    Criteria.builder()
        .setTypes(Image.class, Classifications.class)
        .optModelUrls("https://example.com/squeezenet.zip")
        .optTranslator(ImageClassificationTranslator
               .builder().addTransform(new ToTensor()).build())
        .build();

try (ZooModel<Image, Classification> model = ModelZoo.load(criteria);
        Predictor<Image, Classification> predictor = model.newPredictor()) {
    Image image = ImageFactory.getInstance().fromUrl("https://myimage.jpg");
    Classification result = predictor.predict(image);
}
英文翻译

First Export your model as SavedModel.
集成Google Teachable Machine模型到Java应用程序

Then you can use ML Libraries to read it.

For Example:-

Example code (Taken from here):-

Criteria&lt;Image, Classifications&gt; criteria =
    Criteria.builder()
        .setTypes(Image.class, Classifications.class)
        .optModelUrls(&quot;https://example.com/squeezenet.zip&quot;)
        .optTranslator(ImageClassificationTranslator
               .builder().addTransform(new ToTensor()).build())
        .build();

try (ZooModel&lt;Image, Classification&gt; model = ModelZoo.load(criteria);
        Predictor&lt;Image, Classification&gt; predictor = model.newPredictor()) {
    Image image = ImageFactory.getInstance().fromUrl(&quot;https://myimage.jpg&quot;);
    Classification result = predictor.predict(image);
}

huangapple
  • 本文由 发表于 2020年1月30日 19:49:04
  • 转载请务必保留本文链接:https://java.coder-hub.com/59985403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定