use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class CreateDataset method createDataset.
// Create a dataset that is initially empty.
static void createDataset(String projectId, String datasetName) throws IOException {
// String projectId = "YOUR_PROJECT_ID";
// String datasetName = "YOUR_DATASET_DISPLAY_NAME";
// [END datalabeling_create_dataset_beta]
String endpoint = System.getenv("DATALABELING_ENDPOINT");
if (endpoint == null) {
endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
}
// [START datalabeling_create_dataset_beta]
DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
ProjectName projectName = ProjectName.of(projectId);
Dataset dataset = Dataset.newBuilder().setDisplayName(datasetName).setDescription("YOUR_DESCRIPTION").build();
CreateDatasetRequest createDatasetRequest = CreateDatasetRequest.newBuilder().setParent(projectName.toString()).setDataset(dataset).build();
Dataset createdDataset = dataLabelingServiceClient.createDataset(createDatasetRequest);
System.out.format("Name: %s\n", createdDataset.getName());
System.out.format("DisplayName: %s\n", createdDataset.getDisplayName());
System.out.format("Description: %s\n", createdDataset.getDescription());
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class ExportData method exportData.
// Export data from an annotated dataset.
static void exportData(String datasetName, String annotatedDatasetName, String gcsOutputUri) throws IOException {
// String datasetName = DataLabelingServiceClient.formatDatasetName(
// "YOUR_PROJECT_ID", "YOUR_DATASETS_UUID");
// String annotatedDatasetName = DataLabelingServiceClient.formatAnnotatedDatasetName(
// "YOUR_PROJECT_ID",
// "YOUR_DATASET_UUID",
// "YOUR_ANNOTATED_DATASET_UUID");
// String gcsOutputUri = "gs://YOUR_BUCKET_ID/export_path";
// [END datalabeling_export_data_beta]
String endpoint = System.getenv("DATALABELING_ENDPOINT");
if (endpoint == null) {
endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
}
// [START datalabeling_export_data_beta]
DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUri(gcsOutputUri).setMimeType("text/csv").build();
OutputConfig outputConfig = OutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
ExportDataRequest exportDataRequest = ExportDataRequest.newBuilder().setName(datasetName).setOutputConfig(outputConfig).setAnnotatedDataset(annotatedDatasetName).build();
OperationFuture<ExportDataOperationResponse, ExportDataOperationMetadata> operation = dataLabelingServiceClient.exportDataAsync(exportDataRequest);
ExportDataOperationResponse response = operation.get();
System.out.format("Exported item count: %d\n", response.getExportCount());
LabelStats labelStats = response.getLabelStats();
Set<Entry<String, Long>> entries = labelStats.getExampleCountMap().entrySet();
for (Entry<String, Long> entry : entries) {
System.out.format("\tLabel: %s\n", entry.getKey());
System.out.format("\tCount: %d\n\n", entry.getValue());
}
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class ImportData method importData.
// Import data to an existing dataset.
static void importData(String datasetName, String gcsSourceUri) throws IOException {
// String datasetName = DataLabelingServiceClient.formatDatasetName(
// "YOUR_PROJECT_ID", "YOUR_DATASETS_UUID");
// String gcsSourceUri = "gs://YOUR_BUCKET_ID/path_to_data";
// [END datalabeling_import_data_beta]
String endpoint = System.getenv("DATALABELING_ENDPOINT");
if (endpoint == null) {
endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
}
// [START datalabeling_import_data_beta]
DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
GcsSource gcsSource = GcsSource.newBuilder().setInputUri(gcsSourceUri).setMimeType("text/csv").build();
InputConfig inputConfig = InputConfig.newBuilder().setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
DataType.IMAGE).setGcsSource(gcsSource).build();
ImportDataRequest importDataRequest = ImportDataRequest.newBuilder().setName(datasetName).setInputConfig(inputConfig).build();
OperationFuture<ImportDataOperationResponse, ImportDataOperationMetadata> operation = dataLabelingServiceClient.importDataAsync(importDataRequest);
ImportDataOperationResponse response = operation.get();
System.out.format("Imported items: %d\n", response.getImportCount());
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
use of com.google.cloud.datalabeling.v1beta1.Dataset in project java-datalabeling by googleapis.
the class DataLabelingServiceClientTest method searchEvaluationsTest.
@Test
public void searchEvaluationsTest() throws Exception {
Evaluation responsesElement = Evaluation.newBuilder().build();
SearchEvaluationsResponse expectedResponse = SearchEvaluationsResponse.newBuilder().setNextPageToken("").addAllEvaluations(Arrays.asList(responsesElement)).build();
mockDataLabelingService.addResponse(expectedResponse);
EvaluationName parent = EvaluationName.of("[PROJECT]", "[DATASET]", "[EVALUATION]");
String filter = "filter-1274492040";
SearchEvaluationsPagedResponse pagedListResponse = client.searchEvaluations(parent, filter);
List<Evaluation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getEvaluationsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDataLabelingService.getRequests();
Assert.assertEquals(1, actualRequests.size());
SearchEvaluationsRequest actualRequest = ((SearchEvaluationsRequest) 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.datalabeling.v1beta1.Dataset in project java-aiplatform by googleapis.
the class ImportDataVideoObjectTrackingSampleTest method setUp.
@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException, IOException {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
// create a temp dataset for importing data
DatasetServiceSettings datasetServiceSettings = DatasetServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
try (DatasetServiceClient datasetServiceClient = DatasetServiceClient.create(datasetServiceSettings)) {
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("test_dataset_display_name").setMetadataSchemaUri(metadataSchemaUri).build();
OperationFuture<Dataset, CreateDatasetOperationMetadata> datasetFuture = datasetServiceClient.createDatasetAsync(locationName, dataset);
Dataset datasetResponse = datasetFuture.get(300, TimeUnit.SECONDS);
String[] datasetValues = datasetResponse.getName().split("/");
datasetId = datasetValues[datasetValues.length - 1];
}
}
Aggregations