Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +59 -0
- config.json +37 -0
- example.py +36 -0
- model.keras +3 -0
- preprocessing.py +28 -0
- saved_model/fingerprint.pb +3 -0
- saved_model/saved_model.pb +3 -0
- saved_model/variables/variables.data-00000-of-00001 +3 -0
- saved_model/variables/variables.index +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
model.keras filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
---
|
| 3 |
+
language: en
|
| 4 |
+
license: mit
|
| 5 |
+
library_name: tf
|
| 6 |
+
tags:
|
| 7 |
+
- chest-xray
|
| 8 |
+
- pneumonia
|
| 9 |
+
- medical
|
| 10 |
+
- tensorflow
|
| 11 |
+
- image-classification
|
| 12 |
+
datasets:
|
| 13 |
+
- chest-xray
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Chest X-Ray Pneumonia Detection Model
|
| 17 |
+
|
| 18 |
+
This model classifies chest X-rays as either normal or showing signs of pneumonia.
|
| 19 |
+
|
| 20 |
+
## Model Description
|
| 21 |
+
|
| 22 |
+
This deep learning model was trained on the Chest X-Ray dataset to differentiate between normal lungs and those affected by pneumonia. It uses transfer learning with a pre-trained network to achieve high accuracy.
|
| 23 |
+
|
| 24 |
+
### Intended Use
|
| 25 |
+
|
| 26 |
+
This model is for **research and educational purposes only**. It should not be used for clinical diagnosis or medical decision-making without proper clinical validation.
|
| 27 |
+
|
| 28 |
+
## Usage
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
import tensorflow as tf
|
| 32 |
+
from preprocessing import preprocess_image
|
| 33 |
+
|
| 34 |
+
# Load the model
|
| 35 |
+
model = tf.keras.models.load_model("model.keras")
|
| 36 |
+
|
| 37 |
+
# Preprocess an image
|
| 38 |
+
img = preprocess_image("path/to/chest_xray.jpg")
|
| 39 |
+
|
| 40 |
+
# Make prediction
|
| 41 |
+
prediction = model.predict(img)
|
| 42 |
+
probability = prediction[0][0]
|
| 43 |
+
|
| 44 |
+
# Interpret results
|
| 45 |
+
if probability > 0.5:
|
| 46 |
+
result = "PNEUMONIA"
|
| 47 |
+
confidence = probability
|
| 48 |
+
else:
|
| 49 |
+
result = "NORMAL"
|
| 50 |
+
confidence = 1 - probability
|
| 51 |
+
|
| 52 |
+
print(f"Prediction: {result} with {confidence:.2%} confidence")
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## Limitations
|
| 56 |
+
|
| 57 |
+
- This model should not be used as a substitute for professional medical diagnosis
|
| 58 |
+
- Performance may vary across different patient demographics and equipment
|
| 59 |
+
- The model was trained on a specific dataset which may not represent all clinical scenarios
|
config.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"language": "en",
|
| 3 |
+
"license": "mit",
|
| 4 |
+
"library_name": "tf",
|
| 5 |
+
"tags": [
|
| 6 |
+
"chest-xray",
|
| 7 |
+
"pneumonia",
|
| 8 |
+
"medical",
|
| 9 |
+
"tensorflow"
|
| 10 |
+
],
|
| 11 |
+
"datasets": [
|
| 12 |
+
"chest-xray"
|
| 13 |
+
],
|
| 14 |
+
"model-index": [
|
| 15 |
+
{
|
| 16 |
+
"name": "Chest X-Ray Pneumonia Detection",
|
| 17 |
+
"results": [
|
| 18 |
+
{
|
| 19 |
+
"task": {
|
| 20 |
+
"type": "image-classification",
|
| 21 |
+
"subtype": "binary-classification"
|
| 22 |
+
},
|
| 23 |
+
"dataset": {
|
| 24 |
+
"name": "Chest X-Ray",
|
| 25 |
+
"type": "medical"
|
| 26 |
+
},
|
| 27 |
+
"metrics": [
|
| 28 |
+
{
|
| 29 |
+
"type": "accuracy",
|
| 30 |
+
"value": 0.94
|
| 31 |
+
}
|
| 32 |
+
]
|
| 33 |
+
}
|
| 34 |
+
]
|
| 35 |
+
}
|
| 36 |
+
]
|
| 37 |
+
}
|
example.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from preprocessing import preprocess_image
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Example function to run prediction
|
| 7 |
+
def predict_xray(image_path):
|
| 8 |
+
# Load model
|
| 9 |
+
model = tf.keras.models.load_model("model.keras")
|
| 10 |
+
|
| 11 |
+
# Preprocess image
|
| 12 |
+
img = preprocess_image(image_path)
|
| 13 |
+
|
| 14 |
+
# Get raw image for display
|
| 15 |
+
display_img = plt.imread(image_path)
|
| 16 |
+
|
| 17 |
+
# Run prediction
|
| 18 |
+
prediction = model.predict(img)
|
| 19 |
+
prob = prediction[0][0]
|
| 20 |
+
|
| 21 |
+
# Determine class
|
| 22 |
+
if prob > 0.5:
|
| 23 |
+
result = "PNEUMONIA"
|
| 24 |
+
confidence = prob
|
| 25 |
+
else:
|
| 26 |
+
result = "NORMAL"
|
| 27 |
+
confidence = 1 - prob
|
| 28 |
+
|
| 29 |
+
# Display results
|
| 30 |
+
plt.figure(figsize=(6, 6))
|
| 31 |
+
plt.imshow(display_img, cmap="gray")
|
| 32 |
+
plt.title(f"Prediction: {result}\nConfidence: {confidence:.2%}")
|
| 33 |
+
plt.axis("off")
|
| 34 |
+
plt.show()
|
| 35 |
+
|
| 36 |
+
return {"class": result, "confidence": float(confidence)}
|
model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d7ee3d351795c188c4412570a4334c8b9ccd5d9b4bfc1489979b8393c05f52c7
|
| 3 |
+
size 140642846
|
preprocessing.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
|
| 4 |
+
def preprocess_image(image_path, target_size=(299, 299)):
|
| 5 |
+
"""
|
| 6 |
+
Preprocesses a chest X-ray image for the model.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
image_path: Path to the image file
|
| 10 |
+
target_size: Target size for resizing
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
Preprocessed image tensor ready for prediction
|
| 14 |
+
"""
|
| 15 |
+
# Read image
|
| 16 |
+
img = tf.io.read_file(image_path)
|
| 17 |
+
img = tf.image.decode_image(img, channels=3)
|
| 18 |
+
|
| 19 |
+
# Resize
|
| 20 |
+
img = tf.image.resize(img, target_size)
|
| 21 |
+
|
| 22 |
+
# Normalize to [0,1]
|
| 23 |
+
img = img / 255.0
|
| 24 |
+
|
| 25 |
+
# Add batch dimension
|
| 26 |
+
img = tf.expand_dims(img, 0)
|
| 27 |
+
|
| 28 |
+
return img
|
saved_model/fingerprint.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aab39597d41e6bb3b1caf693a7063929afec7b823065ec4f0755f3b0c195147f
|
| 3 |
+
size 55
|
saved_model/saved_model.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c4f9413ec33133b45a92812478d1052256b332599feaa0725f6ec6b049cf15b5
|
| 3 |
+
size 3826868
|
saved_model/variables/variables.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8676a90dfe6f3e133c9257323f193423c4a823c7d174d40c6eb6cf4647763c7b
|
| 3 |
+
size 93275355
|
saved_model/variables/variables.index
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5241ac83ed297fce860cc62c1ccec32169523e73e124e0f97255d70bed10a9d9
|
| 3 |
+
size 59811
|