This project trains a classifier to distinguish between coded targets, uncoded targets, and non‑targets from image patches. It also includes a public-only test script (test_blob.py) that uses OpenCV’s blob detector to propose candidate detections on arbitrary images.
- Python version: 3.10+ recommended
- From the repo root:
python -m venv venv
.\venv\Scripts\Activate.ps1 # PowerShell on Windows
pip install -r requirements.txtThe repo is configured to ignore large / private assets:
data/andtest_data/(your images)venv/(virtual environment)test.py(private ellipse-fitting harness)
You are expected to provide your own images locally; they are never committed.
If you want to retrain the model:
-
Prepare your data as three folders under
data/:data/Coded/data/not_coded/data/not_target/
-
Run the augmentation / preparation script:
python augment.py- Train the EfficientNet classifier:
python train.py --data_dir ./data/prepared --epochs 30 --batch_size 32This will create:
data/results/best_model.pthdata/results/class_map.json
These are used by test_blob.py for inference. Because data/ is in .gitignore,
you need to train locally to produce these files, or download compatible
weights from a release (if provided on GitHub in the future).
test_blob.py is the public test harness. It:
- uses OpenCV SimpleBlobDetector to find bright/dark round-ish blobs,
- crops patches around each detection,
- runs the trained classifier on each patch,
- keeps predictions labeled Coded or not_coded,
- treats not_target or low-confidence detections as false positives,
- overlays results on the original image:
- green circles = Coded (kept)
- blue circles = not_coded (kept)
- red X = not_target / low-confidence (deleted)
Create a folder (default is test_data/) and drop your test images there:
CCT_Filter/
test_blob.py
data/
results/
best_model.pth
class_map.json
test_data/
your_image_01.png
your_image_02.jpg
...
Images can be .png, .jpg, .jpeg, or .bmp.
From the repo root with the venv activated:
python test_blob.pyBy default this will:
- read images from
./test_data, - load the model from
./data/results/best_model.pth, - open a Matplotlib window per image with the overlayed detections.
You can customize paths and saving:
python test_blob.py \
--test_dir ./my_images \
--model_path ./data/results/best_model.pth \
--cpu \
--save--test_dir– folder containing your own images.--model_path– path to a compatiblebest_model.pthand itsclass_map.json.--cpu– force CPU inference (use this if you see CUDA out-of-memory errors).--save– additionally writes{image_stem}_filtered_blob.pngnext to each input.
Inside test_blob.py:
CONFIDENCE_THRESHOLD = 0.85 # only keep if model is sureAny prediction with confidence below this threshold is treated as not_target, so it will be drawn as a red X and counted as “deleted”. You can tune this value (e.g. 0.9 for stricter filtering, 0.7 for more permissive).
To make the project immediately understandable to new visitors, you can add a demo overlay image:
- Run
test_blob.pyon a representative image. - Take a screenshot of the Matplotlib window showing green/blue/red markers.
- Save it as
assets/demo.pngin the repo root.
Once that file exists, you can embed it in your GitHub description or here:
This repository does not include any copyrighted source imagery; assets/demo.png
should be generated from your own data or from images you have rights to share.
- Your images are never committed:
data/andtest_data/are in.gitignore. data/results/(includingbest_model.pth) is also ignored by default; consumers must either train locally or download weights from a release you publish.test_blob.pyuses only public OpenCV APIs and your local model; it does not depend on any private ellipse-fitting implementation.