use of com.google.cloud.aiplatform.v1.DatasetName in project java-aiplatform by googleapis.
the class ImportDataVideoObjectTrackingSample method importDataVideObjectTracking.
static void importDataVideObjectTracking(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_object_tracking_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(300, TimeUnit.SECONDS);
System.out.format("Import Data Video Object Tracking Response: %s\n", importDataResponse.toString());
}
}
use of com.google.cloud.aiplatform.v1.DatasetName in project java-aiplatform by googleapis.
the class ImportDataImageClassificationSample method importDataImageClassificationSample.
static void importDataImageClassificationSample(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/" + "image_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 Image Classification Response: %s\n", importDataResponse.toString());
}
}
use of com.google.cloud.aiplatform.v1.DatasetName in project java-aiplatform by googleapis.
the class DatasetServiceClientTest method listDataItemsTest.
@Test
public void listDataItemsTest() throws Exception {
DataItem responsesElement = DataItem.newBuilder().build();
ListDataItemsResponse expectedResponse = ListDataItemsResponse.newBuilder().setNextPageToken("").addAllDataItems(Arrays.asList(responsesElement)).build();
mockDatasetService.addResponse(expectedResponse);
DatasetName parent = DatasetName.of("[PROJECT]", "[LOCATION]", "[DATASET]");
ListDataItemsPagedResponse pagedListResponse = client.listDataItems(parent);
List<DataItem> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDataItemsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatasetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDataItemsRequest actualRequest = ((ListDataItemsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.aiplatform.v1.DatasetName in project java-aiplatform by googleapis.
the class CreateDataLabelingJobSpecialistPoolSample method createDataLabelingJobSpecialistPoolSample.
static void createDataLabelingJobSpecialistPoolSample(String project, String displayName, String dataset, String specialistPool, String instructionUri, String inputsSchemaUri, String annotationSpec) 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)) {
JsonArray jsonAnnotationSpecs = new JsonArray();
jsonAnnotationSpecs.add(annotationSpec);
JsonObject jsonInputs = new JsonObject();
jsonInputs.add("annotation_specs", jsonAnnotationSpecs);
Value.Builder inputsBuilder = Value.newBuilder();
JsonFormat.parser().merge(jsonInputs.toString(), inputsBuilder);
Value inputs = inputsBuilder.build();
String datasetName = DatasetName.of(project, location, dataset).toString();
String specialistPoolName = SpecialistPoolName.of(project, location, specialistPool).toString();
DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).addDatasets(datasetName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri(inputsSchemaUri).setInputs(inputs).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "data_labeling_job_specialist_pool").addSpecialistPools(specialistPoolName).build();
LocationName parent = LocationName.of(project, location);
DataLabelingJob response = client.createDataLabelingJob(parent, dataLabelingJob);
System.out.format("response: %s\n", response);
}
}
use of com.google.cloud.aiplatform.v1.DatasetName in project java-aiplatform by googleapis.
the class CreateDataLabelingJobVideoSample method createDataLabelingJobVideo.
static void createDataLabelingJobVideo(String project, String displayName, String datasetId, String instructionUri, String annotationSpec) 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";
LocationName locationName = LocationName.of(project, location);
String jsonString = "{\"annotation_specs\": [ " + annotationSpec + "]}";
Value.Builder annotationSpecValue = Value.newBuilder();
JsonFormat.parser().merge(jsonString, annotationSpecValue);
DatasetName datasetName = DatasetName.of(project, location, datasetId);
DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri("gs://google-cloud-aiplatform/schema/datalabelingjob/inputs/" + "video_classification.yaml").addDatasets(datasetName.toString()).setInputs(annotationSpecValue).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "my_test_saved_query").build();
DataLabelingJob dataLabelingJobResponse = jobServiceClient.createDataLabelingJob(locationName, dataLabelingJob);
System.out.println("Create Data Labeling Job Video Response");
System.out.format("\tName: %s\n", dataLabelingJobResponse.getName());
System.out.format("\tDisplay Name: %s\n", dataLabelingJobResponse.getDisplayName());
System.out.format("\tDatasets: %s\n", dataLabelingJobResponse.getDatasetsList());
System.out.format("\tLabeler Count: %s\n", dataLabelingJobResponse.getLabelerCount());
System.out.format("\tInstruction Uri: %s\n", dataLabelingJobResponse.getInstructionUri());
System.out.format("\tInputs Schema Uri: %s\n", dataLabelingJobResponse.getInputsSchemaUri());
System.out.format("\tInputs: %s\n", dataLabelingJobResponse.getInputs());
System.out.format("\tState: %s\n", dataLabelingJobResponse.getState());
System.out.format("\tLabeling Progress: %s\n", dataLabelingJobResponse.getLabelingProgress());
System.out.format("\tCreate Time: %s\n", dataLabelingJobResponse.getCreateTime());
System.out.format("\tUpdate Time: %s\n", dataLabelingJobResponse.getUpdateTime());
System.out.format("\tLabels: %s\n", dataLabelingJobResponse.getLabelsMap());
System.out.format("\tSpecialist Pools: %s\n", dataLabelingJobResponse.getSpecialistPoolsList());
for (Map.Entry<String, String> annotationLabelMap : dataLabelingJobResponse.getAnnotationLabelsMap().entrySet()) {
System.out.println("\tAnnotation Level");
System.out.format("\t\tkey: %s\n", annotationLabelMap.getKey());
System.out.format("\t\tvalue: %s\n", annotationLabelMap.getValue());
}
Money money = dataLabelingJobResponse.getCurrentSpend();
System.out.println("\tCurrent Spend");
System.out.format("\t\tCurrency Code: %s\n", money.getCurrencyCode());
System.out.format("\t\tUnits: %s\n", money.getUnits());
System.out.format("\t\tNanos: %s\n", money.getNanos());
}
}
Aggregations