faiz4320 commited on
Commit
e9cc1f4
·
verified ·
1 Parent(s): d6811e5

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +83 -0
README.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: keras
4
+ pipeline_tag: image-classification
5
+ tags: [cnn, image-classification, tensorflow, keras, educational, from-scratch]
6
+ ---
7
+
8
+ # cnn-model: small CNN image-classification demo
9
+
10
+ Classroom prototype. NOT a medical device and NOT a validated pneumonia detector.
11
+
12
+ ## Model
13
+
14
+ 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.
15
+
16
+ Classes:
17
+
18
+ - `INVALID`
19
+ - `NORMAL`
20
+ - `PNEUMONIA`
21
+
22
+ Recorded configuration:
23
+
24
+ - Input: RGB image resized to `224 × 224`, producing a `(224, 224, 3)` model input
25
+ - Application preprocessing: convert the image to RGB, resize it to `(224, 224)`, convert it to a NumPy array with `dtype=np.float32`, and add a batch dimension with `np.expand_dims(..., axis=0)`
26
+ - Rescaling: `tf.keras.layers.Rescaling(1.0 / 255.0)` inside the model; do not rescale the application input separately
27
+ - Optimizer: `tf.keras.optimizers.Adam(learning_rate=0.001)`
28
+ - Loss: `tf.keras.losses.SparseCategoricalCrossentropy()`
29
+ - Training metric: `accuracy`
30
+
31
+ ## Training data
32
+
33
+ Dataset name: **not recorded**. Dataset source: **not recorded**. The images are not included.
34
+
35
+ 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.
36
+
37
+ Training used `EarlyStopping` monitoring `val_loss` with patience 5 and `restore_best_weights=True`, plus `ReduceLROnPlateau` monitoring `val_loss`.
38
+
39
+ ## Result
40
+
41
+ **From saved notebook output, not re-run:** validation accuracy **1.0000** and validation loss **0.00044693** on 122 validation images.
42
+
43
+ ## How to read this result
44
+
45
+ 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.
46
+
47
+ ## How to load it
48
+
49
+ 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.
50
+
51
+ ```python
52
+ import tensorflow as tf
53
+ from huggingface_hub import hf_hub_download
54
+
55
+ model_path = hf_hub_download(
56
+ repo_id="faiz4320/cnn-model",
57
+ filename="model.keras"
58
+ )
59
+
60
+ model = tf.keras.models.load_model(
61
+ model_path
62
+ )
63
+ ```
64
+
65
+ 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.
66
+
67
+ ## Intended use and limitations
68
+
69
+ - Educational demonstration only; not for medical use
70
+ - Tiny independent sample: 1 original `NORMAL` image and 1 original `PNEUMONIA` image
71
+ - Leakage caused by augmenting before splitting
72
+ - No held-out test set
73
+ - Artificial class balance created through augmentation
74
+ - Dataset source not recorded
75
+
76
+ ## Code
77
+
78
+ https://github.com/faiz-sheikh/Chest-Xray-CNN
79
+
80
+ ## Credits
81
+
82
+ - TensorFlow/Keras
83
+ - Streamlit