Search in sources :

Example 6 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.

the class MetadataServiceClientTest method listMetadataStoresTest.

@Test
public void listMetadataStoresTest() throws Exception {
    MetadataStore responsesElement = MetadataStore.newBuilder().build();
    ListMetadataStoresResponse expectedResponse = ListMetadataStoresResponse.newBuilder().setNextPageToken("").addAllMetadataStores(Arrays.asList(responsesElement)).build();
    mockMetadataService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListMetadataStoresPagedResponse pagedListResponse = client.listMetadataStores(parent);
    List<MetadataStore> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMetadataStoresList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockMetadataService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListMetadataStoresRequest actualRequest = ((ListMetadataStoresRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListMetadataStoresPagedResponse(com.google.cloud.aiplatform.v1beta1.MetadataServiceClient.ListMetadataStoresPagedResponse) Test(org.junit.Test)

Example 7 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.

the class CreateDatasetVideoSample method createDatasetSample.

static void createDatasetSample(String datasetVideoDisplayName, String project) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    DatasetServiceSettings datasetServiceSettings = DatasetServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DatasetServiceClient datasetServiceClient = DatasetServiceClient.create(datasetServiceSettings)) {
        String location = "us-central1";
        String metadataSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/metadata/video_1.0.0.yaml";
        LocationName locationName = LocationName.of(project, location);
        Dataset dataset = Dataset.newBuilder().setDisplayName(datasetVideoDisplayName).setMetadataSchemaUri(metadataSchemaUri).build();
        OperationFuture<Dataset, CreateDatasetOperationMetadata> datasetFuture = datasetServiceClient.createDatasetAsync(locationName, dataset);
        System.out.format("Operation name: %s\n", datasetFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        Dataset datasetResponse = datasetFuture.get(300, TimeUnit.SECONDS);
        System.out.println("Create Dataset Video Response");
        System.out.format("Name: %s\n", datasetResponse.getName());
        System.out.format("Display Name: %s\n", datasetResponse.getDisplayName());
        System.out.format("Metadata Schema Uri: %s\n", datasetResponse.getMetadataSchemaUri());
        System.out.format("Metadata: %s\n", datasetResponse.getMetadata());
        System.out.format("Create Time: %s\n", datasetResponse.getCreateTime());
        System.out.format("Update Time: %s\n", datasetResponse.getUpdateTime());
        System.out.format("Labels: %s\n", datasetResponse.getLabelsMap());
    }
}
Also used : DatasetServiceSettings(com.google.cloud.aiplatform.v1.DatasetServiceSettings) CreateDatasetOperationMetadata(com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata) Dataset(com.google.cloud.aiplatform.v1.Dataset) DatasetServiceClient(com.google.cloud.aiplatform.v1.DatasetServiceClient) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 8 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.

the class CreateEndpointSample method createEndpointSample.

static void createEndpointSample(String project, String endpointDisplayName) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    EndpointServiceSettings endpointServiceSettings = EndpointServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (EndpointServiceClient endpointServiceClient = EndpointServiceClient.create(endpointServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        Endpoint endpoint = Endpoint.newBuilder().setDisplayName(endpointDisplayName).build();
        OperationFuture<Endpoint, CreateEndpointOperationMetadata> endpointFuture = endpointServiceClient.createEndpointAsync(locationName, endpoint);
        System.out.format("Operation name: %s\n", endpointFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        Endpoint endpointResponse = endpointFuture.get(300, TimeUnit.SECONDS);
        System.out.println("Create Endpoint Response");
        System.out.format("Name: %s\n", endpointResponse.getName());
        System.out.format("Display Name: %s\n", endpointResponse.getDisplayName());
        System.out.format("Description: %s\n", endpointResponse.getDescription());
        System.out.format("Labels: %s\n", endpointResponse.getLabelsMap());
        System.out.format("Create Time: %s\n", endpointResponse.getCreateTime());
        System.out.format("Update Time: %s\n", endpointResponse.getUpdateTime());
    }
}
Also used : Endpoint(com.google.cloud.aiplatform.v1.Endpoint) EndpointServiceClient(com.google.cloud.aiplatform.v1.EndpointServiceClient) CreateEndpointOperationMetadata(com.google.cloud.aiplatform.v1.CreateEndpointOperationMetadata) EndpointServiceSettings(com.google.cloud.aiplatform.v1.EndpointServiceSettings) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 9 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.

the class CreateHyperparameterTuningJobSample method createHyperparameterTuningJobSample.

static void createHyperparameterTuningJobSample(String project, String displayName, String containerImageUri) throws IOException {
    JobServiceSettings settings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    String location = "us-central1";
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient client = JobServiceClient.create(settings)) {
        StudySpec.MetricSpec metric0 = StudySpec.MetricSpec.newBuilder().setMetricId("accuracy").setGoal(StudySpec.MetricSpec.GoalType.MAXIMIZE).build();
        StudySpec.ParameterSpec.DoubleValueSpec doubleValueSpec = StudySpec.ParameterSpec.DoubleValueSpec.newBuilder().setMinValue(0.001).setMaxValue(0.1).build();
        StudySpec.ParameterSpec parameter0 = StudySpec.ParameterSpec.newBuilder().setParameterId("lr").setDoubleValueSpec(doubleValueSpec).build();
        StudySpec studySpec = StudySpec.newBuilder().addMetrics(metric0).addParameters(parameter0).build();
        MachineSpec machineSpec = MachineSpec.newBuilder().setMachineType("n1-standard-4").setAcceleratorType(AcceleratorType.NVIDIA_TESLA_K80).setAcceleratorCount(1).build();
        ContainerSpec containerSpec = ContainerSpec.newBuilder().setImageUri(containerImageUri).build();
        WorkerPoolSpec workerPoolSpec0 = WorkerPoolSpec.newBuilder().setMachineSpec(machineSpec).setReplicaCount(1).setContainerSpec(containerSpec).build();
        CustomJobSpec trialJobSpec = CustomJobSpec.newBuilder().addWorkerPoolSpecs(workerPoolSpec0).build();
        HyperparameterTuningJob hyperparameterTuningJob = HyperparameterTuningJob.newBuilder().setDisplayName(displayName).setMaxTrialCount(2).setParallelTrialCount(1).setMaxFailedTrialCount(1).setStudySpec(studySpec).setTrialJobSpec(trialJobSpec).build();
        LocationName parent = LocationName.of(project, location);
        HyperparameterTuningJob response = client.createHyperparameterTuningJob(parent, hyperparameterTuningJob);
        System.out.format("response: %s\n", response);
        System.out.format("Name: %s\n", response.getName());
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) StudySpec(com.google.cloud.aiplatform.v1.StudySpec) ContainerSpec(com.google.cloud.aiplatform.v1.ContainerSpec) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) CustomJobSpec(com.google.cloud.aiplatform.v1.CustomJobSpec) MachineSpec(com.google.cloud.aiplatform.v1.MachineSpec) LocationName(com.google.cloud.aiplatform.v1.LocationName) HyperparameterTuningJob(com.google.cloud.aiplatform.v1.HyperparameterTuningJob) WorkerPoolSpec(com.google.cloud.aiplatform.v1.WorkerPoolSpec)

Example 10 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.

the class CreateTrainingPipelineCustomTrainingManagedDatasetSample method createTrainingPipelineCustomTrainingManagedDatasetSample.

static void createTrainingPipelineCustomTrainingManagedDatasetSample(String project, String displayName, String modelDisplayName, String datasetId, String annotationSchemaUri, String trainingContainerSpecImageUri, String modelContainerSpecImageUri, String baseOutputUriPrefix) throws IOException {
    PipelineServiceSettings settings = PipelineServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    String location = "us-central1";
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PipelineServiceClient client = PipelineServiceClient.create(settings)) {
        JsonArray jsonArgs = new JsonArray();
        jsonArgs.add("--model-dir=$(AIP_MODEL_DIR)");
        // training_task_inputs
        JsonObject jsonTrainingContainerSpec = new JsonObject();
        jsonTrainingContainerSpec.addProperty("imageUri", trainingContainerSpecImageUri);
        // AIP_MODEL_DIR is set by the service according to baseOutputDirectory.
        jsonTrainingContainerSpec.add("args", jsonArgs);
        JsonObject jsonMachineSpec = new JsonObject();
        jsonMachineSpec.addProperty("machineType", "n1-standard-8");
        JsonObject jsonTrainingWorkerPoolSpec = new JsonObject();
        jsonTrainingWorkerPoolSpec.addProperty("replicaCount", 1);
        jsonTrainingWorkerPoolSpec.add("machineSpec", jsonMachineSpec);
        jsonTrainingWorkerPoolSpec.add("containerSpec", jsonTrainingContainerSpec);
        JsonArray jsonWorkerPoolSpecs = new JsonArray();
        jsonWorkerPoolSpecs.add(jsonTrainingWorkerPoolSpec);
        JsonObject jsonBaseOutputDirectory = new JsonObject();
        jsonBaseOutputDirectory.addProperty("outputUriPrefix", baseOutputUriPrefix);
        JsonObject jsonTrainingTaskInputs = new JsonObject();
        jsonTrainingTaskInputs.add("workerPoolSpecs", jsonWorkerPoolSpecs);
        jsonTrainingTaskInputs.add("baseOutputDirectory", jsonBaseOutputDirectory);
        Value.Builder trainingTaskInputsBuilder = Value.newBuilder();
        JsonFormat.parser().merge(jsonTrainingTaskInputs.toString(), trainingTaskInputsBuilder);
        Value trainingTaskInputs = trainingTaskInputsBuilder.build();
        // model_to_upload
        ModelContainerSpec modelContainerSpec = ModelContainerSpec.newBuilder().setImageUri(modelContainerSpecImageUri).build();
        Model model = Model.newBuilder().setDisplayName(modelDisplayName).setContainerSpec(modelContainerSpec).build();
        GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(baseOutputUriPrefix).build();
        // input_data_config
        InputDataConfig inputDataConfig = InputDataConfig.newBuilder().setDatasetId(datasetId).setAnnotationSchemaUri(annotationSchemaUri).setGcsDestination(gcsDestination).build();
        // training_task_definition
        String customTaskDefinition = "gs://google-cloud-aiplatform/schema/trainingjob/definition/custom_task_1.0.0.yaml";
        TrainingPipeline trainingPipeline = TrainingPipeline.newBuilder().setDisplayName(displayName).setInputDataConfig(inputDataConfig).setTrainingTaskDefinition(customTaskDefinition).setTrainingTaskInputs(trainingTaskInputs).setModelToUpload(model).build();
        LocationName parent = LocationName.of(project, location);
        TrainingPipeline response = client.createTrainingPipeline(parent, trainingPipeline);
        System.out.format("response: %s\n", response);
        System.out.format("Name: %s\n", response.getName());
    }
}
Also used : TrainingPipeline(com.google.cloud.aiplatform.v1.TrainingPipeline) JsonObject(com.google.gson.JsonObject) InputDataConfig(com.google.cloud.aiplatform.v1.InputDataConfig) LocationName(com.google.cloud.aiplatform.v1.LocationName) JsonArray(com.google.gson.JsonArray) ModelContainerSpec(com.google.cloud.aiplatform.v1.ModelContainerSpec) Value(com.google.protobuf.Value) Model(com.google.cloud.aiplatform.v1.Model) PipelineServiceSettings(com.google.cloud.aiplatform.v1.PipelineServiceSettings) PipelineServiceClient(com.google.cloud.aiplatform.v1.PipelineServiceClient) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination)

Aggregations

Test (org.junit.Test)54 AbstractMessage (com.google.protobuf.AbstractMessage)37 LocationName (com.google.cloud.aiplatform.v1.LocationName)36 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 LocationName (com.google.cloud.translate.v3beta1.LocationName)18 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)18 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)15 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)15 Value (com.google.protobuf.Value)15 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)14 Model (com.google.cloud.aiplatform.v1.Model)14 StatusRuntimeException (io.grpc.StatusRuntimeException)14 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)13 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)13 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)13 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)13