use of com.google.cloud.automl.v1.ModelName in project java-automl by googleapis.
the class LanguageEntityExtractionPredictTest method setUp.
@Before
public void setUp() throws IOException, ExecutionException, InterruptedException {
// Verify that the model is deployed for prediction
try (AutoMlClient client = AutoMlClient.create()) {
ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID);
Model model = client.getModel(modelFullId);
if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) {
// Deploy the model if not deployed
DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
client.deployModelAsync(request).get();
}
}
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}
use of com.google.cloud.automl.v1.ModelName in project java-automl by googleapis.
the class LanguageTextClassificationPredictTest method setUp.
@Before
public void setUp() throws IOException, ExecutionException, InterruptedException {
// Verify that the model is deployed for prediction
try (AutoMlClient client = AutoMlClient.create()) {
ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID);
Model model = client.getModel(modelFullId);
if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) {
// Deploy the model if not deployed
DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
client.deployModelAsync(request).get();
}
}
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}
use of com.google.cloud.automl.v1.ModelName in project java-automl by googleapis.
the class VisionClassificationPredictTest method setUp.
@Before
public void setUp() throws IOException, ExecutionException, InterruptedException {
// Verify that the model is deployed for prediction
try (AutoMlClient client = AutoMlClient.create()) {
ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID);
Model model = client.getModel(modelFullId);
if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) {
// Deploy the model if not deployed
DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
client.deployModelAsync(request).get();
}
}
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}
use of com.google.cloud.automl.v1.ModelName in project java-automl by googleapis.
the class AutoMlClientTest method listModelEvaluationsTest.
@Test
public void listModelEvaluationsTest() throws Exception {
ModelEvaluation responsesElement = ModelEvaluation.newBuilder().build();
ListModelEvaluationsResponse expectedResponse = ListModelEvaluationsResponse.newBuilder().setNextPageToken("").addAllModelEvaluation(Arrays.asList(responsesElement)).build();
mockAutoMl.addResponse(expectedResponse);
ModelName parent = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]");
String filter = "filter-1274492040";
ListModelEvaluationsPagedResponse pagedListResponse = client.listModelEvaluations(parent, filter);
List<ModelEvaluation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getModelEvaluationList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListModelEvaluationsRequest actualRequest = ((ListModelEvaluationsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(filter, actualRequest.getFilter());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.automl.v1.ModelName in project java-automl by googleapis.
the class GetModel method getModel.
// Get a model
static void getModel(String projectId, String modelId) throws IOException, StatusRuntimeException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// Get the full path of the model.
ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
Model model = client.getModel(modelFullId);
// Display the model information.
System.out.format("Model name: %s%n", model.getName());
// To get the model id, you have to parse it out of the `name` field. As models Ids are
// required for other methods.
// Name Format: `projects/{project_id}/locations/{location_id}/models/{model_id}`
String[] names = model.getName().split("/");
String retrievedModelId = names[names.length - 1];
System.out.format("Model id: %s%n", retrievedModelId);
System.out.format("Model display name: %s%n", model.getDisplayName());
System.out.println("Model create time:");
System.out.format("\tseconds: %s%n", model.getCreateTime().getSeconds());
System.out.format("\tnanos: %s%n", model.getCreateTime().getNanos());
System.out.format("Model deployment state: %s%n", model.getDeploymentState());
}
}
Aggregations