use of com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testGetCoreMlModel.
@Test
public void testGetCoreMlModel() throws IOException, InterruptedException {
final File model = new File("src/test/resources/visual_recognition/custom_model.mlmodel");
final Buffer buffer = new Buffer().write(Files.toByteArray(model));
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_OCTET_STREAM).setBody(buffer));
String classifierId = "classifier_id";
GetCoreMlModelOptions options = new GetCoreMlModelOptions.Builder().classifierId(classifierId).build();
InputStream modelFile = service.getCoreMlModel(options).execute();
RecordedRequest request = server.takeRequest();
String path = String.format(PATH_CORE_ML, classifierId) + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY;
assertEquals(path, request.getPath());
assertEquals("GET", request.getMethod());
writeInputStreamToFile(modelFile, new File("build/model_result.mlmodel"));
}
use of com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testGetCoreMlModelWOptions.
@Test
public void testGetCoreMlModelWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "This is a mock binary response.";
String getCoreMlModelPath = "/v3/classifiers/testString/core_ml_model";
server.enqueue(new MockResponse().setHeader("Content-type", "application/octet-stream").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetCoreMlModelOptions model
GetCoreMlModelOptions getCoreMlModelOptionsModel = new GetCoreMlModelOptions.Builder().classifierId("testString").build();
// Invoke operation with valid options model (positive test)
Response<InputStream> response = visualRecognitionService.getCoreMlModel(getCoreMlModelOptionsModel).execute();
assertNotNull(response);
InputStream responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getCoreMlModelPath);
}
use of com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testGetCoreMlModel.
/**
* Test getting the Core ML file for a classifier.
*/
@Ignore
@Test
public void testGetCoreMlModel() {
ListClassifiersOptions options = new ListClassifiersOptions.Builder().verbose(true).build();
List<Classifier> classifiers = service.listClassifiers(options).execute().getResult().getClassifiers();
for (Classifier classifier : classifiers) {
if (classifier.isCoreMlEnabled()) {
GetCoreMlModelOptions getCoreMlModelOptions = new GetCoreMlModelOptions.Builder().classifierId(classifier.getClassifierId()).build();
InputStream coreMlFile = service.getCoreMlModel(getCoreMlModelOptions).execute().getResult();
assertNotNull(coreMlFile);
break;
}
}
}
use of com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testGetCoreMlModel.
/**
* Test getting the Core ML file for a classifier.
*/
@Ignore
@Test
public void testGetCoreMlModel() {
ListClassifiersOptions options = new ListClassifiersOptions.Builder().verbose(true).build();
List<Classifier> classifiers = service.listClassifiers(options).execute().getClassifiers();
for (Classifier classifier : classifiers) {
if (classifier.isCoreMlEnabled()) {
GetCoreMlModelOptions getCoreMlModelOptions = new GetCoreMlModelOptions.Builder().classifierId(classifier.getClassifierId()).build();
InputStream coreMlFile = service.getCoreMlModel(getCoreMlModelOptions).execute();
assertNotNull(coreMlFile);
break;
}
}
}
Aggregations