MedFusionNet β Hybrid Pneumonia Detection on Chest X-Rays
Original project: carteeeltheboss/DPR_PFA4IADO
ROC - Confusion Matrix - Benchmarks


MedFusionNet is a binary chest X-ray classifier for NORMAL vs PNEUMONIA using:
- DenseNet-121 for local patterns
- Swin Transformer for global context
- gated fusion
- Grad-CAM
- MC-Dropout
1) Global pipeline
X~=T(X)
Fcβ=Ξ¦cβ(X~),Fsβ=Ξ¦sβ(X~)
g=Ο(Wgβ[GAP(Fcβ),GAP(Fsβ)]+bgβ)
F=gβFcβ+(1βg)βFsβ
Ξ¨(F)=(p,Lc,u)
Short summary: preprocess the image, extract local and global features, fuse them adaptively, then output probability, heatmap, and uncertainty.
2) Input and preprocessing
XβRHΓW
y={10βPNEUMONIANORMALβ
X~=T(X)=A(R(N(X)))
Xnormβ=ΟXβΞΌβ
XβRHΓWβX~βR384Γ384
Short summary: normalize intensity, resize to a fixed resolution, and standardize the input domain.
3) Local branch: DenseNet-121
Fcβ=Ξ¦cβ(X~)βRHβ²ΓWβ²ΓCcβ
Fi,j,cβ²(β)β=u,v,cββWu,v,c,cβ²(β)βFi+u,j+v,c(ββ1)β+bcβ²(β)β
Short summary: captures local opacities, fine textures, subtle consolidations, and small radiographic details.
4) Global branch: Swin Transformer
ziβ=Exiβ+eiposβ
Fsβ=Ξ¦sβ(X~)βRHβ²ΓWβ²ΓCsβ
Q=XWQβ,K=XWKβ,V=XWVβ
Attention(Q,K,V)=softmax(dkββQKβ€β)V
Short summary: captures long-range thoracic structure and contextual anatomical dependencies.
5) Adaptive gated fusion
FΛcβ=GAP(Fcβ),FΛsβ=GAP(Fsβ)
g=Ο(Wgβ[FΛcβ,FΛsβ]+bgβ)
F=gβFcβ+(1βg)βFsβ
Short summary: learns how much the model should trust local evidence versus global context for each image.
6) Classification head
z=GAP(F)
p(y=1β£X)=Ο(wβ€z+b)
y^β={10βif pβ₯Οif p<Οβ
Short summary: converts fused features into a binary pneumonia probability.
7) Grad-CAM
Ξ±kcβ=Z1βiββjβββAijkββycβ
Lc=ReLU(kββΞ±kcβAk)
Short summary: highlights the image regions that support the predicted class.
8) MC-Dropout uncertainty
u=Vartβ(ptβ)
Short summary: repeated stochastic forward passes estimate prediction stability.
9) Training objective
L=Lclsβ+Ξ»1βLlocβ+Ξ»2βLconsβ+Ξ»3βLcalβ
Lfocalβ=βΞ±(1βptβ)Ξ³log(ptβ)
Short summary: the objective combines classification, localization regularization, consistency, and calibration.
10) Dataset
Dataset: Paul Mooney Chest X-Ray Images (Pneumonia)
Classes: NORMAL, PNEUMONIA
data/
βββ train/
β βββ NORMAL/
β βββ PNEUMONIA/
βββ val/
β βββ NORMAL/
β βββ PNEUMONIA/
βββ test/
βββ NORMAL/
βββ PNEUMONIA/
Short summary: binary chest X-ray classification with strong class imbalance and noisy acquisition conditions.
11) Final output
(p(y=1β£X),Lc,u)
Short summary: final prediction = probability + explanation map + uncertainty estimate.
12) Original project
GitHub: https://github.com/carteeeltheboss/DPR_PFA4IADO