Skip to content

Commit

Permalink
feat: add DB columns
Browse files Browse the repository at this point in the history
- predictor for product_insight and prediction tables
- source_image and barcode for logo_annotation table
  • Loading branch information
raphael0202 committed Dec 29, 2022
1 parent 6a6b3cc commit ffc0de8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions robotoff/cli/logos.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def insert_batch(data_path: pathlib.Path, model_name: str, model_version: str) -
index=i,
score=item["score"],
bounding_box=item["bounding_box"],
barcode=image_instance.barcode,
source_image=image_instance.source_image,
)
seen_set.add(key)

Expand Down
5 changes: 5 additions & 0 deletions robotoff/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class ProductInsight(BaseModel):
# Hunger Games) on a subset of products. Each product have 0+ campaign
# tags
campaign = BinaryJSONField(null=True, index=True, default=list)
# Confidence score of the insight, may be null
confidence = peewee.FloatField(null=True, index=True)


class Prediction(BaseModel):
Expand All @@ -175,6 +177,7 @@ class Prediction(BaseModel):
help_text="server domain linked to the insight", index=True
)
predictor = peewee.CharField(max_length=100, null=True)
confidence = peewee.FloatField(null=True, index=False)


class AnnotationVote(BaseModel):
Expand Down Expand Up @@ -267,6 +270,8 @@ class LogoAnnotation(BaseModel):
username = peewee.TextField(null=True, index=True)
completed_at = peewee.DateTimeField(null=True, index=True)
nearest_neighbors = BinaryJSONField(null=True)
barcode = peewee.CharField(max_length=100, null=True, index=True)
source_image = peewee.TextField(null=True, index=True)

class Meta:
constraints = [peewee.SQL("UNIQUE(image_prediction_id, index)")]
Expand Down
1 change: 1 addition & 0 deletions robotoff/prediction/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Prediction:
source_image: Optional[str] = None
server_domain: Optional[str] = None
id: Optional[int] = None
confidence: Optional[float] = None

def to_dict(self) -> dict[str, Any]:
return dataclasses.asdict(self, dict_factory=dict_factory)
Expand Down
2 changes: 2 additions & 0 deletions robotoff/workers/tasks/import_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ def run_logo_object_detection(
index=i,
score=item["score"],
bounding_box=item["bounding_box"],
barcode=image_model.barcode,
source_image=image_model.source_image,
)
)
logger.info("%s logos found for image %s", len(logos), source_image)
Expand Down
2 changes: 2 additions & 0 deletions scripts/insert_image_predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def insert_batch(data_path: pathlib.Path, model_name: str, model_version: str) -
index=i,
score=item["score"],
bounding_box=item["bounding_box"],
barcode=image_instance.barcode,
source_image=image_instance.source_image,
)
seen_set.add(key)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/models_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Meta:
server_domain = factory.LazyFunction(lambda: settings.OFF_SERVER_DOMAIN)
automatic_processing = None
predictor = None
confidence = None


class AnnotationVoteFactory(UuidSequencer, PeeweeModelFactory):
Expand Down

0 comments on commit ffc0de8

Please sign in to comment.