Created
October 10, 2023 10:39
-
-
Save alexgarel/17ac6242884cb73b60f71bd35ba92f00 to your computer and use it in GitHub Desktop.
Getting images embeddings samples from robotoff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run it using docker-compose run --rm worker_high_1 python3 | |
from robotoff.prediction.category.neural.keras_category_classifier_3_0 import * | |
from robotoff.off import * | |
from robotoff.models import * | |
import json | |
import os | |
product_id = ProductIdentifier(barcode="3017620422003", server_type=ServerType.off) | |
product = get_product(product_id, fields=["images"]) | |
image_ids_int = sorted((int(image_id) for image_id in product.get("images", {}) if image_id.isdigit()),reverse=True,)[:MAX_IMAGE_EMBEDDING] | |
image_ids = [str(image_id) for image_id in image_ids_int] | |
with db: | |
embeddings_by_id = fetch_cached_image_embeddings(product_id, image_ids) | |
os.mkdir("/opt/robotoff/data/tmp") | |
json.dump({k: v.tolist() for k, v in embeddings_by_id.items()}, open(f"/opt/robotoff/data/tmp/{product_id.barcode}_embeddings.json", 'w'), sort_keys=True, indent=4) | |
# get images in ./data/tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment