Instructions to use starpreeda/BrainTumorTest with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use starpreeda/BrainTumorTest with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://starpreeda/BrainTumorTest") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -41,14 +41,23 @@ This model is a fine-tuned version of **EfficientNetB0** trained to classify Bra
|
|
| 41 |
pip install tensorflow pillow requests numpy
|
| 42 |
```
|
| 43 |
```
|
|
|
|
|
|
|
| 44 |
import numpy as np
|
| 45 |
import tensorflow as tf
|
| 46 |
from PIL import Image
|
| 47 |
from tensorflow.keras.applications import EfficientNetB0
|
| 48 |
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout, BatchNormalization
|
| 49 |
from tensorflow.keras.models import Model
|
| 50 |
-
from huggingface_hub import hf_hub_download
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
base_model = EfficientNetB0(weights=None, include_top=False, input_shape=(224, 224, 3))
|
| 53 |
x = base_model.output
|
| 54 |
x = GlobalAveragePooling2D()(x)
|
|
@@ -59,9 +68,8 @@ outputs = Dense(4, activation='softmax')(x)
|
|
| 59 |
|
| 60 |
model = Model(inputs=base_model.input, outputs=outputs)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
class_names = ['Glioma', 'Meningioma', 'No Tumor', 'Pituitary']
|
| 66 |
|
| 67 |
def predict_mri(image_path):
|
|
@@ -77,7 +85,7 @@ def predict_mri(image_path):
|
|
| 77 |
return predicted_class, confidence
|
| 78 |
|
| 79 |
# class_label, conf = predict_mri("path/to/your/mri_scan.jpg")
|
| 80 |
-
# print(f"
|
| 81 |
```
|
| 82 |
```
|
| 83 |
## ⚙️ Training Details & Hyperparameters
|
|
|
|
| 41 |
pip install tensorflow pillow requests numpy
|
| 42 |
```
|
| 43 |
```
|
| 44 |
+
import os
|
| 45 |
+
import urllib.request
|
| 46 |
import numpy as np
|
| 47 |
import tensorflow as tf
|
| 48 |
from PIL import Image
|
| 49 |
from tensorflow.keras.applications import EfficientNetB0
|
| 50 |
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout, BatchNormalization
|
| 51 |
from tensorflow.keras.models import Model
|
|
|
|
| 52 |
|
| 53 |
+
|
| 54 |
+
model_url = "[https://huggingface.co/starpreeda/BrainTumorTest/resolve/main/efficientnetb0_finetuned_brain_mri.keras](https://huggingface.co/starpreeda/BrainTumorTest/resolve/main/efficientnetb0_finetuned_brain_mri.keras)"
|
| 55 |
+
weights_path = "model_weights.keras"
|
| 56 |
+
|
| 57 |
+
if not os.path.exists(weights_path):
|
| 58 |
+
print("Downloading model weights...")
|
| 59 |
+
urllib.request.urlretrieve(model_url, weights_path)
|
| 60 |
+
print("Download completed!")
|
| 61 |
base_model = EfficientNetB0(weights=None, include_top=False, input_shape=(224, 224, 3))
|
| 62 |
x = base_model.output
|
| 63 |
x = GlobalAveragePooling2D()(x)
|
|
|
|
| 68 |
|
| 69 |
model = Model(inputs=base_model.input, outputs=outputs)
|
| 70 |
|
| 71 |
+
model.load_weights(weights_path)
|
| 72 |
+
print("✅ Model is ready to use!")
|
|
|
|
| 73 |
class_names = ['Glioma', 'Meningioma', 'No Tumor', 'Pituitary']
|
| 74 |
|
| 75 |
def predict_mri(image_path):
|
|
|
|
| 85 |
return predicted_class, confidence
|
| 86 |
|
| 87 |
# class_label, conf = predict_mri("path/to/your/mri_scan.jpg")
|
| 88 |
+
# print(f"Result: {class_label} ({conf:.2f}%)")
|
| 89 |
```
|
| 90 |
```
|
| 91 |
## ⚙️ Training Details & Hyperparameters
|