API verwenden
Erfahren Sie, wie Sie die API mit Data Labeling verwenden.
Mit Data Labeling sind mehrere APIs verfügbar. Weitere Informationen zu den Befehlen finden Sie unter Data Labeling - API-Referenz und Data Labeling - Verwaltungs-API-Referenz.
Im Folgenden erfahren Sie, wie Sie mit Java oder Python Datasets, Datensätze und Annotationen erstellen. Es wird davon ausgegangen, dass Sie die Artifactory der dedizierten Exadata-Infrastruktur heruntergeladen und installiert haben.
Mit der API den Control-Plane- und Data-Plane-Client mit dem Java-SDK erstellen
Befolgen Sie dieses Beispiel zum Erstellen des Control-Plane- und Data-Plane-Clients für Data Labeling mit dem Java-SDK.
package com.oracle.dls.samples;
import com.oracle.bmc.ConfigFileReader;
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
import com.oracle.bmc.datalabelingservice.DataLabelingManagement;
import com.oracle.bmc.datalabelingservice.DataLabelingManagementClient;
import com.oracle.bmc.datalabelingservicedataplane.DataLabelingClient;
import java.io.IOException;
/**
* Sample Application class for creating singleton DataLabeling control plane and Data plane client.
*/
public class SampleApplication {
private static final String ENDPOINT = "https://dlsdev-cp.us-ashburn-1.oci.oraclecloud.com";
private static final String REGION = "us-ashburn-1";
private final static String CONFIG_LOCATION = "~/.oci/config";
private final static String CONFIG_PROFILE = "DEFAULT";
private static DataLabelingManagement cpClient = null;
private static DataLabelingClient dpClient = null;
private SampleApplication() {
}
public static DataLabelingManagement getDataLabelingCpClient() throws IOException {
if (cpClient == null) {
// Configuring the AuthenticationDetailsProvider. It's assuming there is a default OCI config file
// "~/.oci/config", and a profile in that config with the name defined in CONFIG_PROFILE variable.
final ConfigFileReader.ConfigFile configFile = ConfigFileReader.parse(CONFIG_LOCATION, CONFIG_PROFILE);
final AuthenticationDetailsProvider provider = new ConfigFileAuthenticationDetailsProvider(configFile);
cpClient = new DataLabelingManagementClient(provider);
cpClient.setEndpoint(ENDPOINT);
}
return cpClient;
}
public static DataLabelingClient getDataLabelingDPClient() throws IOException {
if (dpClient == null) {
// Configuring the AuthenticationDetailsProvider. It's assuming there is a default OCI config file
// "~/.oci/config", and a profile in that config with the name defined in CONFIG_PROFILE variable.
final ConfigFileReader.ConfigFile configFile = ConfigFileReader.parse(CONFIG_LOCATION, CONFIG_PROFILE);
final AuthenticationDetailsProvider provider = new ConfigFileAuthenticationDetailsProvider(configFile);
dpClient = new DataLabelingClient(provider);
dpClient.setEndpoint(ENDPOINT);
}
return dpClient;
}
}Mit der API ein Dataset mit dem Java-SDK erstellen
Sie können in Data Labeling mit dem Java-SDK ein Dataset erstellen.
Stellen Sie sicher, dass Sie den Control-Plane- und Data-Plane-Client erstellt haben.
/**
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
*/
package com.oracle.dls.samples;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.google.common.collect.ImmutableList;
import com.oracle.bmc.datalabelingservice.DataLabelingManagement;
import com.oracle.bmc.datalabelingservice.model.*;
import com.oracle.bmc.datalabelingservice.requests.CreateDatasetRequest;
import com.oracle.bmc.datalabelingservice.requests.GetDatasetRequest;
import com.oracle.bmc.datalabelingservice.requests.GetWorkRequestRequest;
import com.oracle.bmc.datalabelingservice.responses.CreateDatasetResponse;
import com.oracle.bmc.datalabelingservice.responses.GetDatasetResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
/**
* This class provides an example of how to use OCI DLS Service to create and get dataset in an async way.
* <p>
* The Data Labeling service queried by this example will be assigned:
* <ul>
* <li>an endpoint url defined by constant ENDPOINT</li>
* <li>an object storage namespace defined by constant NAMESPACE_NAME</li>
* <li>
* The configuration file used by service clients will be sourced from the default
* location (~/.oci/config) and the CONFIG_PROFILE profile will be used.
* </li>
* </ul>
* </p>
*/
public class CreateDatasetSample {
private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
static {
objectMapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
}
private static ScheduledExecutorService executor;
static {
try {
executor = Executors.newSingleThreadScheduledExecutor();
} catch (Exception e) {
System.err.println("Unable to obtain scheduled executor service");
}
}
public static void main(String[] args) throws IOException {
if (args.length > 0) {
throw new IllegalArgumentException(
"This example expects no argument");
}
System.out.println("Start Running CreateDatasetSample Example ...");
DataLabelingManagement client = SampleApplication.getDataLabelingCpClient();
String dataSetId = createDataset(client);
System.out.println("Getting the dataset with id " + dataSetId);
getDataset(client, dataSetId);
}
public static String createDataset(DataLabelingManagement client) throws JsonProcessingException {
// Object storage source details to provide bucket information where
// datasets ( images/text files) are present for labeling.
// Make sure the principal being used has object storage bucket and object access.
ObjectStorageSourceDetails sourceDetails = ObjectStorageSourceDetails.builder()
.bucket(DLSConstants.BUCKET_NAME)
.namespace(DLSConstants.BUCKET_NAME_SPACE)
// Provide prefix in case image are under specific prefix.
//.prefix("fruit")
.build();
// Type of the format of dataset.
// For Image
ImageDatasetFormatDetails formatDetails = ImageDatasetFormatDetails.builder().build();
// For Text
// TextDatasetFormatDetails formatDetails = TextDatasetFormatDetails.builder().build();
// Build label sets which will be used for labeling.
Label label1 = Label.builder().name("label1").build();
Label label2 = Label.builder().name("label2").build();
List<Label> labelItems = ImmutableList.<Label>builder()
.add(label1).add(label2).build();
LabelSet labelSet = LabelSet.builder()
.items(labelItems)
.build();
// freeform tags.
Map<String, String> freeFormTags = new HashMap<>();
freeFormTags.put("foo1", "bar1");
freeFormTags.put("foo2", "bar2");
/* Use below code to build defined tags.
Map<String, Map<String, String>> definedTags = new HashMap<>();
Map<String, String> definedTagNs1 = new HashMap<>();
definedTagNs1.put("definedTagKey", "definedTagValue");
definedTags.put("namespace1", definedTagNs1);
*/
CreateDatasetDetails createDatasetDetails = CreateDatasetDetails.builder()
.compartmentId(DLSConstants.COMPARTMENT_ID)
.displayName("java-sdk-sample-dataset")
.description("Java sdk sample dataset description")
.annotationFormat("SINGLE_LABEL")
.datasetFormatDetails(formatDetails)
.datasetSourceDetails(sourceDetails)
.labelSet(labelSet)
.freeformTags(freeFormTags)
.build();
// Build Create dataset request
CreateDatasetRequest request = CreateDatasetRequest.builder()
.createDatasetDetails(createDatasetDetails)
.build();
System.out.println("Sending create dataset request " + objectMapper.writeValueAsString(request) + "\n");
CreateDatasetResponse response = client.createDataset(request);
WorkRequest workRequest = pollWorkRequestStatus(response.getOpcWorkRequestId(), client);
if (workRequest.getStatus() == OperationStatus.Succeeded) {
System.out.println("Created dataset with dataset Id : " + response.getDataset().getId());
}
return response.getDataset().getId();
}
public static void getDataset(DataLabelingManagement client, String datasetId) throws JsonProcessingException {
GetDatasetRequest getDatasetRequest = GetDatasetRequest.builder()
.datasetId(datasetId)
.build();
GetDatasetResponse getDatasetResponse = client.getDataset(getDatasetRequest);
String responseStr1 = objectMapper.writeValueAsString(getDatasetResponse.getDataset());
System.out.println("Get dataset response : " + responseStr1);
}
public static WorkRequest pollWorkRequestStatus(String workRequestId, DataLabelingManagement client) {
try {
return pollForCompletion(workRequestId, client)
.thenApply(workRequest -> getWorkRequest(client, workRequestId)).get();
} catch (InterruptedException | ExecutionException | CancellationException e) {
return null;
}
}
public static WorkRequest getWorkRequest(DataLabelingManagement client, String opcWorkRequestId) {
GetWorkRequestRequest getWorkRequestRequest = GetWorkRequestRequest.builder().workRequestId(opcWorkRequestId)
.build();
return client.getWorkRequest(getWorkRequestRequest).getWorkRequest();
}
public static CompletableFuture<String> pollForCompletion(String workRequestId, DataLabelingManagement client) {
CompletableFuture<String> completionFuture = new CompletableFuture<>();
final ScheduledFuture<?> checkFuture = executor.scheduleAtFixedRate(() -> {
OperationStatus operationStatus = getWorkRequest(client, workRequestId).getStatus();
System.out.println("OperationStatus of workRequestId + " + workRequestId + " is " + operationStatus);
if (isTerminalOperationStatus(operationStatus)) {
completionFuture.complete(workRequestId);
}
}, 0, 10, TimeUnit.SECONDS);
completionFuture.whenComplete((result, thrown) -> {
checkFuture.cancel(true);
});
return completionFuture;
}
private static Boolean isTerminalOperationStatus(OperationStatus operationStatus) {
if (!(operationStatus.equals(OperationStatus.InProgress) ||
operationStatus.equals(OperationStatus.Accepted) ||
operationStatus.equals(OperationStatus.Waiting) ||
operationStatus.equals(OperationStatus.Canceling))) {
return true;
} else
return false;
}
}Mit der API Datensätze mit dem Java-SDK erstellen
Sie können in Data Labeling mit dem Java-SDK Datensätze erstellen.
Stellen Sie sicher, dass Sie den Control-Plane- und Data-Plane-Client für Data Labeling sowie ein Dataset erstellt haben.
package com.oracle.dls.samples;
/**
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
*/
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.oracle.bmc.datalabelingservicedataplane.DataLabelingClient;
import com.oracle.bmc.datalabelingservicedataplane.model.CreateRecordDetails;
import com.oracle.bmc.datalabelingservicedataplane.model.ObjectStorageSourceDetails;
import com.oracle.bmc.datalabelingservicedataplane.model.CreateObjectStorageSourceDetails;
import com.oracle.bmc.datalabelingservicedataplane.requests.CreateRecordRequest;
import com.oracle.bmc.datalabelingservicedataplane.requests.GetRecordRequest;
import com.oracle.bmc.datalabelingservicedataplane.responses.CreateRecordResponse;
import com.oracle.bmc.datalabelingservicedataplane.responses.GetRecordResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* This class provides an example of how to use OCI DLS Service to create and get Record in an sync way.
* <p>
* The Data Labeling service queried by this example will be assigned:
* <ul>
* <li>an endpoint url defined by constant ENDPOINT</li>
* <li>an object storage namespace defined by constant NAMESPACE_NAME</li>
* <li>
* The configuration file used by service clients will be sourced from the default
* location (~/.oci/config) and the CONFIG_PROFILE profile will be used.
* </li>
* </ul>
* </p>
*/
public class CreateRecordSample {
private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
static {
objectMapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
}
public static void main(String[] args) throws IOException {
DataLabelingClient dataLabelingDPClient = SampleApplication.getDataLabelingDPClient();
createRecord(dataLabelingDPClient, SampleAppConstants.COMPARTMENT_ID, SampleAppConstants.DATASET_ID);
/* We can get record by below code */
getRecord(dataLabelingDPClient, SampleAppConstants.RECORD_ID);
}
public static void createRecord(DataLabelingClient dpClient, String compartmentId, String datasetId) throws JsonProcessingException {
/*
* Object storage source details to provide relative path of the Object for
* Labeling.
*
* For example: If the object "sampleObject.jpg" reside in bucket "test" and
* inside folder "sample", then relativePath parameter should be
* "sampleObject.jpg". The bucket and namespace details are picked from Dataset
* details provided during dataset creation. Note: While creating dataset the
* bucket name is specified as "test" and prefix is specified as "sample"
*
* Make sure the principal being used has object storage bucket and object
* access.
*/
CreateObjectStorageSourceDetails sourceDetails = CreateObjectStorageSourceDetails.builder()
.relativePath("objectname")
// freeform tags.
Map<String, String> freeFormTags = new HashMap<>();
freeFormTags.put("foo1", "bar1");
freeFormTags.put("foo2", "bar2");
/* Use below code to build defined tags.
Map<String, Map<String, String>> definedTags = new HashMap<>();
Map<String, String> definedTagNs1 = new HashMap<>();
definedTagNs1.put("definedTagKey", "definedTagValue");
definedTags.put("namespace1", definedTagNs1);
*/
CreateRecordDetails createRecordDetails = CreateRecordDetails.builder()
.compartmentId(compartmentId)
.name("traffic2.jpg")
.datasetId(datasetId)
.sourceDetails(sourceDetails)
.freeformTags(freeFormTags)
//.definedTags(definedTags)
.build();
// Build Create record request
CreateRecordRequest request = CreateRecordRequest.builder()
.createRecordDetails(createRecordDetails)
.build();
ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
System.out.println("Sending create record request " + objectMapper.writeValueAsString(createRecordDetails) + "\n");
CreateRecordResponse response = dpClient.createRecord(request);
System.out.println("Create dataset request sent. Response : " +
objectMapper.writeValueAsString(response.getRecord()));
}
public static void getRecord(DataLabelingClient dpClient, String recordId) throws JsonProcessingException {
GetRecordRequest getRecordRequest = GetRecordRequest.builder()
.recordId(recordId)
.build();
GetRecordResponse getRecordResponse = dpClient.getRecord(getRecordRequest);
String responseStr1 = objectMapper.writeValueAsString(getRecordResponse.getRecord());
System.out.println("Get record response : " + responseStr1);
}
}Mit der API eine Annotation mit dem Java-SDK erstellen
Sie können in Data Labeling mit dem Java-SDK eine Annotation erstellen.
Stellen Sie sicher, dass Sie den Control-Plane- und Data-Plane-Client für Data Labeling, ein Dataset sowie einen Datensatz zum Annotieren erstellt haben.
/**
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
*/
package com.oracle.dls.samples;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.google.common.collect.ImmutableList;
import com.oracle.bmc.datalabelingservicedataplane.DataLabelingClient;
import com.oracle.bmc.datalabelingservicedataplane.model.*;
import com.oracle.bmc.datalabelingservicedataplane.requests.CreateAnnotationRequest;
import com.oracle.bmc.datalabelingservicedataplane.requests.GetAnnotationRequest;
import com.oracle.bmc.datalabelingservicedataplane.responses.CreateAnnotationResponse;
import com.oracle.bmc.datalabelingservicedataplane.responses.GetAnnotationResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* This class provides an example of how to use OCI DLS Service to create and get Annotation in an sync way.
* <p>
* The Data Labeling service queried by this example will be assigned:
* <ul>
* <li>an endpoint url defined by constant ENDPOINT</li>
* <li>an object storage namespace defined by constant NAMESPACE_NAME</li>
* <li>
* The configuration file used by service clients will be sourced from the default
* location (~/.oci/config) and the CONFIG_PROFILE profile will be used.
* </li>
* </ul>
* </p>
*/
public class CreateAnnotationSample {
private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
static {
objectMapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
}
public static void main(String[] args) throws IOException {
DataLabelingClient dataLabelingDPClient = SampleApplication.getDataLabelingDPClient();
createAnnotation(dataLabelingDPClient, SampleAppConstants.COMPARTMENT_ID, SampleAppConstants.RECORD_ID);
/* We can get annotation by below code */
getAnnotation(dataLabelingDPClient, SampleAppConstants.ANNOTATION_ID);
}
public static void createAnnotation(DataLabelingClient dpClient, String compartmentId, String recordId) throws JsonProcessingException {
List<Entity> entities = buildImageSelectionObjectEntities();
// freeform tags.
Map<String, String> freeFormTags = new HashMap<>();
freeFormTags.put("foo1", "bar1");
freeFormTags.put("foo2", "bar2");
CreateAnnotationDetails createAnnotationDetails = CreateAnnotationDetails.builder()
.compartmentId(compartmentId)
.recordId(recordId)
.entities(entities)
.freeformTags(freeFormTags)
.build();
// Build Create record request
CreateAnnotationRequest request = CreateAnnotationRequest.builder()
.createAnnotationDetails(createAnnotationDetails)
.build();
ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
System.out.println("Sending create annotation request " + objectMapper.writeValueAsString(createAnnotationDetails) + "\n");
CreateAnnotationResponse response = dpClient.createAnnotation(request);
System.out.println("Create annotation request sent. Response : " +
objectMapper.writeValueAsString(response.getAnnotation()));
}
/**
* Create Image object selection entity by providing vertices of the polygon.
*/
private static List<Entity> buildImageSelectionObjectEntities() {
List<NormalizedVertex> vertexList = ImmutableList.of(
NormalizedVertex.builder().x(0.030035F).y(0.13743F).build(),
NormalizedVertex.builder().x(0.030035F).y(0.396943F).build(),
NormalizedVertex.builder().x(0.282685F).y(0.396943F).build(),
NormalizedVertex.builder().x(0.2826855F).y(0.137438F).build()
);
BoundingPolygon boundingPolygon = BoundingPolygon.builder().normalizedVertices(vertexList).build();
List<Label> annotationLabels = ImmutableList.of(
Label.builder().label("L1").build()
);
return ImmutableList.of(ImageObjectSelectionEntity.builder()
.boundingPolygon(boundingPolygon)
.labels(annotationLabels)
.build());
}
public static void getAnnotation(DataLabelingClient dpClient, String annotationId) throws JsonProcessingException {
GetAnnotationRequest getAnnotationRequest = GetAnnotationRequest.builder()
.annotationId(annotationId)
.build();
GetAnnotationResponse getAnnotationResponse = dpClient.getAnnotation(getAnnotationRequest);
String responseStr1 = objectMapper.writeValueAsString(getAnnotationResponse.getAnnotation());
System.out.println("Get annotation response : " + responseStr1);
}
}Mit der API den Control-Plane- und Data-Plane-Client mit dem Python-SDK erstellen
Befolgen Sie dieses Beispiel zum Erstellen des Control-Plane- und Data-Plane-Clients für Data Labeling mit dem Python-SDK.
from oci.data_labeling_service_dataplane.data_labeling_client import DataLabelingClient
from oci.data_labeling_service.data_labeling_management_client import DataLabelingManagementClient
def init_dls_dp_client(config, service_endpoint):
dls_client = DataLabelingClient(config,
service_endpoint=service_endpoint)
return dls_client
def init_dls_cp_client(config, service_endpoint):
dls_client = DataLabelingManagementClient(config,
service_endpoint=service_endpoint)
return dls_clientMit der API ein Dataset mit dem Python-SDK erstellen
Sie können in Data Labeling mit dem Python-SDK ein Dataset erstellen.
Stellen Sie sicher, dass Sie den Control-Plane- und Data-Plane-Client erstellt haben.
from clients import init_dls_cp_client
from oci.data_labeling_service.models import ObjectStorageSourceDetails
from oci.data_labeling_service.models import DatasetFormatDetails
from oci.data_labeling_service.models import LabelSet
from oci.data_labeling_service.models import Label
from oci.data_labeling_service.models import CreateDatasetDetails
# --- Set up
# TODO: Change the below variables
config_file = "<config file>" # '~/.oci/config'
compartment_id = "<compartment ocid>" # 'ocid1.compartment.oc1..xxxxxxxxxxxxxxxxx'
namespace = "<object storage bucket namespace>" # 'idgszs0xipnv'
bucket = "<object storage bucket name>" # 'testing_bucket'
format_type = "IMAGE"
annotation_format = "BOUNDING_BOX"
label1 = "apple"
label2 = "orange"
service_endpoint_cp = "https://dlsprod-cp.us-phoenix-1.oci.oraclecloud.com"
dls_client = init_dls_cp_client(config_file, service_endpoint_cp)
dataset_source_details_obj = ObjectStorageSourceDetails(namespace=namespace, bucket=bucket)
dataset_format_details_obj = DatasetFormatDetails(format_type=format_type)
label_set_obj = LabelSet(items=[Label(name=label1), Label(name=label2)])
create_dataset_obj = CreateDatasetDetails(compartment_id=compartment_id, annotation_format=annotation_format,
dataset_source_details=dataset_source_details_obj,
dataset_format_details=dataset_format_details_obj,
label_set=label_set_obj)
try:
response = dls_client.create_dataset(create_dataset_details=create_dataset_obj)
except Exception as error:
response = errorMit der API Datensätze mit dem Python-SDK erstellen
Sie können in Data Labeling mit dem Python-SDK Datensätze erstellen.
Stellen Sie sicher, dass Sie den Control-Plane- und Data-Plane-Client für Data Labeling sowie ein Dataset erstellt haben.
from oci.data_labeling_service_dataplane.models import CreateObjectStorageSourceDetails
from oci.data_labeling_service_dataplane.models import CreateRecordDetails
from clients import init_dls_dp_client
# --- Set up
# TODO: Change the below variables
config_file = "<config file>" # '~/.oci/config'
compartment_id = "<compartment ocid>" # 'ocid1.compartment.oc1..xxxxxxxxxxxxxxxxx'
# dataset_id can be found in create_dataset response under response.data.id
dataset_id = "<dataset ocid>" # "ocid1.datalabelingdatasetint.oc1.phx.xxxxxx"
# Details of image being sourced from bucket
relative_path = "<relative path of the image w.r.t. bucket>" # training/banana.jpeg(in case images are placed under folder named training) or
# banana.jpeg(if image is directly uploaded in the bucket)
name = "<image name in bucket>" # "pineapple.jpeg"
service_endpoint_dp = "https://dlsprod-dp.us-phoenix-1.oci.oraclecloud.com"
dls_client = init_dls_dp_client(config_file, service_endpoint_dp)
source_details_obj = CreateObjectStorageSourceDetails(relative_path=relative_path)
create_record_obj = CreateRecordDetails(name=name,
dataset_id=dataset_id,
compartment_id=compartment_id,
source_details=source_details_obj)
try:
response = dls_client.create_record(create_record_details=create_record_obj)
except Exception as error:
response = errorMit der API eine Annotation mit dem Python-SDK erstellen
Sie können in Data Labeling mit dem Python-SDK eine Annotation erstellen.
Stellen Sie sicher, dass Sie den Control-Plane- und Data-Plane-Client für Data Labeling, ein Dataset sowie einen Datensatz zum Annotieren erstellt haben.
from oci.data_labeling_service_dataplane.models import Label
from oci.data_labeling_service_dataplane.models import ImageObjectSelectionEntity
from oci.data_labeling_service_dataplane.models import NormalizedVertex
from oci.data_labeling_service_dataplane.models import BoundingPolygon
from oci.data_labeling_service_dataplane.models import CreateAnnotationDetails
from clients import init_dls_dp_client
# --- Set up
# TODO: Change the below variables
config_file = "<config file>" # '~/.oci/config'
compartment_id = "<compartment ocid>" # 'ocid1.compartment.oc1..xxxxxxxxxxxxxxxxx'
# dataset_id can be found in create_record response under response.data.id
record_id = "<record ocid>" # "ocid1.datalabelingdatasetint.oc1.phx.xxxxxx"
label = "<label of annotation>" # "apple"
entity_type = "IMAGEOBJECTSELECTION"
# Co-ordinates of bounding box
x_coordinates = [0.030035335689045935, 0.030035335689045935, 0.2826855123674912, 0.2826855123674912]
y_coordinates = [0.13743816254416963, 0.3969434628975265, 0.3969434628975265, 0.13743816254416963]
labels_obj = [Label(label=label)]
normalized_vector_obj_lst = []
for i in range(len(x_coordinates)):
normalized_vector_obj = NormalizedVertex(x=x_coordinates[i], y=y_coordinates[i])
normalized_vector_obj_lst.append(normalized_vector_obj)
bounding_polygon_obj = BoundingPolygon(normalized_vertices=normalized_vector_obj_lst)
entity_obj = [ImageObjectSelectionEntity(entity_type=entity_type, labels=labels_obj,
bounding_polygon=bounding_polygon_obj)]
create_annotation_details_obj = CreateAnnotationDetails(record_id=record_id, compartment_id=compartment_id,
entities=entity_obj)
service_endpoint_dp = "https://dlstest-dp.us-phoenix-1.oci.oraclecloud.com"
dls_client = init_dls_dp_client(config_file, service_endpoint_dp)
try:
response = dls_client.create_annotation(create_annotation_details=create_annotation_details_obj)
except Exception as error:
response = error