Skip to content

Commit 0506ea0

Browse files
Merge pull request #903 from watson-developer-cloud/core-ml
Add support for Core ML endpoint
2 parents 8dac882 + 9330f3c commit 0506ea0

File tree

14 files changed

+544
-67
lines changed

14 files changed

+544
-67
lines changed

visual-recognition/src/main/java/com/ibm/watson/developer_cloud/visual_recognition/v3/VisualRecognition.java

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,20 @@
2727
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectFacesOptions;
2828
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces;
2929
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions;
30+
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetCoreMlModelOptions;
3031
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions;
3132
import com.ibm.watson.developer_cloud.visual_recognition.v3.model.UpdateClassifierOptions;
3233
import okhttp3.MultipartBody;
3334
import okhttp3.RequestBody;
3435

3536
import java.io.File;
37+
import java.io.InputStream;
3638

3739
/**
38-
* **Important:** As of September 8, 2017, the beta period for Similarity Search is closed. For more information, see
39-
* [Visual Recognition API – Similarity Search
40-
* Update](https://www.ibm.com/blogs/bluemix/2017/08/visual-recognition-api-similarity-search-update).
41-
*
4240
* The IBM Watson Visual Recognition service uses deep learning algorithms to identify scenes, objects, and faces in
4341
* images you upload to the service. You can create and train a custom classifier to identify subjects that suit your
4442
* needs.
4543
*
46-
* **Tip:** To test calls to the **Custom classifiers** methods with the API explorer, provide your `api_key` from your
47-
* IBM® Cloud service instance.
48-
*
4944
* @version v3
5045
* @see <a href="http://www.ibm.com/watson/developercloud/visual-recognition.html">Visual Recognition</a>
5146
*/
@@ -169,9 +164,13 @@ public ServiceCall<ClassifiedImages> classify() {
169164
/**
170165
* Detect faces in images.
171166
*
172-
* Analyze and get data about faces in images. Responses can include estimated age and gender, and the service can
173-
* identify celebrities. This feature uses a built-in classifier, so you do not train it on custom classifiers. The
174-
* Detect faces method does not support general biometric facial recognition.
167+
* **Important:** On April 2, 2018, the identity information in the response to calls to the Face model will be
168+
* removed. The identity information refers to the `name` of the person, `score`, and `type_hierarchy` knowledge
169+
* graph. For details about the enhanced Face model, see the [Release
170+
* notes](https://console.bluemix.net/docs/services/visual-recognition/release-notes.html#23february2018). Analyze and
171+
* get data about faces in images. Responses can include estimated age and gender, and the service can identify
172+
* celebrities. This feature uses a built-in classifier, so you do not train it on custom classifiers. The Detect
173+
* faces method does not support general biometric facial recognition.
175174
*
176175
* @param detectFacesOptions the {@link DetectFacesOptions} containing the options for the call
177176
* @return a {@link ServiceCall} with a response type of {@link DetectedFaces}
@@ -205,9 +204,13 @@ public ServiceCall<DetectedFaces> detectFaces(DetectFacesOptions detectFacesOpti
205204
/**
206205
* Detect faces in images.
207206
*
208-
* Analyze and get data about faces in images. Responses can include estimated age and gender, and the service can
209-
* identify celebrities. This feature uses a built-in classifier, so you do not train it on custom classifiers. The
210-
* Detect faces method does not support general biometric facial recognition.
207+
* **Important:** On April 2, 2018, the identity information in the response to calls to the Face model will be
208+
* removed. The identity information refers to the `name` of the person, `score`, and `type_hierarchy` knowledge
209+
* graph. For details about the enhanced Face model, see the [Release
210+
* notes](https://console.bluemix.net/docs/services/visual-recognition/release-notes.html#23february2018). Analyze and
211+
* get data about faces in images. Responses can include estimated age and gender, and the service can identify
212+
* celebrities. This feature uses a built-in classifier, so you do not train it on custom classifiers. The Detect
213+
* faces method does not support general biometric facial recognition.
211214
*
212215
* @return a {@link ServiceCall} with a response type of {@link DetectedFaces}
213216
*/
@@ -287,7 +290,7 @@ public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierO
287290
}
288291

289292
/**
290-
* Retrieve a list of custom classifiers.
293+
* Retrieve a list of classifiers.
291294
*
292295
* @param listClassifiersOptions the {@link ListClassifiersOptions} containing the options for the call
293296
* @return a {@link ServiceCall} with a response type of {@link Classifiers}
@@ -305,7 +308,7 @@ public ServiceCall<Classifiers> listClassifiers(ListClassifiersOptions listClass
305308
}
306309

307310
/**
308-
* Retrieve a list of custom classifiers.
311+
* Retrieve a list of classifiers.
309312
*
310313
* @return a {@link ServiceCall} with a response type of {@link Classifiers}
311314
*/
@@ -323,7 +326,7 @@ public ServiceCall<Classifiers> listClassifiers() {
323326
* (https://console.bluemix.net/docs/services/visual-recognition/customizing.html#updating-custom-classifiers).
324327
* Encode all names in UTF-8 if they contain non-ASCII characters (.zip and image file names, and classifier and class
325328
* names). The service assumes UTF-8 encoding if it encounters non-ASCII characters. **Important:** You can't update a
326-
* custom classifier with an API key for a Lite plan. To update a custom classifer on a Lite plan, create another
329+
* custom classifier with an API key for a Lite plan. To update a custom classifier on a Lite plan, create another
327330
* service instance on a Standard plan and re-create your custom classifier. **Tip:** Don't make retraining calls on a
328331
* classifier until the status is ready. When you submit retraining requests in parallel, the last request overwrites
329332
* the previous requests. The retrained property shows the last time the classifier retraining finished.
@@ -360,4 +363,23 @@ public ServiceCall<Classifier> updateClassifier(UpdateClassifierOptions updateCl
360363
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class));
361364
}
362365

366+
/**
367+
* Retrieve a Core ML model of a classifier.
368+
*
369+
* Download a Core ML model file (.mlmodel) of a custom classifier that returns <tt>\"core_ml_enabled\": true</tt> in
370+
* the classifier details.
371+
*
372+
* @param getCoreMlModelOptions the {@link GetCoreMlModelOptions} containing the options for the call
373+
* @return a {@link ServiceCall} with a response type of {@link InputStream}
374+
*/
375+
public ServiceCall<InputStream> getCoreMlModel(GetCoreMlModelOptions getCoreMlModelOptions) {
376+
Validator.notNull(getCoreMlModelOptions, "getCoreMlModelOptions cannot be null");
377+
String[] pathSegments = { "v3/classifiers", "core_ml_model" };
378+
String[] pathParameters = { getCoreMlModelOptions.classifierId() };
379+
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
380+
pathParameters));
381+
builder.query(VERSION, versionDate);
382+
return createServiceCall(builder.build(), ResponseConverterUtils.getInputStream());
383+
}
384+
363385
}

visual-recognition/src/main/java/com/ibm/watson/developer_cloud/visual_recognition/v3/model/Classifier.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ public interface Status {
4242
private String name;
4343
private String owner;
4444
private String status;
45+
@SerializedName("core_ml_enabled")
46+
private Boolean coreMlEnabled;
4547
private String explanation;
4648
private Date created;
4749
private List<Class> classes;
4850
private Date retrained;
51+
private Date updated;
4952

5053
/**
5154
* Gets the classifierId.
@@ -92,6 +95,17 @@ public String getStatus() {
9295
return status;
9396
}
9497

98+
/**
99+
* Gets the coreMlEnabled.
100+
*
101+
* Whether the classifier can be downloaded as a Core ML model after the training status is `ready`.
102+
*
103+
* @return the coreMlEnabled
104+
*/
105+
public Boolean isCoreMlEnabled() {
106+
return coreMlEnabled;
107+
}
108+
95109
/**
96110
* Gets the explanation.
97111
*
@@ -106,7 +120,7 @@ public String getExplanation() {
106120
/**
107121
* Gets the created.
108122
*
109-
* Date and time in Coordinated Universal Time that the classifier was created.
123+
* Date and time in Coordinated Universal Time (UTC) that the classifier was created.
110124
*
111125
* @return the created
112126
*/
@@ -128,12 +142,24 @@ public List<Class> getClasses() {
128142
/**
129143
* Gets the retrained.
130144
*
131-
* Date and time in Coordinated Universal Time that the classifier was updated. Returned when verbose=`true`. Might
132-
* not be returned by some requests.
145+
* Date and time in Coordinated Universal Time (UTC) that the classifier was updated. Returned when verbose=`true`.
146+
* Might not be returned by some requests. Identical to `updated` and retained for backward compatibility.
133147
*
134148
* @return the retrained
135149
*/
136150
public Date getRetrained() {
137151
return retrained;
138152
}
153+
154+
/**
155+
* Gets the updated.
156+
*
157+
* Date and time in Coordinated Universal Time (UTC) that the classifier was most recently updated. The field matches
158+
* either `retrained` or `created`. Returned when verbose=`true`. Might not be returned by some requests.
159+
*
160+
* @return the updated
161+
*/
162+
public Date getUpdated() {
163+
return updated;
164+
}
139165
}

visual-recognition/src/main/java/com/ibm/watson/developer_cloud/visual_recognition/v3/model/Classifiers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.ibm.watson.developer_cloud.service.model.GenericModel;
1818

1919
/**
20-
* Verbose list of classifiers retrieved in the GET v2/classifiers call.
20+
* List of classifiers.
2121
*/
2222
public class Classifiers extends GenericModel {
2323

visual-recognition/src/main/java/com/ibm/watson/developer_cloud/visual_recognition/v3/model/ClassifyOptions.java

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,25 @@
1212
*/
1313
package com.ibm.watson.developer_cloud.visual_recognition.v3.model;
1414

15-
import com.ibm.watson.developer_cloud.service.model.GenericModel;
16-
import com.ibm.watson.developer_cloud.util.Validator;
17-
1815
import java.io.File;
1916
import java.io.FileInputStream;
2017
import java.io.FileNotFoundException;
2118
import java.io.InputStream;
2219
import java.util.ArrayList;
2320
import java.util.List;
2421

22+
import com.ibm.watson.developer_cloud.service.model.GenericModel;
23+
import com.ibm.watson.developer_cloud.util.Validator;
24+
2525
/**
2626
* The classify options.
2727
*/
2828
public class ClassifyOptions extends GenericModel {
2929

3030
/**
31-
* Specifies the language of the output class names. Can be `en` (English), `ar` (Arabic), `de` (German), `es`
32-
* (Spanish), `it` (Italian), `ja` (Japanese), or `ko` (Korean). Classes for which no translation is available are
33-
* omitted. The response might not be in the specified language under these conditions: - English is returned when the
34-
* requested language is not supported. - Classes are not returned when there is no translation for them. - Custom
35-
* classifiers returned with this method return tags in the language of the custom classifier.
31+
* The language of the output class names. The full set of languages is supported only for the built-in `default`
32+
* classifier ID. The class names of custom classifiers are not translated. The response might not be in the specified
33+
* language when the requested language is not supported or when there is no translation for the class name.
3634
*/
3735
public interface AcceptLanguage {
3836
/** en. */
@@ -43,6 +41,8 @@ public interface AcceptLanguage {
4341
String DE = "de";
4442
/** es. */
4543
String ES = "es";
44+
/** fr. */
45+
String FR = "fr";
4646
/** it. */
4747
String IT = "it";
4848
/** ja. */
@@ -277,8 +277,8 @@ public Builder newBuilder() {
277277
*
278278
* An image file (.jpg, .png) or .zip file with images. Maximum image size is 10 MB. Include no more than 20 images
279279
* and limit the .zip file to 100 MB. Encode the image and .zip file names in UTF-8 if they contain non-ASCII
280-
* characters. The service assumes UTF-8 encoding if it encounters non-ASCII characters. You can also include images
281-
* with the `url` property in the **parameters** object.
280+
* characters. The service assumes UTF-8 encoding if it encounters non-ASCII characters. You can also include an image
281+
* with the **url** parameter.
282282
*
283283
* @return the imagesFile
284284
*/
@@ -300,11 +300,9 @@ public String imagesFilename() {
300300
/**
301301
* Gets the acceptLanguage.
302302
*
303-
* Specifies the language of the output class names. Can be `en` (English), `ar` (Arabic), `de` (German), `es`
304-
* (Spanish), `it` (Italian), `ja` (Japanese), or `ko` (Korean). Classes for which no translation is available are
305-
* omitted. The response might not be in the specified language under these conditions: - English is returned when the
306-
* requested language is not supported. - Classes are not returned when there is no translation for them. - Custom
307-
* classifiers returned with this method return tags in the language of the custom classifier.
303+
* The language of the output class names. The full set of languages is supported only for the built-in `default`
304+
* classifier ID. The class names of custom classifiers are not translated. The response might not be in the specified
305+
* language when the requested language is not supported or when there is no translation for the class name.
308306
*
309307
* @return the acceptLanguage
310308
*/
@@ -315,8 +313,8 @@ public String acceptLanguage() {
315313
/**
316314
* Gets the url.
317315
*
318-
* A string with the image URL to analyze. Must be in .jpg, or .png format. The minimum recommended pixel density is
319-
* 32X32 pixels per inch, and the maximum image size is 10 MB. You can also include images in the **images_file**
316+
* The URL of an image to analyze. Must be in .jpg, or .png format. The minimum recommended pixel density is 32X32
317+
* pixels per inch, and the maximum image size is 10 MB. You can also include images with the **images_file**
320318
* parameter.
321319
*
322320
* @return the url
@@ -328,8 +326,7 @@ public String url() {
328326
/**
329327
* Gets the threshold.
330328
*
331-
* A floating point value that specifies the minimum score a class must have to be displayed in the response. The
332-
* default threshold for returning scores from a classifier is `0.5`. Set the threshold to `0.0` to ignore the
329+
* The minimum score a class must have to be displayed in the response. Set the threshold to `0.0` to ignore the
333330
* classification score and return all values.
334331
*
335332
* @return the threshold
@@ -341,11 +338,11 @@ public Float threshold() {
341338
/**
342339
* Gets the owners.
343340
*
344-
* An array of the categories of classifiers to apply. Use `IBM` to classify against the `default` general classifier,
345-
* and use `me` to classify against your custom classifiers. To analyze the image against both classifier categories,
346-
* set the value to both `IBM` and `me`. The built-in `default` classifier is used if both **classifier_ids** and
347-
* **owners** parameters are empty. The **classifier_ids** parameter overrides **owners**, so make sure that
348-
* **classifier_ids** is empty.
341+
* The categories of classifiers to apply. Use `IBM` to classify against the `default` general classifier, and use
342+
* `me` to classify against your custom classifiers. To analyze the image against both classifier categories, set the
343+
* value to both `IBM` and `me`. The built-in `default` classifier is used if both **classifier_ids** and **owners**
344+
* parameters are empty. The **classifier_ids** parameter overrides **owners**, so make sure that **classifier_ids**
345+
* is empty.
349346
*
350347
* @return the owners
351348
*/
@@ -356,13 +353,11 @@ public List<String> owners() {
356353
/**
357354
* Gets the classifierIds.
358355
*
359-
* The **classifier_ids** parameter overrides **owners**, so make sure that **classifier_ids** is empty. -
360-
* **classifier_ids**: Specifies which classifiers to apply and overrides the **owners** parameter. You can specify
361-
* both custom and built-in classifiers. The built-in `default` classifier is used if both **classifier_ids** and
362-
* **owners** parameters are empty. The following built-in classifier IDs require no training: - `default`: Returns
363-
* classes from thousands of general tags. - `food`: (Beta) Enhances specificity and accuracy for images of food
364-
* items. - `explicit`: (Beta) Evaluates whether the image might be pornographic. Example:
365-
* `"classifier_ids="CarsvsTrucks_1479118188","explicit"`.
356+
* Which classifiers to apply. Overrides the **owners** parameter. You can specify both custom and built-in
357+
* classifiers. The built-in `default` classifier is used if both **classifier_ids** and **owners** parameters are
358+
* empty. The following built-in classifier IDs require no training: - `default`: Returns classes from thousands of
359+
* general tags. - `food`: (Beta) Enhances specificity and accuracy for images of food items. - `explicit`: (Beta)
360+
* Evaluates whether the image might be pornographic.
366361
*
367362
* @return the classifierIds
368363
*/

visual-recognition/src/main/java/com/ibm/watson/developer_cloud/visual_recognition/v3/model/CreateClassifierOptions.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,10 @@ public String name() {
172172
* Gets the class names.
173173
*
174174
* A .zip file of images that depict the visual subject of a class in the new classifier. You can include more than
175-
* one positive example file in a call. Append `_positive_examples` to the form name. The prefix is used as the class
175+
* one positive example file in a call. Specify the parameter name by appending `_positive_examples` to the class
176176
* name. For example, `goldenretriever_positive_examples` creates the class **goldenretriever**. Include at least 10
177177
* images in .jpg or .png format. The minimum recommended image resolution is 32X32 pixels. The maximum number of
178-
* images is 10,000 images or 100 MB per .zip file. Encode special characters in the file name in UTF-8. The API
179-
* explorer limits you to training only one class. To train more classes, use the API functionality.
178+
* images is 10,000 images or 100 MB per .zip file. Encode special characters in the file name in UTF-8.
180179
*
181180
* @return the classNames
182181
*/
@@ -197,8 +196,8 @@ public File positiveExamplesByClassName(String className) {
197196
/**
198197
* Gets the negativeExamples.
199198
*
200-
* A compressed (.zip) file of images that do not depict the visual subject of any of the classes of the new
201-
* classifier. Must contain a minimum of 10 images. Encode special characters in the file name in UTF-8.
199+
* A .zip file of images that do not depict the visual subject of any of the classes of the new classifier. Must
200+
* contain a minimum of 10 images. Encode special characters in the file name in UTF-8.
202201
*
203202
* @return the negativeExamples
204203
*/

0 commit comments

Comments
 (0)