Skip to content

Conversation

@farkob
Copy link
Contributor

@farkob farkob commented Jun 27, 2022

Adds name field to annotation objects where feature_id required. Makes both fields optional and require one field to be present.

annot,
(VideoClassificationAnnotation, VideoObjectAnnotation)):
video_annotations[annot.feature_schema_id].append(annot)
video_annotations[annot.name or annot.schema_id].append(annot)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it likely doesn't actually do anything to this line since we don't use video_annotations outside of the purpose of having the values(), but maybe we should make it so that it is annot.schema_id or annot.name instead of the reverse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good idea

@@ -1,3 +1,4 @@
from typing import Optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing the comment here, but it looks like the test cases are failing as a result of these changes. they will likely need some updates

@farkob farkob requested review from jtsodapop and msokoloff1 July 1, 2022 19:06
res = super().dict(*args, **kwargs)
if 'name' in res and res['name'] is None:
res.pop('name')
if 'featureSchemaId' in res and res.featureSchemaId is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we use res['name'] and res.featureSchemaId?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah forgot to change it

Copy link
Contributor

@jtsodapop jtsodapop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nit comments + i think some extra lines that don't need to be in there.

@@ -1,3 +1,4 @@
from tkinter import N
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion maybe this was added via your editor? if so, let's drop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


video_annotations = defaultdict(list)
for annot in label.annotations:
# print(dict(annot))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion think this may be extra line we can cut out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover

Copy link
Contributor

@kkim-labelbox kkim-labelbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM other than one super minor nit. Could you add tests as well?

@validator('name', pre=True, always=True)
def validate_name(cls, v, values):
if v is None and 'schema_id' not in values:
raise ValueError("Name is not set. Either set name or schema_id.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name and schema_id are not set. Either set name or schema_id

feature_schema_id: Cuid) -> "NDRadioSubclass":
return cls(answer=NDFeature(schema_id=radio.answer.feature_schema_id),
return cls(answer=NDFeature(name=radio.answer.name,
schema_id=radio.answer.feature_schema_id),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary newline? unless github messed up formatting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatter did this 🤷

@kkim-labelbox
Copy link
Contributor

It might also be good to add updates to docstrings that talk about schema_ids being required for MAL:

  • data/annotation_types/feature.py - FeatureSchema suggests using assign_feature_schema_ids to find schema_ids based on name. This is no longer necessary, so it'll be good to note that name can be provided to MAL
  • data/annotation_types/collection.py - LabelList.assign_feature_schema_ids says schema_ids required for MAL
  • data/annotation_types/label.py - Label.assign_feature_schema_ids says schema_ids required fr MAL

Copy link
Contributor

@kkim-labelbox kkim-labelbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a couple nit comments around wording, and have a request for more test cases.
Could you also add tests for the serialization/deserialization logic, since a bulk of your change touches the annotation type conversion logic?
I see we have a suite of tests under tests/data/serialization/ndsjon that are calling NDJsonConverter.serialize/deserialize across different data types. It'd be great to add tests cases here, for when only name is present. I just want to make sure we're covering test cases for the changes being made, and these additional test cases will ensure that the serialization/deserialization logic are working properly. Thanks!

@@ -1,5 +1,6 @@
from collections import defaultdict
from typing import Any, Callable, Dict, List, Union, Optional
import warnings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary import?

Returns:
LabelList. useful for chaining these modifying functions
Warning: assign_feature_schema_ids is now obsolete, you can
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: assign_feature_schema_ids is now obsolete, you can
                 now use names directly without having to lookup schema_ids.
  • Warning might be too "harsh". I'd just put "Note:"
  • I'd add you can now import annotations using names directly without having to lookup schema_ids

Label. useful for chaining these modifying functions
Warning: assign_feature_schema_ids is now obsolete, you can
now use names directly without having to lookup schema_ids.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same wording as above

if self.name:
if self.name not in valid_feature_schemas_by_name:
raise ValueError(
f"name {self.name} is not valid for the provided project's ontology."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure the error outputted to customers are all formatted and capitalized consistently.
Name {self.name} is not valid for the provided project's ontology

if self.schemaId:
if self.schemaId not in valid_feature_schemas_by_id:
raise ValueError(
f"schema id {self.schemaId} is not valid for the provided project's ontology."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize Schema

@@ -0,0 +1,20 @@
[
{
"answer": { "schemaId": "ckrb1sfl8099g0y91cxbd5ftb" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use name here instead of schemaId for answer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

},
{
"answer": "a value",
"name": "classification b",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two classifications named classification b

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating

farkob added 3 commits July 13, 2022 22:36
# Conflicts:
#	labelbox/data/serialization/ndjson/label.py
#	labelbox/data/serialization/ndjson/objects.py
Copy link
Contributor

@kkim-labelbox kkim-labelbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one more tiny comment, but LGTM otherwise!

Returns:
Label. useful for chaining these modifying functions
Warning: You can now import annotations using names directly without having to lookup schema_ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to Note: You can now import annotations using names directly without having to lookup schema_ids, and remove import warning?

@farkob farkob merged commit 5e1e228 into develop Jul 13, 2022
@farkob farkob deleted the farkob/schema_id_name branch July 13, 2022 22:36
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

Successfully merging this pull request may close these issues.

4 participants