加载中…
加载中…
Classroom prototype. NOT a medical device and NOT a validated pneumonia detector.
This is a custom TensorFlow Sequential CNN with three Conv2D blocks, global-average pooling, a dense layer, dropout, and a three-class softmax output. It was trained from scratch with no pretrained weights.
Classes:
INVALIDNORMALPNEUMONIARecorded configuration:
224 × 224, producing a (224, 224, 3) model input(224, 224), convert it to a NumPy array with dtype=np.float32, and add a batch dimension with np.expand_dims(..., axis=0)tf.keras.layers.Rescaling(1.0 / 255.0) inside the model; do not rescale the application input separatelytf.keras.optimizers.Adam(learning_rate=0.001)tf.keras.losses.SparseCategoricalCrossentropy()accuracyDataset name: not recorded. Dataset source: not recorded. The images are not included.
The experiment used 12 original images: 10 INVALID, 1 NORMAL, and 1 PNEUMONIA. Offline augmentation expanded these into 612 images, which were then split 80/20 with seed 123 into 490 training images and 122 validation images.
Training used EarlyStopping monitoring val_loss with patience 5 and restore_best_weights=True, plus ReduceLROnPlateau monitoring val_loss.
From saved notebook output, not re-run: validation accuracy 1.0000 and validation loss 0.00044693 on 122 validation images.
Augmentation was done before the split, so augmented copies of the same original image appear in both the training and validation sets. The same validation set drove EarlyStopping and ReduceLROnPlateau. There is no held-out test set; precision, recall, F1, and a confusion matrix were not computed. The number does not show performance on new X-rays.
The expected input is one or more RGB images resized to 224 × 224, represented as float32 values in the original 0–255 range. The model contains its own 1/255 rescaling layer.
import tensorflow as tf
from huggingface_hub import hf_hub_download
model_path = hf_hub_download(
repo_id="faiz4320/cnn-model",
filename="model.keras"
)
model = tf.keras.models.load_model(
model_path
)
For inference, convert the source image to RGB, resize it to (224, 224), convert it to a NumPy float32 array, and add a batch dimension. Do not apply another 1/255 normalization because rescaling is part of the saved model.
NORMAL image and 1 original PNEUMONIA imagehttps://github.com/faiz-sheikh/Chest-Xray-CNN