MedFusionNet β€” Hybrid Pneumonia Detection on Chest X-Rays

Original project: carteeeltheboss/DPR_PFA4IADO

ROC - Confusion Matrix - Benchmarks

Benchmark 1

Benchmark 2

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) \tilde X = T(X)

Fc=Ξ¦c(X~),Fs=Ξ¦s(X~) F_c = \Phi_c(\tilde X), \qquad F_s = \Phi_s(\tilde X)

g=σ ⁣(Wg[GAP⁑(Fc),GAP⁑(Fs)]+bg) g = \sigma\!\big(W_g[\operatorname{GAP}(F_c), \operatorname{GAP}(F_s)] + b_g\big)

F=gβŠ™Fc+(1βˆ’g)βŠ™Fs F = g \odot F_c + (1-g)\odot F_s

Ξ¨(F)=(p,Lc,u) \Psi(F) = (p, L^c, 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 X \in \mathbb{R}^{H \times W}

y={1PNEUMONIA0NORMAL y= \begin{cases} 1 & \text{PNEUMONIA}\\ 0 & \text{NORMAL} \end{cases}

X~=T(X)=A(R(N(X))) \tilde X = T(X)=A(R(N(X)))

Xnorm=Xβˆ’ΞΌΟƒ X_{\text{norm}}=\frac{X-\mu}{\sigma}

X∈RHΓ—Wβ†’X~∈R384Γ—384 X \in \mathbb{R}^{H \times W} \rightarrow \tilde X \in \mathbb{R}^{384 \times 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 F_c = \Phi_c(\tilde X) \in \mathbb{R}^{H' \times W' \times C_c}

Fi,j,cβ€²(β„“)=βˆ‘u,v,cWu,v,c,cβ€²(β„“)Fi+u,j+v,c(β„“βˆ’1)+bcβ€²(β„“) F^{(\ell)}_{i,j,c'}= \sum_{u,v,c} W^{(\ell)}_{u,v,c,c'}F^{(\ell-1)}_{i+u,j+v,c}+b^{(\ell)}_{c'}

Short summary: captures local opacities, fine textures, subtle consolidations, and small radiographic details.


4) Global branch: Swin Transformer

zi=Exi+eipos z_i = E x_i + e_i^{pos}

Fs=Ξ¦s(X~)∈RHβ€²Γ—Wβ€²Γ—Cs F_s=\Phi_s(\tilde X)\in\mathbb{R}^{H' \times W' \times C_s}

Q=XWQ,K=XWK,V=XWV Q=XW_Q,\qquad K=XW_K,\qquad V=XW_V

Attention⁑(Q,K,V)=softmax⁑ ⁣(QK⊀dk)V \operatorname{Attention}(Q,K,V)= \operatorname{softmax}\!\left(\frac{QK^\top}{\sqrt{d_k}}\right)V

Short summary: captures long-range thoracic structure and contextual anatomical dependencies.


5) Adaptive gated fusion

FΛ‰c=GAP⁑(Fc),FΛ‰s=GAP⁑(Fs) \bar F_c=\operatorname{GAP}(F_c), \qquad \bar F_s=\operatorname{GAP}(F_s)

g=σ ⁣(Wg[FΛ‰c,FΛ‰s]+bg) g=\sigma\!\left(W_g[\bar F_c,\bar F_s]+b_g\right)

F=gβŠ™Fc+(1βˆ’g)βŠ™Fs F=g\odot F_c + (1-g)\odot F_s

Short summary: learns how much the model should trust local evidence versus global context for each image.


6) Classification head

z=GAP⁑(F) z=\operatorname{GAP}(F)

p(y=1∣X)=Οƒ(w⊀z+b) p(y=1\mid X)=\sigma(w^\top z+b)

y^={1if pβ‰₯Ο„0if p<Ο„ \hat y= \begin{cases} 1 & \text{if } p \ge \tau\\ 0 & \text{if } p < \tau \end{cases}

Short summary: converts fused features into a binary pneumonia probability.


7) Grad-CAM

Ξ±kc=1Zβˆ‘iβˆ‘jβˆ‚ycβˆ‚Aijk \alpha_k^c = \frac{1}{Z}\sum_i\sum_j \frac{\partial y^c}{\partial A^k_{ij}}

Lc=ReLU⁑ ⁣(βˆ‘kΞ±kcAk) L^c=\operatorname{ReLU}\!\left(\sum_k \alpha_k^c A^k\right)

Short summary: highlights the image regions that support the predicted class.


8) MC-Dropout uncertainty

u=Var⁑t(pt) u=\operatorname{Var}_t(p_t)

Short summary: repeated stochastic forward passes estimate prediction stability.


9) Training objective

L=Lcls+Ξ»1Lloc+Ξ»2Lcons+Ξ»3Lcal \mathcal{L} = \mathcal{L}_{cls} + \lambda_1\mathcal{L}_{loc} + \lambda_2\mathcal{L}_{cons} + \lambda_3\mathcal{L}_{cal}

Lfocal=βˆ’Ξ±(1βˆ’pt)Ξ³log⁑(pt) \mathcal{L}_{focal} = -\alpha (1-p_t)^\gamma \log(p_t)

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) \big(p(y=1\mid X),\,L^c,\,u\big)

Short summary: final prediction = probability + explanation map + uncertainty estimate.


12) Original project

GitHub: https://github.com/carteeeltheboss/DPR_PFA4IADO

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support