Search in sources :

Example 41 with ModelName

use of com.google.cloud.aiplatform.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 {
    // 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());
    }
}
Also used : ModelName(com.google.cloud.automl.v1.ModelName) Model(com.google.cloud.automl.v1.Model) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 42 with ModelName

use of com.google.cloud.aiplatform.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());
    }
}
Also used : ModelName(com.google.cloud.automl.v1beta1.ModelName) Model(com.google.cloud.automl.v1beta1.Model) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 43 with ModelName

use of com.google.cloud.aiplatform.v1.ModelName in project java-automl by googleapis.

the class ListModelEvaluations method listModelEvaluations.

// List model evaluations
static void listModelEvaluations(String projectId, String modelId) throws IOException {
    // 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);
        ListModelEvaluationsRequest modelEvaluationsrequest = ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();
        // List all the model evaluations in the model by applying filter.
        System.out.println("List of model evaluations:");
        for (ModelEvaluation modelEvaluation : client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
            System.out.format("Model Evaluation Name: %s%n", modelEvaluation.getName());
            System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId());
            System.out.println("Create Time:");
            System.out.format("\tseconds: %s%n", modelEvaluation.getCreateTime().getSeconds());
            System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9);
            System.out.format("Evalution Example Count: %d%n", modelEvaluation.getEvaluatedExampleCount());
            System.out.format("Tables Model Evaluation Metrics: %s%n", modelEvaluation.getClassificationEvaluationMetrics());
        }
    }
}
Also used : ModelEvaluation(com.google.cloud.automl.v1beta1.ModelEvaluation) ModelName(com.google.cloud.automl.v1beta1.ModelName) ListModelEvaluationsRequest(com.google.cloud.automl.v1beta1.ListModelEvaluationsRequest) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 44 with ModelName

use of com.google.cloud.aiplatform.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);
}
Also used : DeployModelRequest(com.google.cloud.automl.v1.DeployModelRequest) PrintStream(java.io.PrintStream) ModelName(com.google.cloud.automl.v1.ModelName) Model(com.google.cloud.automl.v1.Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) Before(org.junit.Before)

Example 45 with ModelName

use of com.google.cloud.aiplatform.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);
}
Also used : DeployModelRequest(com.google.cloud.automl.v1.DeployModelRequest) PrintStream(java.io.PrintStream) ModelName(com.google.cloud.automl.v1.ModelName) Model(com.google.cloud.automl.v1.Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) Before(org.junit.Before)

Aggregations

ModelName (com.google.cloud.automl.v1.ModelName)24 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)16 ModelName (com.google.cloud.automl.v1beta1.ModelName)15 Empty (com.google.protobuf.Empty)14 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)11 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)10 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)10 ModelName (com.google.cloud.aiplatform.v1.ModelName)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 PrintStream (java.io.PrintStream)9 Before (org.junit.Before)9 BatchPredictionJob (com.google.cloud.aiplatform.v1.BatchPredictionJob)8 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)8 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)8 LocationName (com.google.cloud.aiplatform.v1.LocationName)8 Model (com.google.cloud.automl.v1.Model)8 PredictionServiceClient (com.google.cloud.automl.v1.PredictionServiceClient)8 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)7 ExamplePayload (com.google.cloud.automl.v1.ExamplePayload)7 PredictResponse (com.google.cloud.automl.v1.PredictResponse)7