Create Filter - annotation_results

Hi,

I want to create a filter using the sdk to filter out images where the ‘annotation_results’ column is a an empty dictionary. I tried to do so with the following code but it does not seem to work:

filters = Filters.create(Filters.OR, [
   Filters.item(
   Column.annotations_results,
   operator.NOT_EQUAL,
   Type.String,
   Filters.value([  ])
)
])

Does anyone have any experience with this?

To filter out images where the annotation_results column is an empty dictionary using the SDK, you need to ensure that the filter is correctly set up to handle the specific structure of the annotation_results field.

The NOT_EQUAL operator might not work as expected with an empty list or dictionary. Instead, you can use the EMPTY operator to check if the annotation_results field is empty.

from label_studio_sdk.data_manager import Filters, Column, Operator, Type

filters = Filters.create(Filters.OR, [
    Filters.item(
        Column.annotations_results,
        Operator.EMPTY,
        Type.String,
        Filters.value(True)
    )
])

This filter will match tasks where the annotation_results field is empty. If you want to exclude these tasks, you can use the NOT_EMPTY operator instead:

filters = Filters.create(Filters.OR, [
    Filters.item(
        Column.annotations_results,
        Operator.NOT_EMPTY,
        Type.String,
        Filters.value(True)
    )
])

Let me know if this helps!

Hi,

This doesn’t work because it I can’t use NOT_EMPTY or EMPTY as an operator.

Replace this line in your code:

to this:

Filters.value("[]")