-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
fix: Do not apply nutriscore prediction if it does not match the current nutriscore of the product #772
fix: Do not apply nutriscore prediction if it does not match the current nutriscore of the product #772
Changes from 3 commits
6680b9d
201911f
c570894
a37d23f
a0e2805
92e91ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from robotoff.utils import get_image_from_url | ||
|
||
image = get_image_from_url('https://world.openfoodfacts.org/images/products/330/274/003/0949/front_fr.110.400.jpg', error_raise=False) | ||
|
||
# expected_predictions_all = [Prediction(type=<PredictionType.nutrient: 'nutrient'>, data={'nutrients': {'salt': [{'raw': 'sel: 1,7 g', 'nutrient': 'salt', 'value': '1.7', 'unit': 'g'}]}, 'version': '2'}, value_tag=None, value=None, automatic_processing=None, predictor=None, barcode='3302740030949', timestamp=None, source_image='/802/509/314/0251/4.jpg', server_domain=None, id=None), Prediction(type=<PredictionType.nutrient_mention: 'nutrient_mention'>, data={'mentions': {'saturated_fat': [{'raw': 'acides gras saturés', 'span': [101, 120], 'languages': ['fr']}], 'fat': [{'raw': 'lipides', 'span': [87, 94], 'languages': ['fr']}], 'sugar': [{'raw': 'sucres', 'span': [151, 157], 'languages': ['fr']}], 'protein': [{'raw': 'proteines', 'span': [158, 167], 'languages': ['fr']}], 'salt': [{'raw': 'sel', 'span': [168, 171], 'languages': ['fr']}], 'nutrition_values': [{'raw': 'valeur nutritionnelle', 'span': [0, 21], 'languages': ['fr']}]}, 'version': '2'}, value_tag=None, value=None, automatic_processing=None, predictor=None, barcode='3302740030949', timestamp=None, source_image='/802/509/314/0251/4.jpg', server_domain=None, id=None), Prediction(type=<PredictionType.image_lang: 'image_lang'>, data={'count': {'fr': 25, 'null': 5, 'words': 35, 'en': 2, 'it': 3}, 'percent': {'fr': 71.42857142857143, 'null': 14.285714285714286, 'en': 5.714285714285714, 'it': 8.571428571428571}}, value_tag=None, value=None, automatic_processing=None, predictor=None, barcode='3302740030949', timestamp=None, source_image='/802/509/314/0251/4.jpg', server_domain=None, id=None), Prediction(type=<PredictionType.image_orientation: 'image_orientation'>, data={'count': {'up': 35}, 'orientation': 'up', 'rotation': 0}, value_tag=None, value=None, automatic_processing=None, predictor=None, barcode='3302740030949', timestamp=None, source_image='/802/509/314/0251/4.jpg', server_domain=None, id=None)] | ||
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. I think that's what you get when you run the prediction locally, but as you don't have models for nutriscore locally (they are big models), this give you no prediction with value_tag="en:nutriscore-c". You only get predictions computed by other kind of predictors. But as told below, this is not a problem, we are not interested in testing get_image_from_url but the import process. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from PIL import Image | ||
from tests import data | ||
from robotoff.insights.extraction import get_predictions_from_image | ||
from robotoff.insights.importer import import_insights | ||
from unittest.mock import Mock | ||
|
||
|
||
def test_import_insights_from_image(mock): | ||
barcode = "3302740030949" | ||
source_image = '/330/274/003/0949/6.jpg ' | ||
ocr_url = 'https://world.openfoodfacts.org/images/products/802/509/314/0251/4.json' | ||
server_domain = 'api.openfoodfacts.org' | ||
|
||
expected_predictions_all = get_predictions_from_image(barcode, data.image, source_image, ocr_url) | ||
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. We don't want to really call get_predictions_from_image because this would need to have the model, and we don't want to have it in dev / test environment. That's why you will mock the function below. Instead you should have something like: expected_predictions_all = [
PredictionFactory(type=label, barcode=barcode, data={"model": "nutriscore", "confidence": 0.871872]}, value_tag="en:nutriscore-c", value="", automatic_processing="f")
PredictionFactory(type=label, barcode=barcode, data={".... Where parameter of your instances of PredictionFactory are taken from #115 (comment) but I don't take unnecessary values (some values are automatically generated by PredictionFactory, you can look at its code). |
||
|
||
get_predictions_from_image = mock.Mock(return_value=data.expected_predictions_all) |
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.
You misinterpret my previous command about putting the image in test/data, it was to put the image file in a data/ folder :-) (that is the jpg file).
But I think you don't need that.