With multi-center k=5 reference the gate is already more selective;
0.55 was too strict for non-standard angles (e.g. spread intestinal
specimens). p5 of training set is 0.507 so 0.35 still filters true
outliers while allowing valid pathology images through.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add k-means multi-center reference for similarity gateβ
- model.py: predict_image accepts 2-D ref_emb (cluster centers);
sim = max cosine similarity to any center; thres default 0.55
- main.py: load cluster_centers.npy if present, else avg12_embedding.npy
- scripts/compute_cluster_centers.py: extract embeddings from all
training images, k-means k=5, save cluster_centers.npy
Run script once to generate cluster_centers.npy, then redeploy.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove LOW_CONF block: in-range images should always be classifiedβ
Images passing the similarity gate (is_in_criteria=True) are already
confirmed as in-distribution. Low model confidence in those cases just
means borderline bacteria/virus β still a valid classification.
Only keep HIGH_CONF bypass (>= 0.85) to fix high-confidence images
being wrongly blocked by sim gate (e.g. organ specimens on black bg).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three-zone confidence decision: bypass sim gate for high-conf, reject low-confβ
New module: app/dashboard/
- router.py: APIRouter with 5 endpoints
GET /dashboard/ β HTML dashboard page
GET /dashboard/status/ β CPU / RAM / Disk metrics via psutil
GET /dashboard/logs/ β tail of app.log (last N lines)
GET /dashboard/database/β inference_results.csv as JSON
GET /dashboard/uploads/ β list of uploaded images
GET /dashboard/uploads/{filename} β serve image file
- index.html: single-page dashboard with auto-refresh every 5s
Status cards (CPU%, RAM, Disk), Logs viewer, Records table,
Uploaded images grid
app/main.py: register dashboard router
requirements.txt: add psutil
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix 5 bugs in upload validation, inference, and file cleanupβ
- Bug1: Replace second-precision timestamp with uuid suffix to prevent
filename collision under concurrent requests
- Bug2: Add file extension whitelist in save_uploaded_file; raise
ValueError for unsupported types before writing to disk
- Bug3: Remove misleading comment claiming SIM_THRES default is 0.75
- Bug4: Explicitly check model output keys and raise KeyError instead
of silently falling back to positional indices
- Bug5: Call os.remove(saved_path) in preprocessing failure path to
prevent orphaned files accumulating in uploads/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>