# Youssef Ahmed Afify

- **Event:** [Built with Opus 4.7: a Claude Code hackathon](https://cerebralvalley.ai/e/built-with-4-7-hackathon)
- **When:** Apr 21 at 12:00 PM – Apr 27 at 2:00 AM (EDT)
- **Where:** Online
- **Team:** [Yusuf Afify](https://cerebralvalley.ai/u/Afify)
- **GitHub:** https://github.com/yusufafify/interpretable-med-mamba
- **Demo video:** https://drive.google.com/file/d/1-QHEUw5E0SZGlT99_jXfTVJx8qBEoScQ/view?usp=sharing
- **Gallery:** https://cerebralvalley.ai/e/built-with-4-7-hackathon/hackathon/gallery
- **Page:** https://cerebralvalley.ai/e/built-with-4-7-hackathon/hackathon/gallery/168

MedMamba is an autonomous medical-image diagnostic system: drop in any image and the model decides for itself which of four imaging modalities it is (histopathology, dermoscopy, blood-cell microscopy, or retinal OCT), runs the matching diagnostic head, generates an SSM-GradCAM saliency map, and asks Claude Opus 4.7 to produce a clinician-style explanation of what it's looking at — with no human ever specifying the modality.

The problem: standard multi-task medical classifiers fail on an unspoken assumption — a human must tell the model what kind of image it is at inference. That makes them useless for any real triage scenario where the modality is the question itself.

The architectural contribution: a Supervised-Contrastive auxiliary objective trained alongside the multi-task heads forces the VMamba backbone to learn modality-separating geometry. After training, per-modality prototypes are stored inside the model. At inference, an unknown image self-routes via 1-NN cosine similarity in feature space, then the matching head fires. Two objectives (fine-grained class CE + coarse-grained domain SupCon) operate at orthogonal scales, so satisfying both costs essentially no per-task accuracy. Trained results across 4 MedMNIST+ datasets: avg F1 = 0.90 (PathMNIST 0.99, BloodMNIST 0.99, OCTMNIST 0.92, DermaMNIST 0.70 — class-imbalance bound), 93/93 tests passing.

The Opus 4.7 contribution: the autonomous prediction (modality + class + confidence + top-k) and the GradCAM heatmap are sent to Opus 4.7 alongside the original image. Opus 4.7 returns a structured JSON explanation — focus_region, finding, differential, confidence_note, follow_up — using the right vocabulary per modality (histopathology, dermoscopic, cytomorphological, or retinal-OCT terms). Because Opus 4.7 sees both the image AND the heatmap, it surfaces a known failure mode pure-softmax can't: high model confidence + diffuse heatmap = flag for manual review.

Provenance: every line was written collaboratively with Claude Code. The SupCon contrastive feature itself was planned, implemented, tested, and verified by a single Opus 4.7 Claude Code agent session — 7 files changed, 17 new tests added, 93 tests green on first run.

---

Markdown version of https://cerebralvalley.ai/e/built-with-4-7-hackathon/hackathon/gallery/168. Site index for agents: https://cerebralvalley.ai/llms.txt · full text: https://cerebralvalley.ai/llms-full.txt
