copyright | lastupdated | ||
---|---|---|---|
|
2018-07-31 |
{:shortdesc: .shortdesc} {:new_window: target="_blank"} {:tip: .tip} {:pre: .pre} {:codeblock: .codeblock} {:screen: .screen} {:curl: #curl .ph data-hd-programlang='curl'} {:javascript: .ph data-hd-programlang='javascript'} {:java: .ph data-hd-programlang='java'} {:python: .ph data-hd-programlang='python'} {:swift: .ph data-hd-programlang='swift'} {:download: .download}
This tutorial guides you through how to use some built-in classifiers in {{site.data.keyword.visualrecognitionfull}} Dedicated to classify an image. {: shortdesc}
{: #prerequisites}
You create your service instance of the {{site.data.keyword.visualrecognitionshort}} Dedicated service through {{site.data.keyword.Bluemix}}, so you need a free {{site.data.keyword.Bluemix_dedicated_notm}} account to get started.
-
Log into your {{site.data.keyword.Bluemix_dedicated_notm}} account.
-
After you log in, create your service instance from the {{site.data.keyword.visualrecognitionshort}}
{: new_window} page in the Catalog.
-
The API uses HTTP basic authentication. If you already know your credentials for the {{site.data.keyword.visualrecognitionshort}} service, skip this step. For details about how to find your service credentials, see Service credentials for Watson services
{: new_window}.
Note: Service credentials (
username
andpassword
) are different from your {{site.data.keyword.Bluemix_dedicated_notm}} account username and password.
{: #classify}
The endpoint used in this tutorial might not be your service endpoint. Check your endpoint URL on the Service credentials page in your instance of the {{site.data.keyword.visualrecognitionshort}} Dedicated service on {{site.data.keyword.Bluemix_dedicated_notm}}. {: tip}
-
Download the sample fruitbowl.jpg
image.
-
Issue the following command to upload the image and classify it against the General model:
- Replace
{username}
and{password}
with the service credentials you copied earlier. - Modify the location of the images_file to point to where you saved the image.
- Replace the
https . . .
endpoint with your endpoint URL
curl -X POST -u "{username}:{password}" --form "[email protected]" \ "https://gateway.yourenvironment.watsonplatform.net/visual-recognition/api/v3/classify?version=2016-05-20"
{: pre}
The response includes the General model or classifier (which uses the
default
classifier_id), the classes identified in the image, and a score for each class.{ "images": [ { "classifiers": [ { "classifier_id": "default", "name": "default", "classes": [ { "class": "banana", "score": 0.562, "type_hierarchy": "/fruit/banana" }, { "class": "fruit", "score": 0.788 }, { "class": "diet (food)", "score": 0.528, "type_hierarchy": "/food/diet (food)" }, { "class": "food", "score": 0.528 }, { "class": "honeydew", "score": 0.5, "type_hierarchy": "/fruit/melon/honeydew" }, { "class": "melon", "score": 0.501 }, { "class": "olive color", "score": 0.973 }, { "class": "lemon yellow color", "score": 0.789 } ] } ], "image": "fruitbowl.jpg" } ], "images_processed": 1, "custom_classes": 0 }
{: codeblock}
Confidence scores are in the range of 0 to 1, with a higher score indicating greater correlation. By default, the
/v3/classify
calls don't include classes with a score below0.5
. - Replace
You have a basic understanding of how to use the built-in default classifier with {{site.data.keyword.visualrecognitionshort}} Dedicated. Now dive deeper:
- Learn more about how to build a custom classifier.
- Read about the API in the API reference
{: new_window}.
{: #attributions}
- Fruit basket
{: new_window} by Flikr user Ryan Edwards-Crewe
{: new_window} used under Creative Commons Attribution 2.0 license
{: new_window}. No changes were made to this image.