Update README.md
Browse files
README.md
CHANGED
@@ -1,16 +1,100 @@
|
|
1 |
---
|
2 |
license: mit
|
3 |
-
language:
|
4 |
-
- en
|
5 |
-
- id
|
6 |
-
metrics:
|
7 |
-
- accuracy
|
8 |
-
pipeline_tag: image-classification
|
9 |
tags:
|
10 |
-
-
|
11 |
-
-
|
12 |
-
-
|
13 |
-
-
|
14 |
-
- pytorch
|
15 |
-
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
tags:
|
4 |
+
- image-classification
|
5 |
+
- pneumonia-detection
|
6 |
+
- healthcare
|
7 |
+
- medical-imaging
|
8 |
+
- pytorch
|
9 |
+
- resnet18
|
10 |
+
library_name: pytorch
|
11 |
+
model_name: resnet18_pneumonia_classifier
|
12 |
+
---
|
13 |
+
|
14 |
+
# ResNet18 Pneumonia Detection Model
|
15 |
+
|
16 |
+
This model is a fine-tuned version of the ResNet18 architecture for pneumonia detection. It was trained on the [Kaggle Chest X-ray Pneumonia dataset](https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia), which includes images of normal lungs and lungs with pneumonia. The model is capable of distinguishing between **Pneumonia** and **Normal** chest X-rays.
|
17 |
+
|
18 |
+
## Model Details
|
19 |
+
|
20 |
+
- **Model Architecture**: ResNet18
|
21 |
+
- **Input Size**: 224 x 224
|
22 |
+
- **Number of Classes**: 2 (Pneumonia, Normal)
|
23 |
+
- **Framework**: PyTorch
|
24 |
+
- **Training Dataset**: [Kaggle Chest X-ray Pneumonia Dataset](https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia)
|
25 |
+
- **Library**: PyTorch
|
26 |
+
|
27 |
+
## Model Performance
|
28 |
+
|
29 |
+
- **Accuracy**: 83.3%
|
30 |
+
- **Loss**: 0.2459
|
31 |
+
|
32 |
+
## Intended Use
|
33 |
+
|
34 |
+
This model is designed to assist healthcare professionals in identifying pneumonia from chest X-ray images. It should not be used as a sole diagnostic tool but as a supplement to medical expertise.
|
35 |
+
|
36 |
+
## Training Details
|
37 |
+
|
38 |
+
The model was trained using the following setup:
|
39 |
+
|
40 |
+
- **Architecture**: ResNet18 (Pre-trained on ImageNet)
|
41 |
+
- **Optimizer**: SGD (Stochastic Gradient Descent)
|
42 |
+
- **Learning Rate**: 0.001
|
43 |
+
- **Momentum**: 0.9
|
44 |
+
- **Loss Function**: CrossEntropyLoss
|
45 |
+
- **Batch Size**: 32
|
46 |
+
- **Data Augmentation**:
|
47 |
+
- Random Rotation (±30 degrees)
|
48 |
+
- Random Zoom (20%)
|
49 |
+
- Random Horizontal Shift (±10% width)
|
50 |
+
- Random Vertical Shift (±10% height)
|
51 |
+
- Random Horizontal Flip
|
52 |
+
- **Training Epochs**: 1
|
53 |
+
- **Evaluation Metric**: Cross Entropy Loss
|
54 |
+
|
55 |
+
### Augmentation Details
|
56 |
+
|
57 |
+
The dataset was augmented during training with the following transformations:
|
58 |
+
- Randomly rotated some training images by 30 degrees
|
59 |
+
- Randomly zoomed some training images by 20%
|
60 |
+
- Randomly shifted images horizontally by 10% of the width
|
61 |
+
- Randomly shifted images vertically by 10% of the height
|
62 |
+
- Randomly flipped images horizontally
|
63 |
+
|
64 |
+
|
65 |
+
## How to Use the Model
|
66 |
+
|
67 |
+
You can use this model with the `transformers` and `torch` libraries.
|
68 |
+
|
69 |
+
```python
|
70 |
+
import torch
|
71 |
+
from torchvision import transforms
|
72 |
+
from PIL import Image
|
73 |
+
import requests
|
74 |
+
|
75 |
+
# Load the model from Hugging Face Hub
|
76 |
+
model = torch.hub.load('huggingface/pytorch', 'resnet18_pneumonia_classifier')
|
77 |
+
model.eval()
|
78 |
+
|
79 |
+
# Image preprocessing
|
80 |
+
transform = transforms.Compose([
|
81 |
+
transforms.Grayscale(num_output_channels=3),
|
82 |
+
transforms.Resize((224, 224)),
|
83 |
+
transforms.ToTensor(),
|
84 |
+
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
85 |
+
])
|
86 |
+
|
87 |
+
# Sample Image (replace with your own image)
|
88 |
+
url = 'https://storage.googleapis.com/kagglesdsdata/datasets/17810/23812/chest_xray/test/NORMAL/IM-0005-0001.jpeg?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20240913%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20240913T014624Z&X-Goog-Expires=345600&X-Goog-SignedHeaders=host&X-Goog-Signature=1f6b37d181f12d083ffc951657e85fea087bb4e81ab955ec955dafcdae49c0d53ce20bc0be93605e2672b9bdd59e752eba9d5a3a0da2e3b3a03c888580b88d63d87611b4e4cec8b8802d53abd53fda165dd04765b8d9f30ddd4e908cd7a2a389ce8244fca7bfa36b3c9cff79d7c5e3f9ee7d59d5b9ef97a2e5c083997892ee3023302313fafff48ded58232db57d6affcfaee704eebba55f2b0abac40b14a38137275ad19cdb1b787930d134f7c30710e29c409bd765ca02e46851470a871cc697f614d464086373f43f5462f241eaf023cfd31e217d7b11e24e1ff34857deb200f5dc1a8c28c8115048ee840be8481f1bd79a2d8e2de1b30cb71420c007d32c'
|
89 |
+
img = Image.open(requests.get(url, stream=True).raw)
|
90 |
+
|
91 |
+
# Preprocess the image
|
92 |
+
input_img = transform(img).unsqueeze(0)
|
93 |
+
|
94 |
+
# Inference
|
95 |
+
with torch.no_grad():
|
96 |
+
output = model(input_img)
|
97 |
+
_, predicted = torch.max(output, 1)
|
98 |
+
|
99 |
+
labels = {0: 'Pneumonia', 1: 'Normal'}
|
100 |
+
print(f'Predicted label: {labels[predicted.item()]}')
|