With the recent advancements in computer vision and optical character recognition and using a convolutional neural network to cut out the product from a picture, it has now become possible to reliably extract ingredient lists from the back of a product using the Anthropic API. Open-weight or even only on-device optical character recognition lacks the quality to be used in a production environment, although the progress in development is promising. The Anthropic API is also currently not feasible due to the high cost of 1 Swiss Franc per 100 pictures.
The training code and data is available on GitHub. This repository just contains an inference example and the report.
This repository consists of two models, one vision model and a large language model.
Vision Model
Custom convolutional neural network based on ResNet18. It detects the four corner points and the upper and lower limits of a product.
Language Model
Converts the text from the optical character recognition engine which lies in-between the two models to JSON. It is fine-tuned from unsloth/Qwen2-0.5B-Instruct-bnb-4bit.
Usage
Clone the repository and install the dependencies on any debian-based system: