Skip to main content

Delete Annotations

info

Before using the Python SDK, Node.js SDK, or any of our gRPC clients, ensure they are properly installed on your machine. Refer to their respective installation guides for instructions on how to install and initialize them.

Delete Annotation by Input ID and Annotation ID

Below is an example of how to delete a single annotation by input ID and annotation ID.

#####################################################################
# In this section, we set the user authentication, app ID, input ID,
# and annotation ID. Change these strings to run your own example.
#####################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotation you want to delete
INPUT_ID = '53d0362a9dfa4e03b2293375e2d0db73'
ANNOTATION_ID = '300b8e39a65e4f33ae4e15e86eaf4a3b'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

delete_annotation_response = stub.DeleteAnnotation(
service_pb2.DeleteAnnotationRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
input_id=INPUT_ID,
annotation_id=ANNOTATION_ID
),
metadata=metadata
)

if delete_annotation_response.status.code != status_code_pb2.SUCCESS:
print(delete_annotation_response.status)
raise Exception("Delete annotations failed, status: " + delete_annotation_response.status.description)

Bulk Delete Annotations by Input IDs and Annotation IDs

You can delete multiple annotations in one API call. You need to provide a list of input IDs and a list of annotation IDs. The number of input IDs has to match the number of annotation IDs.

Below is an example of how to do that.

#######################################################################
# In this section, we set the user authentication, app ID, input IDs,
# and annotation IDs. Change these strings to run your own example.
#######################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotations you want to bulk delete
INPUT_ID_1 = 'b76fe0adb0294906942f169bb1f6cacf'
INPUT_ID_2 = 'e838fac8da9d40c89f2291a6496593da'
ANNOTATION_ID_1 = '35c37cda9ad8460fae12b2b2b6a23f1d'
ANNOTATION_ID_2 = '63d69000ae3343d0b70b892ea3dcb01d'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

delete_annotations_response = stub.DeleteAnnotations(
service_pb2.DeleteAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
input_ids=[INPUT_ID_1, INPUT_ID_2],
ids=[ANNOTATION_ID_1, ANNOTATION_ID_2]
),
metadata=metadata
)

if delete_annotations_response.status.code != status_code_pb2.SUCCESS:
print(delete_annotations_response.status)
raise Exception("Delete annotations failed, status: " + delete_annotations_response.status.description)

Bulk Delete All Annotations by Input IDs

To delete all annotations of a given input, you just need to set their input ID(s). This will delete all annotations for these input(s), EXCEPT the input level annotations, which only get deleted if you delete the inputs themselves.

Below is an example of how to do that.

##########################################################################
# In this section, we set the user authentication, app ID, and input IDs.
# Change these strings to run your own example.
##########################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the annotations you want to bulk delete
INPUT_ID_1 = '53d0362a9dfa4e03b2293375e2d0db73'
INPUT_ID_2 = '00f6d742124147ac8ca7788f73736fb9'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

delete_annotations_response = stub.DeleteAnnotations(
service_pb2.DeleteAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
input_ids=[INPUT_ID_1, INPUT_ID_2]
),
metadata=metadata
)

if delete_annotations_response.status.code != status_code_pb2.SUCCESS:
print(delete_annotations_response.status)
raise Exception("Delete annotations failed, status: " + delete_annotations_response.status.description)