Skip to content

Commit e29bac5

Browse files
committed
feat(visual-recognition): Add Core ML endpoint and options model
1 parent 6f539c1 commit e29bac5

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
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
/**
3840
* The IBM Watson Visual Recognition service uses deep learning algorithms to identify scenes, objects, and faces in
@@ -361,4 +363,23 @@ public ServiceCall<Classifier> updateClassifier(UpdateClassifierOptions updateCl
361363
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class));
362364
}
363365

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+
364385
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.developer_cloud.visual_recognition.v3.model;
14+
15+
import com.ibm.watson.developer_cloud.service.model.GenericModel;
16+
import com.ibm.watson.developer_cloud.util.Validator;
17+
18+
/**
19+
* The getCoreMlModel options.
20+
*/
21+
public class GetCoreMlModelOptions extends GenericModel {
22+
23+
private String classifierId;
24+
25+
/**
26+
* Builder.
27+
*/
28+
public static class Builder {
29+
private String classifierId;
30+
31+
private Builder(GetCoreMlModelOptions getCoreMlModelOptions) {
32+
classifierId = getCoreMlModelOptions.classifierId;
33+
}
34+
35+
/**
36+
* Instantiates a new builder.
37+
*/
38+
public Builder() {
39+
}
40+
41+
/**
42+
* Instantiates a new builder with required properties.
43+
*
44+
* @param classifierId the classifierId
45+
*/
46+
public Builder(String classifierId) {
47+
this.classifierId = classifierId;
48+
}
49+
50+
/**
51+
* Builds a GetCoreMlModelOptions.
52+
*
53+
* @return the getCoreMlModelOptions
54+
*/
55+
public GetCoreMlModelOptions build() {
56+
return new GetCoreMlModelOptions(this);
57+
}
58+
59+
/**
60+
* Set the classifierId.
61+
*
62+
* @param classifierId the classifierId
63+
* @return the GetCoreMlModelOptions builder
64+
*/
65+
public Builder classifierId(String classifierId) {
66+
this.classifierId = classifierId;
67+
return this;
68+
}
69+
}
70+
71+
private GetCoreMlModelOptions(Builder builder) {
72+
Validator.notEmpty(builder.classifierId, "classifierId cannot be empty");
73+
classifierId = builder.classifierId;
74+
}
75+
76+
/**
77+
* New builder.
78+
*
79+
* @return a GetCoreMlModelOptions builder
80+
*/
81+
public Builder newBuilder() {
82+
return new Builder(this);
83+
}
84+
85+
/**
86+
* Gets the classifierId.
87+
*
88+
* The ID of the classifier.
89+
*
90+
* @return the classifierId
91+
*/
92+
public String classifierId() {
93+
return classifierId;
94+
}
95+
}

0 commit comments

Comments
 (0)