Keras
Aminatron / README.md
sdhaos's picture
Upload README.md with huggingface_hub
f655f07 verified
|
Raw
History Blame Contribute Delete
6.33 kB
metadata
title: Aminatron
emoji: A
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
python_version: 3.12
pinned: false
license: mit

Aminatron

Aminatron is a multi-object detection model.

It detects several objects on one image and returns object class, confidence, bounding box and an annotated image.

Folders

aminatron/
  photos/              default input photos
  model/aminatron.pt   main Aminatron model
  runs/predict/        output images with boxes
  coco_yolo/           prepared COCO dataset
  open_images_coco_ext_yolo/ prepared COCO + Open Images dataset

model/aminatron.pt is the main model everywhere. No yolo11s.pt or yolo11m.pt files are needed after aminatron.pt is created.

Install

cd /Users/aminmammadov/aiwork/models/aminatron
python3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Create Aminatron Model

Create model/aminatron.pt from YOLO11m once:

python train.py --save-as-aminatron

This uses yolo11m.pt as source and saves it as:

model/aminatron.pt

Run On Laptop

Put images into:

aminatron/photos/

Run:

python predict.py

Run on one custom image:

python predict.py path/to/image.jpg

Results are saved to:

runs/predict/

Prepare COCO

Prepare a smaller COCO subset:

python train.py --prepare-only --max-train 5000 --max-val 1000 --overwrite

Prepare full COCO:

python train.py --prepare-only --max-train 0 --max-val 0 --overwrite

0 means no limit.

Fine-Tune Aminatron

Fine-tune the existing model/aminatron.pt:

python train.py --epochs 10

Continue training later:

python train.py --epochs 5

Both commands use model/aminatron.pt by default and save the best result back to model/aminatron.pt.

Add Open Images V7 Classes Without Forgetting COCO

Open Images V7 is useful for adding more objects like fruits, toys and animals. Do not train on Open Images alone if you want to keep old COCO classes. Prepare COCO first, then prepare a mixed COCO + Open Images dataset.

Prepare COCO if coco_yolo/data.yaml does not exist:

python train.py --prepare-only --max-train 5000 --max-val 1000 --overwrite

Install the Open Images preparation dependency locally:

pip install -r requirements-open-images.txt

FiftyOne upgrades Pillow above the version required by Gradio. That is okay for dataset preparation/training. Before running the web app again, run pip install -r requirements.txt to restore the app dependencies.

Prepare a small starter subset:

python prepare_open_images.py --max-train 2000 --max-val 500 --overwrite

Prepare a tiny test subset first if you only want to check that the pipeline works:

python prepare_open_images.py --max-train 50 --max-val 20 --overwrite

Prepare only specific classes:

python prepare_open_images.py --classes Apple Banana Orange Toy Doll "Teddy bear" Ball Cat Dog Person --max-train 3000 --max-val 700 --overwrite

The result is saved to:

open_images_coco_ext_yolo/data.yaml

This mixed dataset uses:

coco_yolo/images/train + open_images_coco_ext_yolo/images/train
coco_yolo/images/val   + open_images_coco_ext_yolo/images/val

Class ids are COCO-compatible. Matching Open Images classes are mapped into existing COCO ids, for example Person -> person, Dog -> dog, Apple -> apple, Teddy bear -> teddy bear. Truly new classes are added after the 80 COCO classes.

Because your previous test run produced an 18-class aminatron.pt, restore the COCO base before additive training:

python train.py --save-as-aminatron

Train Aminatron on COCO + Open Images together:

python train.py --data-dir open_images_coco_ext_yolo --no-auto-prepare --epochs 10

--no-auto-prepare is intentional: it prevents train.py from accidentally preparing plain COCO if open_images_coco_ext_yolo/data.yaml is missing.

Important: old model files are backed up automatically to model/backups/ before model/aminatron.pt is overwritten.

Web Demo

python app.py

Hugging Face Space Email Review

The Space can email the original uploaded image and the processed result image to:

mammadov.amin2000@gmail.com

For this to work, add these Hugging Face Space Secrets:

RESEND_API_KEY=your_resend_api_key
EMAIL_TO=mammadov.amin2000@gmail.com
EMAIL_FROM=Aminatron <onboarding@resend.dev>

Recommended setup:

  1. Create a Resend account with mammadov.amin2000@gmail.com.
  2. Create an API key at https://resend.com/api-keys.
  3. Add RESEND_API_KEY to Hugging Face Space Secrets.
  4. Keep EMAIL_TO=mammadov.amin2000@gmail.com.

If you use Resend without a verified custom domain, keep:

EMAIL_FROM=Aminatron <onboarding@resend.dev>

This is better for Hugging Face Spaces than Gmail SMTP because SMTP ports can be unreachable from the Space container.

Fallback Gmail SMTP secrets, only if SMTP works in your environment:

SMTP_USER=your_gmail_address@gmail.com
SMTP_PASSWORD=your_gmail_app_password
EMAIL_TO=mammadov.amin2000@gmail.com

For Gmail, SMTP_PASSWORD must be a Gmail App Password, not your normal Gmail password.

You can also use this secret name instead of SMTP_PASSWORD:

GMAIL_APP_PASSWORD=your_gmail_app_password

Gmail setup:

  1. Enable 2-Step Verification in your Google account.
  2. Create an App Password for Mail.
  3. Put that app password into SMTP_PASSWORD or GMAIL_APP_PASSWORD.

Optional secrets:

SMTP_HOST=smtp.gmail.com
SMTP_PORT=587

If SMTP secrets are missing, the Space still works, but photos are not emailed.

Most Needed Commands

cd /Users/aminmammadov/aiwork/models/aminatron
source .venv/bin/activate
python train.py --save-as-aminatron
python predict.py
python train.py --prepare-only --max-train 5000 --max-val 1000 --overwrite
pip install -r requirements-open-images.txt
python prepare_open_images.py --max-train 2000 --max-val 500 --overwrite
python train.py --save-as-aminatron
python train.py --data-dir open_images_coco_ext_yolo --no-auto-prepare --epochs 10
python train.py --epochs 10
python train.py --epochs 5
python app.py