Skip to content

Commit

Permalink
Revert "feat: use the new category classifier model for category pred…
Browse files Browse the repository at this point in the history
…iction (#512)"

This reverts commit a45ded0.
  • Loading branch information
Olivier Cervello committed Dec 9, 2021
1 parent a45ded0 commit 30dc472
Show file tree
Hide file tree
Showing 19 changed files with 933 additions and 380 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/models-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,34 @@ jobs:
tar -xzvf saved_model.tar.gz --strip-component=1
rm saved_model.tar.gz
# TODO(kulizhsy): delete this job after we've migrated to TF Serving.
keras-category-classifier-sync:
name: Sync Keras category classifier configs
runs-on: ubuntu-latest
environment: ${{ matrix.env }}
strategy:
matrix:
env:
- ${{ startsWith(github.ref, 'refs/tags/v') && 'robotoff-org' || 'robotoff-net' }}
steps:
- uses: actions/checkout@master
- name: Download
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
proxy_host: ${{ secrets.PROXY_HOST }}
proxy_username: ${{ secrets.USERNAME }}
proxy_key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ matrix.env }}/models
base_url=https://github.com/openfoodfacts/robotoff-models/releases/download/keras-category-classifier-xx-1.0
dest_folder=category
mkdir -p ${dest_folder}
wget -cO - ${base_url}/config.json > ${dest_folder}/config.json
wget -cO - ${base_url}/category_taxonomy.json > ${dest_folder}/category_taxonomy.json
wget -cO - ${base_url}/category_voc.json > ${dest_folder}/category_voc.json
wget -cO - ${base_url}/ingredient_voc.json > ${dest_folder}/ingredient_voc.json
wget -cO - ${base_url}/product_name_voc.json > ${dest_folder}/product_name_voc.json
wget -cO - ${base_url}/checkpoint.hdf5 > ${dest_folder}/checkpoint.hdf5
26 changes: 26 additions & 0 deletions data/clf_category_blacklist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
en:alcoholic-beverages
en:beverages
en:biscuits-and-cakes
en:breakfasts
en:cereals-and-potatoes
en:cereals-and-their-products
en:dairies
en:fermented-foods
en:fermented-milk-products
en:frozen-foods
en:fruits-and-vegetables-based-foods
en:fruits-based-foods
en:groceries
en:meals
en:meat-based-products
en:meats
en:non-alcoholic-beverages
en:plant-based-beverages
en:plant-based-foods
en:plant-based-foods-and-beverages
en:prepared-meats
en:snacks
en:spreads
en:sweet-snacks
en:sweet-spreads
en:vegetables-based-foods
36 changes: 15 additions & 21 deletions robotoff/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,31 +194,25 @@ def download_models(force: bool = False) -> None:
def categorize(
barcode: str,
deepest_only: bool = False,
blacklist: bool = False,
) -> None:
"""Categorise predicts product categories based on the neural category classifier.
deepest_only: controls whether the returned predictions should only contain the deepmost
categories for a predicted taxonomy chain.
For example, if we predict 'fresh vegetables' -> 'legumes' -> 'beans' for a product,
setting deepest_only=True will return 'beans'."""
from robotoff.ml.category.neural.category_classifier import CategoryClassifier
from robotoff.products import get_product
from robotoff.taxonomy import TaxonomyType, get_taxonomy

product = get_product(barcode)
if product is None:
print(f"Product {barcode} not found")
return

predicted = CategoryClassifier(get_taxonomy(TaxonomyType.category.name)).predict(
product, deepest_only
from robotoff import settings
from robotoff.ml.category.neural.model import (
LocalModel,
filter_blacklisted_categories,
)
from robotoff.utils import get_logger

get_logger()
model = LocalModel(settings.CATEGORY_CLF_MODEL_PATH)
predicted = model.predict_from_barcode(barcode, deepest_only=deepest_only)

if predicted:
for prediction in predicted:
print(f"{prediction.category}: {prediction.confidence}")
else:
print(f"Nothing predicted for product {barcode}")
if blacklist:
predicted = filter_blacklisted_categories(predicted)

for cat, confidence in predicted:
print("{}: {}".format(cat, confidence))


@app.command()
Expand Down
1 change: 0 additions & 1 deletion robotoff/insights/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def import_insights(
server_domain: str,
automatic: bool,
) -> int:
"""Returns the number of insights that were imported."""
timestamp = datetime.datetime.utcnow()
processed_insights: Iterator[Insight] = self.process_insights(
data, server_domain, automatic
Expand Down
Loading

0 comments on commit 30dc472

Please sign in to comment.