YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
π§Ύ Receipt (Bonnetje) Segmentation β YOLO11n-seg + Streamlit
A web app that detects receipts in photos and outlines them with a pixel-level segmentation mask, then lets you download the straightened (deskewed) receipt.
- Model: YOLO11n-seg, 1 class (
bonnetje= receipt), ~2.8 M parameters, ~6 MB βciCic/yolo11n-seg-bonnetjeson Hugging Face - App: Streamlit Β· runs on CPU, no GPU needed
Features
- Upload one or many images (JPG, PNG, WEBP, BMP) or use the camera
- Adjustable confidence / IoU / image-size settings
- Annotated image with masks, plus a table (confidence, box, mask area)
- Extracts each receipt as a straightened crop (perspective-corrected), downloadable as PNG
- Handles phone-photo EXIF rotation and downsizes very large images automatically
Project structure
βββ app.py # Streamlit UI
βββ inference.py # model loading, prediction, deskew helpers
βββ requirements.txt # Python dependencies (used by Streamlit Cloud)
βββ packages.txt # system libs for OpenCV on Streamlit Cloud
βββ .streamlit/config.toml # server / theme settings
βββ models/ # optional: put your own best.pt here
βββ notebooks/ # original Colab training notebook
βββ tests/ # offline unit tests (pytest)
βββ .github/workflows/ci.yml
Run locally
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
streamlit run app.py
Open http://localhost:8501. The first start downloads the ~6 MB weights from Hugging Face and caches them.
Run the tests (no internet or GPU needed):
pip install -r requirements-dev.txt
pytest -q
Publish to GitHub
git init
git add .
git commit -m "Receipt segmentation Streamlit app"
git branch -M main
git remote add origin https://github.com/<your-username>/<repo-name>.git
git push -u origin main
Deploy on Streamlit Community Cloud (free)
- Push the repo to GitHub (above). The repo must be public, or you must grant Streamlit access.
- Go to https://share.streamlit.io β Create app β pick your repo and branch
main. - Set Main file path to
app.py. - Open Advanced settings β choose Python 3.12.
- Click Deploy. The first build takes several minutes (PyTorch is large).
packages.txt installs the system libraries OpenCV needs; no other setup is required.
Using your own weights
Copy your trained checkpoint to models/best.pt (commit it; ~6 MB is fine for GitHub).
It takes priority over the Hugging Face download. You can also set the environment
variable MODEL_PATH, or HF_REPO_ID / HF_FILENAME to point at a different Hub model.
About the training notebook: the notebook fine-tunes on COCO128-seg, which has 80 classes, while this model has 1 (
bonnetje). Ultralytics skips every label it can't map, so that run learns nothing (validation mAP β 0). This app therefore uses the original Hugging Face model. To really fine-tune, use a receipt segmentation dataset with a single class0: bonnetjeand polygon labels.
Troubleshooting
| Problem | Fix |
|---|---|
ImportError: libGL.so.1 |
Make sure packages.txt is in the repo root (it is included). |
| Build fails / runs out of disk or memory on Streamlit Cloud | Default PyTorch from PyPI ships multi-GB CUDA libraries. Put these two lines at the top of requirements.txt to use the small CPU build: --extra-index-url https://download.pytorch.org/whl/cpu then torch==2.6.0+cpu and torchvision==0.21.0+cpu (each on its own line). Or deploy on Hugging Face Spaces / Render / Docker. |
| "Could not load the model" | First run needs internet access to Hugging Face, or provide models/best.pt. |
| No detections | Lower the confidence slider; make sure the receipt is clearly visible. |
License
MIT for the app code (see LICENSE). Ultralytics is AGPL-3.0; the model weights follow
the license on their Hugging Face page. Check both before commercial use.