Skip to content

Commit b91479f

Browse files
[QQC-2474] Expose quality mode through SDK create_project method (#1224)
1 parent d814fcb commit b91479f

File tree

7 files changed

+90
-26
lines changed

7 files changed

+90
-26
lines changed

labelbox/client.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from labelbox.schema.model_run import ModelRun
3232
from labelbox.schema.ontology import Ontology, Tool, Classification, FeatureSchema
3333
from labelbox.schema.organization import Organization
34+
from labelbox.schema.quality_mode import QualityMode, BENCHMARK_AUTO_AUDIT_NUMBER_OF_LABELS, \
35+
BENCHMARK_AUTO_AUDIT_PERCENTAGE, CONSENSUS_AUTO_AUDIT_NUMBER_OF_LABELS, CONSENSUS_AUTO_AUDIT_PERCENTAGE
3436
from labelbox.schema.user import User
3537
from labelbox.schema.project import Project
3638
from labelbox.schema.role import Role
@@ -636,16 +638,33 @@ def create_project(self, **kwargs) -> Project:
636638
description (str): A short summary for the project
637639
media_type (MediaType): The type of assets that this project will accept
638640
queue_mode (Optional[QueueMode]): The queue mode to use
639-
auto_audit_percentage (Optional[float]): The percentage of data rows that will require more than 1 label
640-
auto_audit_number_of_labels (Optional[float]): Number of labels required for data rows selected for multiple labeling (auto_audit_percentage)
641+
quality_mode (Optional[QualityMode]): The quality mode to use (e.g. Benchmark, Consensus). Defaults to
642+
Benchmark
641643
Returns:
642644
A new Project object.
643645
Raises:
644646
InvalidAttributeError: If the Project type does not contain
645647
any of the attribute names given in kwargs.
646648
"""
647-
media_type = kwargs.get("media_type")
649+
650+
auto_audit_percentage = kwargs.get("auto_audit_percentage")
651+
auto_audit_number_of_labels = kwargs.get("auto_audit_number_of_labels")
652+
if auto_audit_percentage is not None or auto_audit_number_of_labels is not None:
653+
raise ValueError(
654+
"quality_mode must be set instead of auto_audit_percentage or auto_audit_number_of_labels."
655+
)
656+
648657
queue_mode = kwargs.get("queue_mode")
658+
if queue_mode is QueueMode.Dataset:
659+
raise ValueError(
660+
"Dataset queue mode is deprecated. Please prefer Batch queue mode."
661+
)
662+
elif queue_mode is QueueMode.Batch:
663+
logger.warning(
664+
"Passing a queue mode of batch is redundant and will soon no longer be supported."
665+
)
666+
667+
media_type = kwargs.get("media_type")
649668
if media_type:
650669
if MediaType.is_supported(media_type):
651670
media_type = media_type.value
@@ -658,20 +677,25 @@ def create_project(self, **kwargs) -> Project:
658677
"Creating a project without specifying media_type"
659678
" through this method will soon no longer be supported.")
660679

661-
if not queue_mode:
662-
logger.warning(
663-
"Default createProject behavior will soon be adjusted to prefer "
664-
"batch projects. Pass in `queue_mode` parameter explicitly to opt-out for the "
665-
"time being.")
666-
elif queue_mode == QueueMode.Dataset:
667-
logger.warning(
668-
"QueueMode.Dataset will eventually be deprecated, and is no longer "
669-
"recommended for new projects. Prefer QueueMode.Batch instead.")
680+
quality_mode = kwargs.get("quality_mode")
681+
if not quality_mode:
682+
logger.info("Defaulting quality mode to Benchmark.")
683+
684+
data = kwargs
685+
data.pop("quality_mode", None)
686+
if quality_mode is None or quality_mode is QualityMode.Benchmark:
687+
data[
688+
"auto_audit_number_of_labels"] = BENCHMARK_AUTO_AUDIT_NUMBER_OF_LABELS
689+
data["auto_audit_percentage"] = BENCHMARK_AUTO_AUDIT_PERCENTAGE
690+
else:
691+
data[
692+
"auto_audit_number_of_labels"] = CONSENSUS_AUTO_AUDIT_NUMBER_OF_LABELS
693+
data["auto_audit_percentage"] = CONSENSUS_AUTO_AUDIT_PERCENTAGE
670694

671695
return self._create(Entity.Project, {
672-
**kwargs,
696+
**data,
673697
**({
674-
'media_type': media_type
698+
"media_type": media_type
675699
} if media_type else {})
676700
})
677701

labelbox/orm/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def relationship(source, relationship, where, order_by):
314314

315315

316316
def create(entity, data):
317-
""" Generats a query and parameters for creating a new DB object.
317+
""" Generates a query and parameters for creating a new DB object.
318318
319319
Args:
320320
entity (type): An Entity subtype indicating which kind of

labelbox/schema/project.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,10 @@ def update(self, **kwargs):
120120
for a project is inferred through the following attributes:
121121
122122
Benchmark:
123-
auto_audit_number_of_labels = 1
124-
auto_audit_percentage = 1.0
123+
auto_audit_number_of_labels = 1 and auto_audit_percentage = 1.0
125124
126125
Consensus:
127-
auto_audit_number_of_labels > 1
128-
auto_audit_percentage <= 1.0
126+
auto_audit_number_of_labels > 1 or auto_audit_percentage <= 1.0
129127
130128
Attempting to switch between benchmark and consensus modes is an invalid operation and will result
131129
in an error.

labelbox/schema/quality_mode.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from enum import Enum
2+
3+
4+
class QualityMode(str, Enum):
5+
Benchmark = "BENCHMARK"
6+
Consensus = "CONSENSUS"
7+
8+
9+
BENCHMARK_AUTO_AUDIT_NUMBER_OF_LABELS = 1
10+
BENCHMARK_AUTO_AUDIT_PERCENTAGE = 1
11+
CONSENSUS_AUTO_AUDIT_NUMBER_OF_LABELS = 3
12+
CONSENSUS_AUTO_AUDIT_PERCENTAGE = 0

tests/integration/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from labelbox.schema.enums import AnnotationImportState
2323
from labelbox.schema.invite import Invite
2424
from labelbox.schema.project import Project
25+
from labelbox.schema.quality_mode import QualityMode
2526
from labelbox.schema.queue_mode import QueueMode
2627
from labelbox.schema.user import User
2728

@@ -231,7 +232,7 @@ def project(client, rand_gen):
231232
@pytest.fixture
232233
def consensus_project(client, rand_gen):
233234
project = client.create_project(name=rand_gen(str),
234-
auto_audit_percentage=0,
235+
quality_mode=QualityMode.Consensus,
235236
queue_mode=QueueMode.Batch,
236237
media_type=MediaType.Image)
237238
yield project
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import pytest
22

3-
from labelbox.exceptions import InvalidQueryError, MalformedQueryException
4-
from labelbox.schema.media_type import MediaType
53
from labelbox.schema.queue_mode import QueueMode
64

75

86
def test_project_dataset(client, rand_gen):
97
with pytest.raises(
10-
MalformedQueryException,
8+
ValueError,
119
match=
12-
"DataSet queue mode is deprecated. Please prefer Batch queue mode."
10+
"Dataset queue mode is deprecated. Please prefer Batch queue mode."
1311
):
1412
client.create_project(
1513
name=rand_gen(str),
@@ -18,6 +16,21 @@ def test_project_dataset(client, rand_gen):
1816

1917

2018
def test_legacy_project_dataset_relationships(project, dataset):
21-
2219
assert [ds for ds in project.datasets()] == []
2320
assert [p for p in dataset.projects()] == []
21+
22+
23+
def test_project_auto_audit_parameters(client, rand_gen):
24+
with pytest.raises(
25+
ValueError,
26+
match=
27+
"quality_mode must be set instead of auto_audit_percentage or auto_audit_number_of_labels."
28+
):
29+
client.create_project(name=rand_gen(str), auto_audit_percentage=0.5)
30+
31+
with pytest.raises(
32+
ValueError,
33+
match=
34+
"quality_mode must be set instead of auto_audit_percentage or auto_audit_number_of_labels."
35+
):
36+
client.create_project(name=rand_gen(str), auto_audit_number_of_labels=2)

tests/integration/test_project.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from labelbox import Project, LabelingFrontend, Dataset
99
from labelbox.exceptions import InvalidQueryError
1010
from labelbox.schema.media_type import MediaType
11+
from labelbox.schema.quality_mode import QualityMode
1112
from labelbox.schema.queue_mode import QueueMode
1213

1314

1415
def test_project(client, rand_gen):
15-
1616
data = {
1717
"name": rand_gen(str),
1818
"description": rand_gen(str),
@@ -260,3 +260,19 @@ def test_media_type(client, project: Project, rand_gen):
260260
media_type=MediaType[media_type])
261261
assert project.media_type == MediaType[media_type]
262262
project.delete()
263+
264+
265+
def test_queue_mode(client, rand_gen):
266+
project = client.create_project(name=rand_gen(str)) # defaults to benchmark
267+
assert project.auto_audit_number_of_labels == 1
268+
assert project.auto_audit_percentage == 1
269+
270+
project = client.create_project(name=rand_gen(str),
271+
quality_mode=QualityMode.Benchmark)
272+
assert project.auto_audit_number_of_labels == 1
273+
assert project.auto_audit_percentage == 1
274+
275+
project = client.create_project(name=rand_gen(str),
276+
quality_mode=QualityMode.Consensus)
277+
assert project.auto_audit_number_of_labels == 3
278+
assert project.auto_audit_percentage == 0

0 commit comments

Comments
 (0)