Skip to content

Commit

Permalink
feat: add yolo model for nutriscore object detection (#1356)
Browse files Browse the repository at this point in the history
* chore: change OpenCV dependency

We're not using imshow function, so we can use the headless version of
OpenCV, which is lighter.
See https://pypi.org/project/opencv-python/ for more information.

* feat: implement YOLO models

* fix: fix UPC detection after OpenCV upgrade

* fix: disable UPC detection
  • Loading branch information
raphael0202 authored Jul 5, 2024
1 parent 2d00822 commit be19217
Show file tree
Hide file tree
Showing 14 changed files with 1,352 additions and 1,138 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ dl-object-detection-models:
mkdir -p $${dir}/1; \
wget -cO - https://github.com/openfoodfacts/robotoff-models/releases/download/$${asset_name}-1.0/model.onnx > $${dir}/1/model.onnx; \
done; \
mkdir -p nutriscore-yolo/1; \
wget -cO - https://huggingface.co/openfoodfacts/nutriscore-yolo/resolve/main/weights/best.onnx > nutriscore-yolo/1/model.onnx

dl-category-classifier-model:
@echo "⏬ Downloading category classifier model files …"
Expand Down
5 changes: 5 additions & 0 deletions models/triton/nutriscore-yolo/labels.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nutriscore-a
nutriscore-b
nutriscore-c
nutriscore-d
nutriscore-e
2,098 changes: 1,047 additions & 1,051 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ influxdb-client = "~1.34.0"
jsonschema = "~4.4.0"
orjson = ">=3.8.2,<3.10.0"
Pillow = ">=9.3,<10.4"
numpy = "~1.23.5"
numpy = "~1.26.4"
protobuf = "~3.19.0"
Pint = "0.22"
APScheduler = "~3.10.1"
Expand All @@ -72,7 +72,7 @@ python-redis-lock = "~4.0.0"
transformers = ">=4.30.2,<4.39.0"
lark = "~1.1.4"
h5py = "~3.8.0"
opencv-contrib-python = "~4.7.0.72"
opencv-contrib-python-headless = "~4.10.0.84"
toml = "~0.10.2"
openfoodfacts = "0.1.11"
imagehash = "~4.3.1"
Expand Down
4 changes: 2 additions & 2 deletions robotoff/insights/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def run_object_detection_model(

timestamp = datetime.datetime.utcnow()
results = ObjectDetectionModelRegistry.get(model_name.value).detect_from_image(
image, output_image=False, triton_uri=triton_uri
image, output_image=False, triton_uri=triton_uri, threshold=threshold
)
data = results.to_json(threshold=threshold)
data = results.to_json()
max_confidence = max((item["score"] for item in data), default=None)
return ImagePrediction.create(
image=image_model,
Expand Down
Loading

0 comments on commit be19217

Please sign in to comment.