Skip to content

Feature/second look UI#8

Open
HassanDawy wants to merge 8 commits into
mainfrom
feature/second-look-ui
Open

Feature/second look UI#8
HassanDawy wants to merge 8 commits into
mainfrom
feature/second-look-ui

Conversation

@HassanDawy

Copy link
Copy Markdown
Collaborator

No description provided.

HassanDawy and others added 8 commits June 28, 2026 02:34
The training tf.data pipeline feeds tf.image.decode_png(channels=1) tensors
(shape (H,W,1)) into the numpy preprocessing helpers, which surfaced two
crashes the first time modeling/train.py was run against a real build:

1. _to_grayscale rejected single-channel 3D arrays (only 2D / 3ch / 4ch were
   handled), raising "Unsupported image shape". A (H,W,1) array is already
   grayscale; squeeze the trailing axis. Fixed in both preprocessor.py and
   quality.py (the intentionally duplicated helper).

2. The module-global cv2.createCLAHE object is not thread-safe; under
   tf.data's num_parallel_calls=AUTOTUNE it crashed with an OpenCV ROI
   assertion / "Unknown C++ exception". Construct CLAHE per call instead.

Safety behavior preserved: genuinely unsupported shapes still raise
ValueError. Test suite remains green (33 passed, 2 skipped).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
demos/preprocessing_grid.py renders the 8 stages of the preprocessor
(raw -> grayscale -> CLAHE -> breast mask -> background removed ->
pectoral removed -> orientation normalized -> 224x224 model input) on a
real cached CBIS-DDSM scan and saves a slide-ready PNG. Defaults to a
positive MLO case; --case <case_folder> selects another.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
demos/second_look_app.py: single-screen app demonstrating the on-device flow
image -> preprocessing -> binary model -> confidence -> concern tier
(Low / Moderate / Elevated via label_mapper). Pick a cached CBIS sample or
upload an image; shows the 224x224 model input and a color-coded tier badge.

Carries a prominent, hard-coded "placeholder model -- not yet trained" banner:
the bundled checkpoint is a 1-epoch smoke model, so tiers are meaningless and
for plumbing demonstration only. Adds gradio to requirements.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The app now leads with the binary classification the model actually outputs
("⚠️ Worth a second look" vs "✅ Not worth a second look", thresholded at 0.5
on P(WORTH_SECOND_LOOK)) as the primary result, with the Low/Moderate/Elevated
concern tier kept as supporting context. Also auto-selects the larger overnight
checkpoint when present, falling back to the smoke model. Placeholder banner
unchanged — predictions are still for plumbing demonstration only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
evaluate.py had never been run end-to-end; on a Windows cp1252 console the
results printout crashed with UnicodeEncodeError on the "<-" arrow in the
PRIMARY METRIC marker (and the header em-dash rendered as mojibake). Replaced
both with ASCII so the evaluator runs cross-platform.

Validated end-to-end: WORTH sensitivity 0.908 on the CBIS test split with the
overnight baseline checkpoint; sensitivity-floor check prints PASS.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolved data_pipeline/preprocessor.py and data_pipeline/quality.py by taking
main's versions. Main's refactor (Dr. Fulton) already fixes both bugs this
branch fixed, more thoroughly:
- the (H,W,1) grayscale case is handled in the new data_pipeline/_imaging_utils
  .to_grayscale (shared by preprocessor + quality), and
- _apply_clahe builds CLAHE per call (thread-safe under tf.data) and runs CLAHE
  on native bit depth before normalizing.
So this branch's now-redundant edits to those two files are dropped.

Also updated demos/preprocessing_grid.py to import to_grayscale/breast_mask from
data_pipeline._imaging_utils, since main moved those helpers out of
preprocessor.py. Grid regenerated; full test suite green (33 passed, 2 skipped).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
demos/pipeline_diagram.py renders a factual DATA -> PREPROCESS -> MODEL ->
EVALUATE/UX flow (each box labeled with its real source file) and saves a
slide-ready PNG. Complements the image-level preprocessing_grid.png.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Brings main's preprocessor/quality refactor (_imaging_utils), the evaluate.py
Windows fix, the grid import fix, and the pipeline diagram into the UI branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant