Skip to content

Commit

Permalink
chore(visual-recognition): manual changes
Browse files Browse the repository at this point in the history
feat(visual-recognition): Add integration test
  • Loading branch information
germanattanasio committed May 27, 2020
1 parent 8e51881 commit 681f9f8
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2431,4 +2431,4 @@ public ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOpti
ResponseConverter<Void> responseConverter = ResponseConverterUtils.getVoid();
return createServiceCall(builder.build(), responseConverter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.ibm.watson.visual_recognition.v4.model.GetCollectionOptions;
import com.ibm.watson.visual_recognition.v4.model.GetImageDetailsOptions;
import com.ibm.watson.visual_recognition.v4.model.GetJpegImageOptions;
import com.ibm.watson.visual_recognition.v4.model.GetModelFileOptions;
import com.ibm.watson.visual_recognition.v4.model.GetObjectMetadataOptions;
import com.ibm.watson.visual_recognition.v4.model.GetTrainingUsageOptions;
import com.ibm.watson.visual_recognition.v4.model.ImageDetails;
Expand Down Expand Up @@ -384,6 +385,42 @@ public ServiceCall<Void> deleteCollection(DeleteCollectionOptions deleteCollecti
return createServiceCall(builder.build(), responseConverter);
}

/**
* Get a model.
*
* <p>Download a model that you can deploy to detect objects in images. The collection must
* include a generated model, which is indicated in the response for the collection details as
* `"rscnn_ready": true`. If the value is `false`, train or retrain the collection to generate the
* model.
*
* <p>Currently, the model format is specific to Android apps. For more information about how to
* deploy the model to your app, see the [Watson Visual Recognition on
* Android](https://github.com/matt-ny/rscnn) project in GitHub.
*
* @param getModelFileOptions the {@link GetModelFileOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link InputStream}
*/
public ServiceCall<InputStream> getModelFile(GetModelFileOptions getModelFileOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(
getModelFileOptions, "getModelFileOptions cannot be null");
String[] pathSegments = {"v4/collections", "model"};
String[] pathParameters = {getModelFileOptions.collectionId()};
RequestBuilder builder =
RequestBuilder.get(
RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments, pathParameters));
builder.query("version", versionDate);
Map<String, String> sdkHeaders =
SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "getModelFile");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/octet-stream");
builder.query("feature", getModelFileOptions.feature());
builder.query("model_format", getModelFileOptions.modelFormat());
ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
return createServiceCall(builder.build(), responseConverter);
}

/**
* Add images.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* (C) Copyright IBM Corp. 2020.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.visual_recognition.v4.model;

import com.ibm.cloud.sdk.core.service.model.GenericModel;

/** The getModelFile options. */
public class GetModelFileOptions extends GenericModel {

/** The feature for the model. */
public interface Feature {
/** objects. */
String OBJECTS = "objects";
}

/** The format of the returned model. */
public interface ModelFormat {
/** rscnn. */
String RSCNN = "rscnn";
}

protected String collectionId;
protected String feature;
protected String modelFormat;

/** Builder. */
public static class Builder {
private String collectionId;
private String feature;
private String modelFormat;

private Builder(GetModelFileOptions getModelFileOptions) {
this.collectionId = getModelFileOptions.collectionId;
this.feature = getModelFileOptions.feature;
this.modelFormat = getModelFileOptions.modelFormat;
}

/** Instantiates a new builder. */
public Builder() {}

/**
* Instantiates a new builder with required properties.
*
* @param collectionId the collectionId
* @param feature the feature
* @param modelFormat the modelFormat
*/
public Builder(String collectionId, String feature, String modelFormat) {
this.collectionId = collectionId;
this.feature = feature;
this.modelFormat = modelFormat;
}

/**
* Builds a GetModelFileOptions.
*
* @return the getModelFileOptions
*/
public GetModelFileOptions build() {
return new GetModelFileOptions(this);
}

/**
* Set the collectionId.
*
* @param collectionId the collectionId
* @return the GetModelFileOptions builder
*/
public Builder collectionId(String collectionId) {
this.collectionId = collectionId;
return this;
}

/**
* Set the feature.
*
* @param feature the feature
* @return the GetModelFileOptions builder
*/
public Builder feature(String feature) {
this.feature = feature;
return this;
}

/**
* Set the modelFormat.
*
* @param modelFormat the modelFormat
* @return the GetModelFileOptions builder
*/
public Builder modelFormat(String modelFormat) {
this.modelFormat = modelFormat;
return this;
}
}

protected GetModelFileOptions(Builder builder) {
com.ibm.cloud.sdk.core.util.Validator.notEmpty(
builder.collectionId, "collectionId cannot be empty");
com.ibm.cloud.sdk.core.util.Validator.notNull(builder.feature, "feature cannot be null");
com.ibm.cloud.sdk.core.util.Validator.notNull(
builder.modelFormat, "modelFormat cannot be null");
collectionId = builder.collectionId;
feature = builder.feature;
modelFormat = builder.modelFormat;
}

/**
* New builder.
*
* @return a GetModelFileOptions builder
*/
public Builder newBuilder() {
return new Builder(this);
}

/**
* Gets the collectionId.
*
* <p>The identifier of the collection.
*
* @return the collectionId
*/
public String collectionId() {
return collectionId;
}

/**
* Gets the feature.
*
* <p>The feature for the model.
*
* @return the feature
*/
public String feature() {
return feature;
}

/**
* Gets the modelFormat.
*
* <p>The format of the returned model.
*
* @return the modelFormat
*/
public String modelFormat() {
return modelFormat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class ObjectTrainingStatus extends GenericModel {
@SerializedName("latest_failed")
protected Boolean latestFailed;

@SerializedName("rscnn_ready")
protected Boolean rscnnReady;

protected String description;

/** Builder. */
Expand All @@ -37,13 +40,15 @@ public static class Builder {
private Boolean inProgress;
private Boolean dataChanged;
private Boolean latestFailed;
private Boolean rscnnReady;
private String description;

private Builder(ObjectTrainingStatus objectTrainingStatus) {
this.ready = objectTrainingStatus.ready;
this.inProgress = objectTrainingStatus.inProgress;
this.dataChanged = objectTrainingStatus.dataChanged;
this.latestFailed = objectTrainingStatus.latestFailed;
this.rscnnReady = objectTrainingStatus.rscnnReady;
this.description = objectTrainingStatus.description;
}

Expand All @@ -57,18 +62,21 @@ public Builder() {}
* @param inProgress the inProgress
* @param dataChanged the dataChanged
* @param latestFailed the latestFailed
* @param rscnnReady the rscnnReady
* @param description the description
*/
public Builder(
Boolean ready,
Boolean inProgress,
Boolean dataChanged,
Boolean latestFailed,
Boolean rscnnReady,
String description) {
this.ready = ready;
this.inProgress = inProgress;
this.dataChanged = dataChanged;
this.latestFailed = latestFailed;
this.rscnnReady = rscnnReady;
this.description = description;
}

Expand Down Expand Up @@ -125,6 +133,17 @@ public Builder latestFailed(Boolean latestFailed) {
return this;
}

/**
* Set the rscnnReady.
*
* @param rscnnReady the rscnnReady
* @return the ObjectTrainingStatus builder
*/
public Builder rscnnReady(Boolean rscnnReady) {
this.rscnnReady = rscnnReady;
return this;
}

/**
* Set the description.
*
Expand All @@ -144,12 +163,14 @@ protected ObjectTrainingStatus(Builder builder) {
builder.dataChanged, "dataChanged cannot be null");
com.ibm.cloud.sdk.core.util.Validator.notNull(
builder.latestFailed, "latestFailed cannot be null");
com.ibm.cloud.sdk.core.util.Validator.notNull(builder.rscnnReady, "rscnnReady cannot be null");
com.ibm.cloud.sdk.core.util.Validator.notNull(
builder.description, "description cannot be null");
ready = builder.ready;
inProgress = builder.inProgress;
dataChanged = builder.dataChanged;
latestFailed = builder.latestFailed;
rscnnReady = builder.rscnnReady;
description = builder.description;
}

Expand Down Expand Up @@ -206,6 +227,17 @@ public Boolean latestFailed() {
return latestFailed;
}

/**
* Gets the rscnnReady.
*
* <p>Whether the model can be downloaded after the training status is `ready`.
*
* @return the rscnnReady
*/
public Boolean rscnnReady() {
return rscnnReady;
}

/**
* Gets the description.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.ibm.watson.visual_recognition.v4.model.GetCollectionOptions;
import com.ibm.watson.visual_recognition.v4.model.GetImageDetailsOptions;
import com.ibm.watson.visual_recognition.v4.model.GetJpegImageOptions;
import com.ibm.watson.visual_recognition.v4.model.GetModelFileOptions;
import com.ibm.watson.visual_recognition.v4.model.GetTrainingUsageOptions;
import com.ibm.watson.visual_recognition.v4.model.ImageDetails;
import com.ibm.watson.visual_recognition.v4.model.ImageDetailsList;
Expand Down Expand Up @@ -59,8 +60,7 @@
public class VisualRecognitionIT extends WatsonServiceTest {
private static final String VERSION = "2019-02-11";
private static final String RESOURCE = "src/test/resources/visual_recognition/v4/";

private static final String COLLECTION_ID = "10e96193-0e08-406b-b8fb-b5b9ea9fe99a";
private static final String COLLECTION_ID = "a06f7036-0529-49ee-bdf6-82ddec276923";
private static final String GIRAFFE_CLASSNAME = "giraffe";
private static final String SINGLE_GIRAFFE_IMAGE_PATH = RESOURCE + "giraffe_to_classify.jpg";
private static final String GIRAFFE_POSITIVE_EXAMPLES_PATH =
Expand Down Expand Up @@ -380,6 +380,19 @@ public void testTrainingOperations() throws FileNotFoundException {
}
}

@Test
public void testGetModelFile() {
GetModelFileOptions options =
new GetModelFileOptions.Builder()
.collectionId(COLLECTION_ID)
.feature("objects")
.modelFormat("rscnn")
.build();
int statusCode = service.getModelFile(options).execute().getStatusCode();

assertEquals(200, statusCode);
}

@Test
public void testDeleteUserData() {
DeleteUserDataOptions deleteUserDataOptions =
Expand Down

0 comments on commit 681f9f8

Please sign in to comment.