Watson视觉识别,针对Java中的多个分类器进行分类 [英] Watson visual recognition, classify against multiple classifiers in java

查看:108
本文介绍了Watson视觉识别,针对Java中的多个分类器进行分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在API文档中找到了curl命令,可以根据多个分类器对图像进行分类:

I found this curl command in API document that can classify an image against multiple classifiers:

    curl -u "{username}":"{password}" \
-X POST \
-F "images_file=@batch1.zip" \
-F "classifier_ids=<classifierlist.json" \
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"

我想知道是否可以在Java中做到这一点,因为我正在使用Watson的视觉识别服务来开发一个android程序.

I wondered if it is possible to do this in java since I'm working on an android program using Watson's visual recognition service.

谢谢

推荐答案

使用本教程设置Java环境

Use this tutorial to set your Java environment

https://developer.ibm .com/recipes/tutorials/bluemix-watson-apis-quickstart-using-java-sdk/

然后看一下另一本教程,该教程展示了如何使用Java代码使用多个分类器

Then take a look on this other tutorial that shows how to use multiple classifiers using Java code

https://developer.ibm.com/recipes/tutorials/estimate-a-childs-age-based-on-photos-using-watson-visual-recognition/

简而言之,您的代码将如下所示

Briefly speaking, your code will look like this

第1步-创建分类器

 VisualRecognition service = new VisualRecognition(VisualRecognition.VERSION_DATE_2015_12_02);
 service.setUsernameAndPassword("*******", "********");

 File p1 = new File("/home/leoks/Desktop/models/pos2010-2011.zip");
 File n1 = new File("/home/leoks/Desktop/models/pos2014-2015.zip");
 VisualClassifier c1 = service.createClassifier("2010", p1, n1);

 File p3 = new File("/home/leoks/Desktop/models/pos2014-2015.zip");
 File n3 = new File("/home/leoks/Desktop/models/pos2010-2011.zip");
 VisualClassifier c3 = service.createClassifier("2014", p3, n3);

System.out.println(service.getClassifiers());

第2步-使用它们

File image = new File("...");

 VisualClassifier vc1 = new VisualClassifier("2010_633980596");
 VisualClassifier vc2 = new VisualClassifier("2014_450835300");
 VisualClassification result = service.classify(image, vc1,vc2);
 System.out.println(result);

如果分类器识别出您的图像,它将返回分数,否则将不返回任何答案.例如

If your image is identified by the classifier, it will return the score, otherwise, no answer will be returned. E.g.

{
 "images": [
 {
 "image": "2012.jpg",
 "scores": [
 {
 "classifier_id": "2010_633980596",
 "name": "2010",
 "score": 0.992153
 },
 {
 "classifier_id": "2014_450835300",
 "name": "2014",
 "score": 0.833185
 }
 ]
 }
 ]
}

查看教程,它们是分步说明.祝你好运.

check the tutorials, they're step-by-step instructions. Good luck.

这篇关于Watson视觉识别,针对Java中的多个分类器进行分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆