Initial Commit
Browse files- .gitattributes +1 -0
- README.md +79 -0
- app.py +65 -0
- best_model_efficientnet_vad2.h5 +3 -0
- model.h5 +3 -0
- model/fingerprint.pb +3 -0
- model/keras_metadata.pb +3 -0
- model/saved_model.pb +3 -0
- model/variables/variables.data-00000-of-00001 +3 -0
- model/variables/variables.index +0 -0
- requirements.txt +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/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
license: mit
|
4 |
+
tags:
|
5 |
+
- tensorflow
|
6 |
+
- image-classification
|
7 |
+
- medical-imaging
|
8 |
+
- vascular-dementia
|
9 |
+
datasets:
|
10 |
+
- custom
|
11 |
+
---
|
12 |
+
|
13 |
+
# EfficientNet Model for Vascular Dementia Detection
|
14 |
+
|
15 |
+
This model was trained to detect Vascular Dementia (VAD) from MRI scans. It uses an EfficientNet architecture fine-tuned on a custom dataset of brain MRI images.
|
16 |
+
|
17 |
+
## Model Description
|
18 |
+
|
19 |
+
- **Model Type:** EfficientNet
|
20 |
+
- **Task:** Binary classification (VAD-Demented vs. Non-Demented)
|
21 |
+
- **Input:** MRI brain scans (224x224 RGB)
|
22 |
+
- **Output:** Binary classification with confidence score
|
23 |
+
|
24 |
+
## Usage
|
25 |
+
|
26 |
+
```python
|
27 |
+
import tensorflow as tf
|
28 |
+
import numpy as np
|
29 |
+
from PIL import Image
|
30 |
+
|
31 |
+
# Load the model
|
32 |
+
model = tf.keras.models.load_model("path/to/downloaded/model")
|
33 |
+
|
34 |
+
# Preprocess your image
|
35 |
+
image = Image.open("path/to/your/mri.jpg")
|
36 |
+
image = image.resize((224, 224))
|
37 |
+
image_array = np.array(image) / 255.0
|
38 |
+
image_array = np.expand_dims(image_array, axis=0)
|
39 |
+
|
40 |
+
# Get prediction
|
41 |
+
prediction = model.predict(image_array)
|
42 |
+
predicted_class = "VAD-Demented" if prediction[0][0] > 0.5 else "Non-Demented"
|
43 |
+
confidence = prediction[0][0] * 100 if prediction[0][0] > 0.5 else (1 - prediction[0][0]) * 100
|
44 |
+
|
45 |
+
print(f"Prediction: {predicted_class}")
|
46 |
+
print(f"Confidence: {confidence:.2f}%")
|
47 |
+
```
|
48 |
+
|
49 |
+
## API Usage
|
50 |
+
|
51 |
+
This model can be used directly with the Hugging Face Inference API:
|
52 |
+
|
53 |
+
```python
|
54 |
+
import requests
|
55 |
+
import base64
|
56 |
+
from PIL import Image
|
57 |
+
import io
|
58 |
+
|
59 |
+
# Convert image to base64
|
60 |
+
image = Image.open("path/to/your/mri.jpg")
|
61 |
+
buffered = io.BytesIO()
|
62 |
+
image.save(buffered, format="JPEG")
|
63 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
64 |
+
|
65 |
+
# API endpoint
|
66 |
+
API_URL = "https://api-inference.huggingface.co/models/thakshana02/vad-efficientnet-model"
|
67 |
+
|
68 |
+
# API headers with your token
|
69 |
+
headers = {"Authorization": "Bearer YOUR_TOKEN"}
|
70 |
+
|
71 |
+
# Make prediction request
|
72 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": {"image": img_str}})
|
73 |
+
result = response.json()
|
74 |
+
print(result)
|
75 |
+
```
|
76 |
+
|
77 |
+
## Limitations
|
78 |
+
|
79 |
+
This model is intended for research purposes only and should not be used for clinical diagnosis without proper validation by healthcare professionals.
|
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
import base64
|
6 |
+
import json
|
7 |
+
|
8 |
+
class MRIClassifier:
|
9 |
+
def __init__(self):
|
10 |
+
# Load the model
|
11 |
+
self.model = tf.keras.models.load_model("./model")
|
12 |
+
self.img_size = (224, 224) # EfficientNet standard size
|
13 |
+
print(f"Model loaded with input size: {self.img_size}")
|
14 |
+
|
15 |
+
def preprocess(self, image):
|
16 |
+
# Resize image to expected input shape
|
17 |
+
image = image.resize(self.img_size)
|
18 |
+
|
19 |
+
# Convert to RGB if not already
|
20 |
+
if image.mode != "RGB":
|
21 |
+
image = image.convert("RGB")
|
22 |
+
|
23 |
+
# Convert to array and normalize
|
24 |
+
image_array = np.array(image) / 255.0
|
25 |
+
|
26 |
+
# Add batch dimension
|
27 |
+
image_array = np.expand_dims(image_array, axis=0)
|
28 |
+
|
29 |
+
return image_array
|
30 |
+
|
31 |
+
def predict(self, image_bytes):
|
32 |
+
# Convert bytes to image
|
33 |
+
image = Image.open(io.BytesIO(image_bytes))
|
34 |
+
|
35 |
+
# Preprocess image
|
36 |
+
image_array = self.preprocess(image)
|
37 |
+
|
38 |
+
# Make prediction
|
39 |
+
prediction = self.model.predict(image_array)
|
40 |
+
pred_value = float(prediction[0][0])
|
41 |
+
|
42 |
+
# Format result
|
43 |
+
predicted_class = "VAD-Demented" if pred_value > 0.5 else "Non-Demented"
|
44 |
+
|
45 |
+
return [
|
46 |
+
{
|
47 |
+
"label": predicted_class,
|
48 |
+
"score": pred_value
|
49 |
+
}
|
50 |
+
]
|
51 |
+
|
52 |
+
# Initialize classifier
|
53 |
+
classifier = MRIClassifier()
|
54 |
+
|
55 |
+
def inference(model_inputs):
|
56 |
+
# Handle both direct image inputs and base64 encoded images
|
57 |
+
if isinstance(model_inputs, dict) and "image" in model_inputs:
|
58 |
+
# Base64 encoded image
|
59 |
+
image_bytes = base64.b64decode(model_inputs["image"])
|
60 |
+
else:
|
61 |
+
# Direct image bytes (from API)
|
62 |
+
image_bytes = model_inputs
|
63 |
+
|
64 |
+
results = classifier.predict(image_bytes)
|
65 |
+
return results
|
best_model_efficientnet_vad2.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9ff88252154c2d64ddfc42bf4bfa20a142ec8f2f26a385dfd1afd4c0fea0944d
|
3 |
+
size 36286472
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f789cb5ad86c4b708307dfd270a317c8586d186b1eab05e04abc9d934a76ee31
|
3 |
+
size 17522648
|
model/fingerprint.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:609519a3390dd5c72fcf5babaea7d589755aea9d77ac6c3151334f51dccc0c19
|
3 |
+
size 55
|
model/keras_metadata.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1f027ee845a0d0b9be32a779ccedc9b86b11bde0b48c73991b2de3e7e6879280
|
3 |
+
size 524632
|
model/saved_model.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b3ca74fb08fbffe0b615e47393732cc2928b5f835127c84ad7f72cff2f7d671d
|
3 |
+
size 3865326
|
model/variables/variables.data-00000-of-00001
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a6c9676b6b5de2cba69357b13569f77d88eede30da8e161ef6e95c8f44bb2e74
|
3 |
+
size 17045849
|
model/variables/variables.index
ADDED
Binary file (20.3 kB). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow>=2.4.0
|
2 |
+
pillow
|
3 |
+
numpy
|