Skip to content

Using external_id with Label container #1941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Issa-Bqain opened this issue Jan 13, 2025 · 2 comments
Open

Using external_id with Label container #1941

Issa-Bqain opened this issue Jan 13, 2025 · 2 comments

Comments

@Issa-Bqain
Copy link

Describe the bug

Hi, I am uploading annotations to a project using the SDK. When refencing the image to upload the annotations to this can be done using external_id, row data id or global key.

I am successful in doing this by using the row data id but this adds some complexity to my pipeline I can avoid by using the external_id.

There is a key which can be used for this as mentioned here but I run into a validation error when using this that is unclear to me.

Would appreciate some help in better understanding this, it may be that I am making a mistake somewhere.

Thank you

To reproduce


import labelbox as lb
import labelbox.data.annotation_types as lb_types
from labelbox import MALPredictionImport
import uuid

bbox_annotation_1 = lb_types.ObjectAnnotation(
    name="something",
    value=lb_types.Rectangle(
        start=lb_types.Point(x=1000, y=2000),
        end=lb_types.Point(x=1000, y=30)
    )
)

annotations = [
    bbox_annotation_1,
]

#use the labels container (we can use global or external key instead of data row id)
labels = [
    lb_types.Label(
        data={
          "external_id": "name.jpg"
        },
        annotations=annotations,
    )
]

# Upload labels for one image
upload_job = MALPredictionImport.create_from_objects(
  client = client,
  project_id = project_id,
  name = "mal_job"+str(uuid.uuid4()),
  predictions = labels)

upload_job.wait_till_done()

#error check
print(f"Errors: {upload_job.errors}", )
print(f"Status of uploads: {upload_job.statuses}")

Error

ValidationError: 1 validation error for DataRow
  Value error, Must set either id or global_key [type=value_error, input_value={'id': None, 'global_key': None}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/value_error
File <command-510266779839629>, line 2
      1 # Upload labels for one image
----> 2 upload_job = MALPredictionImport.create_from_objects(
      3   client = client,
      4   project_id = project_id,
      5   name = "mal_job"+str(uuid.uuid4()),
      6   predictions = labels)
      8 upload_job.wait_till_done()
     10 #error check
File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.11/site-packages/pydantic/main.py:214, in BaseModel.__init__(self, **data)
    212 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    213 __tracebackhide__ = True
--> 214 validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    215 if self is not validated_self:
    216     warnings.warn(
    217         'A custom validator is returning a value other than `self`.\n'
    218         "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
    219         'See the `model_validator` docs ([https://docs.pydantic.dev/latest/concepts/validators/#model-validators](https://adb-377525844578231.11.azuredatabricks.net/editor/notebooks/%3Ca%20class=)" target="_blank" rel="noopener noreferrer">[https://docs.pydantic.dev/latest/concepts/validators/#model-validators</a>](https://docs.pydantic.dev/latest/concepts/validators/#model-validators%3C/a%3E)) for more details.',
    220         stacklevel=2,
    221     )

Additional context

Add any other context about the problem here.

@vbrodsky
Copy link
Contributor

Please try with global_key instead of external_id. The value can remain the same. i.e. try

labels = [
    lb_types.Label(
        data={
          "global_key": "name.jpg"
        },
        annotations=annotations,
    )
]

@Issa-Bqain
Copy link
Author

Issa-Bqain commented Jan 14, 2025

Please try with global_key instead of external_id. The value can remain the same. i.e. try

labels = [
    lb_types.Label(
        data={
          "global_key": "name.jpg"
        },
        annotations=annotations,
    )
]

I tried this however it returns an error message stating that it could not find the image which otherwise works using the data row key.

Errors: [{'uuid': 'uuid here', 'dataRow': {'id': None, 'globalKey': 'name of file'}, 'status': 'FAILURE',

How could it identify an image using the external_id key value through the global_key key? based on my interpretation of the class this should not be possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants