82611

Watson visual recognition, classify against multiple classifiers in java

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"

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.

thank you

Answer1:

Use this tutorial to set your Java environment

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

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

Step #1 - create the classifiers

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());

Step #2 - use them

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.

Answer2:

You can use the Watson Java SDK - Visual Recognition. It provides a Java client library to use the Watson Developer Cloud services, a collection of REST APIs and SDKs that use cognitive computing to solve complex problems.

In your case you can use the classify() method of the Visual Recognition class. Take a look at the VisualRecognition Class Documentation.

Recommend

  • Retrieve matched text from input.text.matches and store into context variable in watson conversation
  • Can Watson Visual Recognition determine density?
  • Bluemix Secure Gateway AS 400 DB2 Connection refused Issue
  • Recognize undefined Entities in Watson Conversation
  • Migrate bluemix app to another organization (another person's account)
  • Adding a loading gif to simple script
  • mysql doesnt return proper json
  • Testing across multiple activities with Espresso Null Pointer
  • How to separate the barchart?
  • Created a maven project using quickstart using intelliJ, didn't seem to generate any dir struct
  • MySQL: “Unknown column in where clause” during Update Statement
  • Upload a Java and node.js project to Google AppEngine at once
  • Custom Keyboard or to create own keyboard
  • In a MEAN stack, how can I do one-time MongoDB indexing?
  • Python PIL remove sections of an image based on its colour
  • Get rendered html code in Backing Component from Composite Component
  • record audio in HTML / js without Flash?
  • How could I prohibit anonymous access to my NodeRed UI Dashboard on IBM Cloud(Bluemix)?
  • Consuming a web service with the Netbeans Platform
  • c# winform DrawToBitmap offscreen
  • ASPNetCore MVC Routing Let Server Handle Specific Route
  • Implement JwtBearer Authentication in NSwag SwaggerUi
  • Facebook iOS SDK Not Calling Completion Handler
  • Access user's phone number on iOS 7
  • Android application: how to use the camera and grab the image bytes?
  • How to revert to previous XCode version?
  • How to get Eclipse Oxygen to run on Java 9
  • Record samples being played with OpenAL
  • Typescript - Unable to get 'import' statement to function
  • Xamarin Forms - UWP Fonts
  • Get object from AWS S3 as a stream
  • Controls, properties, events and timers running in design time
  • Updated Ionic CLI but shows previous version (Windows)
  • Getting 'uninitialized constant' error when using delegate in belongs_to in model
  • How to set the response of a form post action to a iframe source?
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Change div Background jquery
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory