Search in sources :

Example 6 with Dataset

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

the class ImportDataTextClassificationSingleLabelSample method importDataTextClassificationSingleLabelSample.

static void importDataTextClassificationSingleLabelSample(String project, String datasetId, String gcsSourceUri) 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 importSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/ioformat/" + "text_classification_single_label_io_format_1.0.0.yaml";
        GcsSource.Builder gcsSource = GcsSource.newBuilder();
        gcsSource.addUris(gcsSourceUri);
        DatasetName datasetName = DatasetName.of(project, location, datasetId);
        List<ImportDataConfig> importDataConfigList = Collections.singletonList(ImportDataConfig.newBuilder().setGcsSource(gcsSource).setImportSchemaUri(importSchemaUri).build());
        OperationFuture<ImportDataResponse, ImportDataOperationMetadata> importDataResponseFuture = datasetServiceClient.importDataAsync(datasetName, importDataConfigList);
        System.out.format("Operation name: %s\n", importDataResponseFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        ImportDataResponse importDataResponse = importDataResponseFuture.get(300, TimeUnit.SECONDS);
        System.out.format("Import Data Text Classification Response: %s\n", importDataResponse.toString());
    }
}
Also used : ImportDataResponse(com.google.cloud.aiplatform.v1.ImportDataResponse) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) ImportDataConfig(com.google.cloud.aiplatform.v1.ImportDataConfig) DatasetServiceSettings(com.google.cloud.aiplatform.v1.DatasetServiceSettings) DatasetName(com.google.cloud.aiplatform.v1.DatasetName) DatasetServiceClient(com.google.cloud.aiplatform.v1.DatasetServiceClient) ImportDataOperationMetadata(com.google.cloud.aiplatform.v1.ImportDataOperationMetadata)

Example 7 with Dataset

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

the class ImportDataTextSentimentAnalysisSample method importDataTextSentimentAnalysisSample.

static void importDataTextSentimentAnalysisSample(String project, String datasetId, String gcsSourceUri) 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 importSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/ioformat/" + "text_sentiment_io_format_1.0.0.yaml";
        GcsSource.Builder gcsSource = GcsSource.newBuilder();
        gcsSource.addUris(gcsSourceUri);
        DatasetName datasetName = DatasetName.of(project, location, datasetId);
        List<ImportDataConfig> importDataConfigList = Collections.singletonList(ImportDataConfig.newBuilder().setGcsSource(gcsSource).setImportSchemaUri(importSchemaUri).build());
        OperationFuture<ImportDataResponse, ImportDataOperationMetadata> importDataResponseFuture = datasetServiceClient.importDataAsync(datasetName, importDataConfigList);
        System.out.format("Operation name: %s\n", importDataResponseFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        ImportDataResponse importDataResponse = importDataResponseFuture.get(300, TimeUnit.SECONDS);
        System.out.format("Import Data Text Sentiment Analysis Response: %s\n", importDataResponse.toString());
    }
}
Also used : ImportDataResponse(com.google.cloud.aiplatform.v1.ImportDataResponse) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) ImportDataConfig(com.google.cloud.aiplatform.v1.ImportDataConfig) DatasetServiceSettings(com.google.cloud.aiplatform.v1.DatasetServiceSettings) DatasetName(com.google.cloud.aiplatform.v1.DatasetName) DatasetServiceClient(com.google.cloud.aiplatform.v1.DatasetServiceClient) ImportDataOperationMetadata(com.google.cloud.aiplatform.v1.ImportDataOperationMetadata)

Example 8 with Dataset

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

the class ImportDataVideoClassificationSample method importDataVideoClassification.

static void importDataVideoClassification(String gcsSourceUri, String project, String datasetId) throws IOException, ExecutionException, InterruptedException, 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 importSchemaUri = "gs://google-cloud-aiplatform/schema/dataset/ioformat/" + "video_classification_io_format_1.0.0.yaml";
        GcsSource.Builder gcsSource = GcsSource.newBuilder();
        gcsSource.addUris(gcsSourceUri);
        DatasetName datasetName = DatasetName.of(project, location, datasetId);
        List<ImportDataConfig> importDataConfigs = Collections.singletonList(ImportDataConfig.newBuilder().setGcsSource(gcsSource).setImportSchemaUri(importSchemaUri).build());
        OperationFuture<ImportDataResponse, ImportDataOperationMetadata> importDataResponseFuture = datasetServiceClient.importDataAsync(datasetName, importDataConfigs);
        System.out.format("Operation name: %s\n", importDataResponseFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        ImportDataResponse importDataResponse = importDataResponseFuture.get(1800, TimeUnit.SECONDS);
        System.out.format("Import Data Video Classification Response: %s\n", importDataResponse.toString());
    }
}
Also used : ImportDataResponse(com.google.cloud.aiplatform.v1.ImportDataResponse) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) ImportDataConfig(com.google.cloud.aiplatform.v1.ImportDataConfig) DatasetServiceSettings(com.google.cloud.aiplatform.v1.DatasetServiceSettings) DatasetName(com.google.cloud.aiplatform.v1.DatasetName) DatasetServiceClient(com.google.cloud.aiplatform.v1.DatasetServiceClient) ImportDataOperationMetadata(com.google.cloud.aiplatform.v1.ImportDataOperationMetadata)

Example 9 with Dataset

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

the class GetBatchPredictionJobSample method getBatchPredictionJobSample.

static void getBatchPredictionJobSample(String project, String batchPredictionJobId) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        BatchPredictionJobName batchPredictionJobName = BatchPredictionJobName.of(project, location, batchPredictionJobId);
        BatchPredictionJob batchPredictionJob = jobServiceClient.getBatchPredictionJob(batchPredictionJobName);
        System.out.println("Get Batch Prediction Job Response");
        System.out.format("\tName: %s\n", batchPredictionJob.getName());
        System.out.format("\tDisplay Name: %s\n", batchPredictionJob.getDisplayName());
        System.out.format("\tModel: %s\n", batchPredictionJob.getModel());
        System.out.format("\tModel Parameters: %s\n", batchPredictionJob.getModelParameters());
        System.out.format("\tState: %s\n", batchPredictionJob.getState());
        System.out.format("\tCreate Time: %s\n", batchPredictionJob.getCreateTime());
        System.out.format("\tStart Time: %s\n", batchPredictionJob.getStartTime());
        System.out.format("\tEnd Time: %s\n", batchPredictionJob.getEndTime());
        System.out.format("\tUpdate Time: %s\n", batchPredictionJob.getUpdateTime());
        System.out.format("\tLabels: %s\n", batchPredictionJob.getLabelsMap());
        InputConfig inputConfig = batchPredictionJob.getInputConfig();
        System.out.println("\tInput Config");
        System.out.format("\t\tInstances Format: %s\n", inputConfig.getInstancesFormat());
        GcsSource gcsSource = inputConfig.getGcsSource();
        System.out.println("\t\tGcs Source");
        System.out.format("\t\t\tUris: %s\n", gcsSource.getUrisList());
        BigQuerySource bigquerySource = inputConfig.getBigquerySource();
        System.out.println("\t\tBigquery Source");
        System.out.format("\t\t\tInput Uri: %s\n", bigquerySource.getInputUri());
        OutputConfig outputConfig = batchPredictionJob.getOutputConfig();
        System.out.println("\tOutput Config");
        System.out.format("\t\tPredictions Format: %s\n", outputConfig.getPredictionsFormat());
        GcsDestination gcsDestination = outputConfig.getGcsDestination();
        System.out.println("\t\tGcs Destination");
        System.out.format("\t\t\tOutput Uri Prefix: %s\n", gcsDestination.getOutputUriPrefix());
        BigQueryDestination bigqueryDestination = outputConfig.getBigqueryDestination();
        System.out.println("\t\tBigquery Destination");
        System.out.format("\t\t\tOutput Uri: %s\n", bigqueryDestination.getOutputUri());
        OutputInfo outputInfo = batchPredictionJob.getOutputInfo();
        System.out.println("\tOutput Info");
        System.out.format("\t\tGcs Output Directory: %s\n", outputInfo.getGcsOutputDirectory());
        System.out.format("\t\tBigquery Output Dataset: %s\n", outputInfo.getBigqueryOutputDataset());
        Status status = batchPredictionJob.getError();
        System.out.println("\tError");
        System.out.format("\t\tCode: %s\n", status.getCode());
        System.out.format("\t\tMessage: %s\n", status.getMessage());
        List<Any> detailsList = status.getDetailsList();
        for (Status partialFailure : batchPredictionJob.getPartialFailuresList()) {
            System.out.println("\tPartial Failure");
            System.out.format("\t\tCode: %s\n", partialFailure.getCode());
            System.out.format("\t\tMessage: %s\n", partialFailure.getMessage());
            List<Any> details = partialFailure.getDetailsList();
        }
        ResourcesConsumed resourcesConsumed = batchPredictionJob.getResourcesConsumed();
        System.out.println("\tResources Consumed");
        System.out.format("\t\tReplica Hours: %s\n", resourcesConsumed.getReplicaHours());
        CompletionStats completionStats = batchPredictionJob.getCompletionStats();
        System.out.println("\tCompletion Stats");
        System.out.format("\t\tSuccessful Count: %s\n", completionStats.getSuccessfulCount());
        System.out.format("\t\tFailed Count: %s\n", completionStats.getFailedCount());
        System.out.format("\t\tIncomplete Count: %s\n", completionStats.getIncompleteCount());
    }
}
Also used : Status(com.google.rpc.Status) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) BigQueryDestination(com.google.cloud.aiplatform.v1.BigQueryDestination) Any(com.google.protobuf.Any) OutputInfo(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputInfo) OutputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputConfig) ResourcesConsumed(com.google.cloud.aiplatform.v1.ResourcesConsumed) BatchPredictionJobName(com.google.cloud.aiplatform.v1.BatchPredictionJobName) InputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.InputConfig) BigQuerySource(com.google.cloud.aiplatform.v1.BigQuerySource) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) CompletionStats(com.google.cloud.aiplatform.v1.CompletionStats)

Example 10 with Dataset

use of com.google.cloud.aiplatform.v1.Dataset 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)

Aggregations

DatasetServiceClient (com.google.cloud.aiplatform.v1.DatasetServiceClient)15 DatasetServiceSettings (com.google.cloud.aiplatform.v1.DatasetServiceSettings)15 LocationName (com.google.cloud.aiplatform.v1.LocationName)14 IOException (java.io.IOException)14 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 PrintStream (java.io.PrintStream)10 ArrayList (java.util.ArrayList)10 Before (org.junit.Before)10 DatasetName (com.google.cloud.aiplatform.v1.DatasetName)9 ImportDataConfig (com.google.cloud.aiplatform.v1.ImportDataConfig)8 ImportDataOperationMetadata (com.google.cloud.aiplatform.v1.ImportDataOperationMetadata)8 ImportDataResponse (com.google.cloud.aiplatform.v1.ImportDataResponse)8 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)8 Dataset (com.google.cloud.automl.v1.Dataset)8 LocationName (com.google.cloud.automl.v1.LocationName)7 Dataset (com.google.cloud.datalabeling.v1beta1.Dataset)7 CreateDatasetOperationMetadata (com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata)6 Dataset (com.google.cloud.aiplatform.v1.Dataset)6 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)6