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=gFc+(1g)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

XRH×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}

XRH×WX~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 ⁣(QKdk)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=gFc+(1g)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=1X)=σ(wz+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=1ZijycAijk \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=Vart(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=α(1pt)γ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=1X),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