Search in sources :

Example 1 with GetCoreMlModelOptions

use of com.ibm.watson.developer_cloud.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"));
}
Also used : Buffer(okio.Buffer) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) GetCoreMlModelOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetCoreMlModelOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with GetCoreMlModelOptions

use of com.ibm.watson.developer_cloud.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;
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ListClassifiersOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) GetCoreMlModelOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetCoreMlModelOptions) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

GetCoreMlModelOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetCoreMlModelOptions)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)1 ListClassifiersOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions)1 File (java.io.File)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Buffer (okio.Buffer)1 Ignore (org.junit.Ignore)1