Chest X-Ray Pneumonia Detection is a Python project that compares two ways of classifying chest X-ray images as NORMAL or PNEUMONIA: a classical machine learning pipeline built on handcrafted and pixel-based features, and a deep learning pipeline that fine-tunes a pretrained ResNet18. Its README describes it as an educational and experimental project, not a clinical product, and says it must not be used for medical decision-making.
What does the project do?
The repository trains and evaluates two binary classifiers on the Kaggle-style chest X-ray folder layout, where the class folders must be named exactly NORMAL and PNEUMONIA. The classical pipeline turns each image into a combined feature vector and trains three models: an SVM with an RBF kernel, a RandomForest, and a soft-voting ensemble of SVM, RandomForest and GradientBoosting. The deep learning pipeline fine-tunes ResNet18 and writes Grad-CAM heatmaps. A combined runner, main.py, executes both, picks the best classical model by F1 score and saves a side-by-side comparison chart. Both pipelines report accuracy, sensitivity, specificity, F1-score, AUC-ROC, a confusion matrix and inference time.
For background on the two approaches, see How Does Machine Learning Work? and What is Deep Learning?
How does it work?
The classical pipeline loads grayscale images, resizes them to 256 x 256, applies CLAHE contrast enhancement and Gaussian denoising, and then extracts GLCM and LBP texture features, histogram statistics, HOG descriptors, spatial and edge statistics, and flattened pixels from 128 x 128 images. The features are standardized and reduced with PCA to 300 components before the classifiers are trained.
The deep learning pipeline resizes images to 224 x 224, applies augmentation and ImageNet normalization, and fine-tunes ResNet18 with IMAGENET1K_V1 weights and a new head of Dropout(0.4) plus a single linear output. It trains with BCEWithLogitsLoss and Adam, using defaults of 20 epochs, batch size 32 and learning rate 5e-5 on CUDA when available, and keeps the checkpoint with the lowest validation loss.
What are the design decisions?
Class imbalance in the deep learning training set is handled with a WeightedRandomSampler, and training images are augmented with random horizontal flips, rotation, affine translation and brightness and contrast jitter. Instead of a fixed 0.5 cutoff, both pipelines tune the decision threshold: the classical one selects it with 5-fold cross-validation on the training set, while the deep one uses training-set predictions and tries to reach sensitivity and specificity of 0.90 before falling back to a G-mean-optimal threshold. Grad-CAM, computed on the last block of model.layer4, produces interpretability heatmaps for sample test images from both classes. The comparison report uses different targets: 0.80 for the classical metrics and 0.90 for the deep learning metrics.
What are its limitations?
The README lists them plainly. The scripts use hardcoded absolute Windows paths that must be edited before running, the repository has no requirements.txt or dependency lockfile, and there is no script for predicting a single new image. Threshold selection in both pipelines can fall back to test-set information, so the reported test metrics should be read as experimental rather than as strict held-out benchmarks. The classical pipeline may adopt a test-set operating point when sensitivity or specificity stays below 0.80. The repository saves its results as plots, not as published numbers, so this page quotes none. The project is educational and must not be used for medical decisions.
Where can I try it or read the code?
The source is on GitHub under the MIT License. The dataset is not included: the scripts expect a Kaggle-style chest X-ray folder (the deep learning pipeline uses train, val and test, the classical one train and test). The saved plots (preprocessing, training history, evaluation, Grad-CAM overlays, comparison chart) are in the results folder. The README suggests Python 3.10+ and a manual install, after which one command runs the whole comparison:
pip install numpy matplotlib opencv-python scikit-image scikit-learn seaborn pillow torch torchvision
python3 main.py
More work like this is on the Projects page.
The one sentence version
Chest X-Ray Pneumonia Detection compares a classical machine learning pipeline with a fine-tuned ResNet18 on chest X-rays (NORMAL or PNEUMONIA), adds Grad-CAM heatmaps, and is an educational experiment, not a clinical tool.