-
Notifications
You must be signed in to change notification settings - Fork 68
Huge optimization to annotation import library #1727
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
Merged
+33
−108
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
libs/labelbox/tests/data/annotation_import/test_annotation_import_limit.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import itertools | ||
import uuid | ||
from labelbox.schema.annotation_import import AnnotationImport, MALPredictionImport | ||
from labelbox.schema.media_type import MediaType | ||
import pytest | ||
from unittest.mock import patch | ||
|
||
|
||
@patch('labelbox.schema.annotation_import.ANNOTATION_PER_LABEL_LIMIT', 1) | ||
def test_above_annotation_limit_on_single_import_on_single_data_row(annotations_by_media_type): | ||
|
||
annotations_ndjson = list(itertools.chain.from_iterable(annotations_by_media_type[MediaType.Image])) | ||
data_row_id = annotations_ndjson[0]["dataRow"]["id"] | ||
|
||
data_row_annotations = [annotation for annotation in annotations_ndjson if annotation["dataRow"]["id"] == data_row_id and "bbox" in annotation] | ||
|
||
with pytest.raises(ValueError): | ||
AnnotationImport._validate_data_rows([data_row_annotations[0]]*2) | ||
|
||
|
||
@patch('labelbox.schema.annotation_import.ANNOTATION_PER_LABEL_LIMIT', 1) | ||
def test_above_annotation_limit_divided_among_different_rows(annotations_by_media_type): | ||
|
||
annotations_ndjson = list(itertools.chain.from_iterable(annotations_by_media_type[MediaType.Image])) | ||
data_row_id = annotations_ndjson[0]["dataRow"]["id"] | ||
|
||
first_data_row_annotation = [annotation for annotation in annotations_ndjson if annotation["dataRow"]["id"] == data_row_id and "bbox" in annotation][0] | ||
|
||
second_data_row_annotation = first_data_row_annotation.copy() | ||
second_data_row_annotation["dataRow"]["id"] == "data_row_id_2" | ||
|
||
with pytest.raises(ValueError): | ||
AnnotationImport._validate_data_rows([first_data_row_annotation, second_data_row_annotation]*2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,110 +219,3 @@ def test_delete(module_project, predictions): | |
bulk_import_request.delete() | ||
all_import_requests = module_project.bulk_import_requests() | ||
assert len(list(all_import_requests)) == 0 | ||
|
||
|
||
def _create_label(row_index, data_row_uids, label_name_ids=['bbox']): | ||
label_name = label_name_ids[row_index % len(label_name_ids)] | ||
data_row_uid = data_row_uids[row_index % len(data_row_uids)] | ||
return Label(data=GenericDataRowData(uid=data_row_uid), | ||
annotations=[ | ||
VideoObjectAnnotation(name=label_name, | ||
keyframe=True, | ||
frame=4, | ||
segment_index=0, | ||
value=Rectangle( | ||
start=Point(x=100, y=100), | ||
end=Point(x=105, y=105), | ||
)) | ||
]) | ||
|
||
|
||
@pytest.mark.parametrize("configured_project", [MediaType.Video], indirect = True) | ||
@patch('labelbox.schema.annotation_import.ANNOTATION_PER_LABEL_LIMIT', 20) | ||
def test_below_annotation_limit_on_single_data_row( | ||
client, configured_project, video_data, rand_gen): | ||
_, data_row_uids = video_data | ||
configured_project.create_batch( | ||
rand_gen(str), | ||
data_row_uids, # sample of data row objects | ||
5 # priority between 1(Highest) - 5(lowest) | ||
) | ||
labels = [_create_label(index, data_row_uids) for index in range(19)] | ||
import_annotations = MALPredictionImport.create_from_objects( | ||
client=client, | ||
project_id=configured_project.uid, | ||
name=f"import {str(uuid.uuid4())}", | ||
predictions=labels) | ||
import_annotations.wait_until_done() | ||
|
||
assert import_annotations.errors == [] | ||
|
||
|
||
@pytest.mark.parametrize("configured_project", [MediaType.Video], indirect = True) | ||
@patch('labelbox.schema.annotation_import.ANNOTATION_PER_LABEL_LIMIT', 20) | ||
def test_above_annotation_limit_on_single_label_on_single_data_row( | ||
client, configured_project, video_data, rand_gen): | ||
_, data_row_uids = video_data | ||
|
||
configured_project.create_batch( | ||
rand_gen(str), | ||
data_row_uids, # sample of data row objects | ||
5 # priority between 1(Highest) - 5(lowest) | ||
) | ||
labels = [_create_label(index, data_row_uids) for index in range(21)] | ||
with pytest.raises(ValueError): | ||
import_annotations = MALPredictionImport.create_from_objects( | ||
client=client, | ||
project_id=configured_project.uid, | ||
name=f"import {str(uuid.uuid4())}", | ||
predictions=labels) | ||
import_annotations.wait_until_done() | ||
|
||
@pytest.mark.parametrize("configured_project", [MediaType.Video], indirect = True) | ||
@patch('labelbox.schema.annotation_import.ANNOTATION_PER_LABEL_LIMIT', 20) | ||
def test_above_annotation_limit_divided_among_different_rows( | ||
client, configured_project, video_data_100_rows, | ||
rand_gen): | ||
_, data_row_uids = video_data_100_rows | ||
|
||
configured_project.create_batch( | ||
rand_gen(str), | ||
data_row_uids, # sample of data row objects | ||
5 # priority between 1(Highest) - 5(lowest) | ||
) | ||
labels = [_create_label(index, data_row_uids) for index in range(21)] | ||
|
||
import_annotations = MALPredictionImport.create_from_objects( | ||
client=client, | ||
project_id=configured_project.uid, | ||
name=f"import {str(uuid.uuid4())}", | ||
predictions=labels) | ||
|
||
assert import_annotations.errors == [] | ||
|
||
|
||
@pytest.mark.parametrize("configured_project", [MediaType.Video], indirect = True) | ||
@patch('labelbox.schema.annotation_import.ANNOTATION_PER_LABEL_LIMIT', 20) | ||
def test_above_annotation_limit_divided_among_labels_on_one_row( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to do almost the same thing above, so it was removed. I can add this back in as a unit test instead if wanted |
||
client, configured_project, video_data, rand_gen): | ||
_, data_row_uids = video_data | ||
|
||
configured_project.create_batch( | ||
rand_gen(str), | ||
data_row_uids, # sample of data row objects | ||
5 # priority between 1(Highest) - 5(lowest) | ||
) | ||
labels = [ | ||
_create_label(index, | ||
data_row_uids, | ||
label_name_ids=['bbox', 'bbox_tool_with_nested_text']) | ||
for index in range(21) | ||
] | ||
|
||
import_annotations = MALPredictionImport.create_from_objects( | ||
client=client, | ||
project_id=configured_project.uid, | ||
name=f"import {str(uuid.uuid4())}", | ||
predictions=labels) | ||
|
||
assert import_annotations.errors == [] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this we are constantly testing for this case everytime we do a label import