Skip to content

Commit f50aa74

Browse files
committed
refactor
1 parent 0f03afc commit f50aa74

File tree

6 files changed

+37
-22
lines changed

6 files changed

+37
-22
lines changed

labelbox/schema/batch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Batch(DbObject):
3232
created_at = Field.DateTime("created_at")
3333
updated_at = Field.DateTime("updated_at")
3434
size = Field.Int("size")
35+
consensus_settings = Field.Json("consensus_settings_json")
3536

3637
# Relationships
3738
created_by = Relationship.ToOne("User")
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
from pydantic import BaseModel
1+
from labelbox.utils import _CamelCaseMixin
22

33

4-
class ConsensusSettings(BaseModel):
4+
class ConsensusSettings(_CamelCaseMixin):
55
"""Container for holding consensus quality settings
66
77
>>> ConsensusSettings(
8-
>>> numberOfLabels = 2,
9-
>>> coveragePercentage = 0.2
8+
>>> number_of_labels = 2,
9+
>>> coverage_percentage = 0.2
1010
>>> )
1111
1212
Args:
13-
numberOfLabels: Number of labels for consensus
14-
coveragePercentage: Percentage of data rows to be labeled more than once
13+
number_of_labels: Number of labels for consensus
14+
coverage_percentage: Percentage of data rows to be labeled more than once
1515
"""
1616

17-
numberOfLabels: int
18-
coveragePercentage: float
17+
number_of_labels: int
18+
coverage_percentage: float

labelbox/schema/data_row_metadata.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pydantic import BaseModel, conlist, constr
99

1010
from labelbox.schema.ontology import SchemaId
11-
from labelbox.utils import camel_case
11+
from labelbox.utils import _CamelCaseMixin
1212

1313

1414
class DataRowMetadataKind(Enum):
@@ -36,13 +36,6 @@ class DataRowMetadataSchema(BaseModel):
3636
String: Type[str] = constr(max_length=500)
3737

3838

39-
class _CamelCaseMixin(BaseModel):
40-
41-
class Config:
42-
allow_population_by_field_name = True
43-
alias_generator = camel_case
44-
45-
4639
# Metadata base class
4740
class DataRowMetadataField(_CamelCaseMixin):
4841
schema_id: SchemaId

labelbox/schema/project.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,14 @@ def create_batch(self,
566566
name: str,
567567
data_rows: List[str],
568568
priority: int = 5,
569-
consensus_settings: Optional[ConsensusSettings] = None):
569+
consensus_settings: Optional[Dict[str, float]] = None):
570570
"""Create a new batch for a project. Batches is in Beta and subject to change
571571
572572
Args:
573573
name: a name for the batch, must be unique within a project
574574
data_rows: Either a list of `DataRows` or Data Row ids
575575
priority: An optional priority for the Data Rows in the Batch. 1 highest -> 5 lowest
576-
576+
consensus_settings: An optional dictionary with consensus settings: {'number_of_labels': 3, 'coverage_percentage': 0.1}
577577
"""
578578

579579
# @TODO: make this automatic?
@@ -605,15 +605,16 @@ def create_batch(self,
605605
}
606606
""" % (method, method, query.results_query_part(Entity.Batch))
607607

608-
consensus_settings_dict = consensus_settings.dict(
609-
) if consensus_settings else None
608+
if consensus_settings:
609+
consensus_settings = ConsensusSettings(**consensus_settings).dict(
610+
by_alias=True)
610611
params = {
611612
"projectId": self.uid,
612613
"batchInput": {
613614
"name": name,
614615
"dataRowIds": dr_ids,
615616
"priority": priority,
616-
"consensusSettings": consensus_settings_dict
617+
"consensusSettings": consensus_settings
617618
}
618619
}
619620

labelbox/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from pydantic import BaseModel
23

34

45
def _convert(s, sep, title):
@@ -23,3 +24,10 @@ def title_case(s):
2324
def snake_case(s):
2425
""" Converts a string in [snake|camel|title]case to snake_case. """
2526
return _convert(s, "_", lambda i: False)
27+
28+
29+
class _CamelCaseMixin(BaseModel):
30+
31+
class Config:
32+
allow_population_by_field_name = True
33+
alias_generator = camel_case

tests/integration/test_batch.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33
from labelbox import Dataset, Project
4-
from labelbox.schema.queue_mode import QueueMode
54

65
IMAGE_URL = "https://storage.googleapis.com/diagnostics-demo-data/coco/COCO_train2014_000000000034.jpg"
76

@@ -39,6 +38,19 @@ def test_create_batch(batch_project: Project, big_dataset: Dataset):
3938
assert batch.size == len(data_rows)
4039

4140

41+
def test_create_batch_with_consensus_settings(batch_project: Project,
42+
big_dataset: Dataset):
43+
data_rows = [dr.uid for dr in list(big_dataset.export_data_rows())]
44+
consensus_settings = {"coverage_percentage": 0.1, "number_of_labels": 3}
45+
batch = batch_project.create_batch("batch with consensus settings",
46+
data_rows,
47+
3,
48+
consensus_settings=consensus_settings)
49+
assert batch.name == "batch with consensus settings"
50+
assert batch.size == len(data_rows)
51+
assert batch.consensus_settings == consensus_settings
52+
53+
4254
def test_archive_batch(batch_project: Project, small_dataset: Dataset):
4355
data_rows = [dr.uid for dr in list(small_dataset.export_data_rows())]
4456
batch = batch_project.create_batch("batch to archive", data_rows)

0 commit comments

Comments
 (0)