# PELM: A Deep Learning Model for Early Detection of Pneumonia in Chest Radiography
## 3 Materials and Methods
### Data Collection and Preprocessing
#### 3.1.1 Dataset
Representative examples are shown in Figure 4, illustrating clear lungs in a normal scan, localized consolidation in bacterial pneumonia, and diffuse opacities in viral pneumonia. The CXR-NIH, CheXpert, PadChest, and Kaggle CXR datasets were combined, and independent datasets were studied to prevent patient overlaps. The authors have declared that there are no patient overlaps across the datasets, ensuring all samples are unique. Regarding dataset selection criteria, chest X-rays in both posterior-anterior (PA) and anteroposterior (AP) views were considered to ensure coverage of pneumonia cases commonly encountered in clinical settings, including ICU patients. Poor quality or unreadable images (e.g., excessive noise, motion blur) were excluded using an automatic filtering review process. The distribution of the datasets used in this study is presented in detail in Table 2.  
To build a robust and generalizable model for pneumonia detection, this study employed data augmentation and transfer learning as foundational techniques. These strategies were critical for improving model performance, mitigating overfitting, and addressing class imbalance and dataset heterogeneity. An initial pool of 57,656 chest X-ray (CXR) images was compiled from four large-scale public datasets: PadChest, CXR NIH, Kaggle CXR Pneumonia, and CheXpert. Following a rigorous quality control process--which excluded images with low resolution, poor exposure, or anatomical truncation--and a class-balancing step, a refined dataset of 50,000 images was constructed, containing equal numbers of pneumonia-positive and normal/other findings cases (25,000 each). \begin{table}
\begin{tabular}{c c c c c} \hline \hline  & **Kaggle CXR** & **CXR NIH** & **PadChest** & **CheXpert** \\  & **Pneumonia** & & & \\ \hline Pneumonia & 4273 & 1431 & 8174 & 6047 \\ Normal & 1583 & 60,361 & 50,684 & 22,419 \\ Other Findings & - & 50,328 & 102,003 & 195,182 \\ Total & 5856 & 112,120 & 160,861 & 223,648 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Data set distribution. Figure 4: Kaggle CXR Pneumonia Dataset (**(a)** “Normal”, **(b)** “Bacterial Pneumonia”, **(c)** “Viral Pneumonia”) [26]. To ensure fair and consistent evaluation, the curated dataset was partitioned into 40,000 training, 5000 validations, and 5000 test images. The distribution and origin of the images used are detailed in Table 3.  
While the curated dataset used in this study supports more consistent and balanced model training, it does not fully encapsulate the variability observed in real-world clinical practice. Technically suboptimal images--such as those affected by low contrast, motion artifacts, or non-standard patient positioning--were excluded during quality filtering. Although this improves training stability, it may limit the model's generalizability, as such imperfections are frequently encountered in everyday radiology workflows. Furthermore, while the negative (non-pneumonia) class included a mix of normal and pathological findings (e.g., fibrosis, cardiomegaly, and nodules), and the pneumonia class encompassed cases with overlapping thoracic abnormalities (e.g., pleural effusion, consolidation, and infiltration), both classes were curated to a degree. As a result, the dataset may not fully reflect the diagnostic complexity and clinical ambiguity often present in actual practice. Future studies should incorporate a broader range of image quality, acquisition variability, and comorbid conditions to better align with real-world deployment scenarios. To mitigate dataset limitations and improve classification performance, we employed transfer learning using a diverse set of high-performing convolutional and transformer-based models, including VGG16, ResNet50, InceptionV3, DenseNet121, DenseNet201, MobileNetV2, and Vision Transformer (ViT). Pretrained on the ImageNet dataset, these architectures provide robust and transferable hierarchical representations, which were fine-tuned for pneumonia detection.