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
|
@@ -1,22 +1,25 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
| 2 |
license: mit
|
| 3 |
-
|
| 4 |
tags:
|
| 5 |
- medical
|
| 6 |
- mri
|
| 7 |
- brain-tumor-detection
|
| 8 |
- computer-vision
|
| 9 |
-
- image-classification
|
| 10 |
- tensorflow
|
| 11 |
-
- keras
|
| 12 |
pipeline_tag: image-classification
|
| 13 |
-
|
| 14 |
---
|
| 15 |
|
| 16 |
# 🧠 Brain Tumor MRI Classification Model (Fine-Tuned EfficientNetB0)
|
| 17 |
|
| 18 |
This model is a fine-tuned version of **EfficientNetB0** trained to classify Brain Tumor types from MRI images into 4 distinct classes.
|
| 19 |
|
|
|
|
|
|
|
| 20 |
## 📋 Model Overview
|
| 21 |
|
| 22 |
- **Base Architecture:** EfficientNetB0 (Pre-trained on ImageNet)
|
|
@@ -24,6 +27,8 @@ This model is a fine-tuned version of **EfficientNetB0** trained to classify Bra
|
|
| 24 |
- **Input Image Size:** 224 x 224 x 3
|
| 25 |
- **Framework:** TensorFlow 2.x / Keras
|
| 26 |
|
|
|
|
|
|
|
| 27 |
## 🏷️ Target Classes
|
| 28 |
|
| 29 |
1. **Glioma Tumor**
|
|
@@ -31,6 +36,62 @@ This model is a fine-tuned version of **EfficientNetB0** trained to classify Bra
|
|
| 31 |
3. **No Tumor**
|
| 32 |
4. **Pituitary Tumor**
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
## ⚙️ Training Details & Hyperparameters
|
| 35 |
|
| 36 |
- **Optimizer:** Adam (Learning Rate = `1e-4`)
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- th
|
| 5 |
license: mit
|
| 6 |
+
library_name: keras
|
| 7 |
tags:
|
| 8 |
- medical
|
| 9 |
- mri
|
| 10 |
- brain-tumor-detection
|
| 11 |
- computer-vision
|
|
|
|
| 12 |
- tensorflow
|
|
|
|
| 13 |
pipeline_tag: image-classification
|
| 14 |
+
base_model: google/efficientnet-b0
|
| 15 |
---
|
| 16 |
|
| 17 |
# 🧠 Brain Tumor MRI Classification Model (Fine-Tuned EfficientNetB0)
|
| 18 |
|
| 19 |
This model is a fine-tuned version of **EfficientNetB0** trained to classify Brain Tumor types from MRI images into 4 distinct classes.
|
| 20 |
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
## 📋 Model Overview
|
| 24 |
|
| 25 |
- **Base Architecture:** EfficientNetB0 (Pre-trained on ImageNet)
|
|
|
|
| 27 |
- **Input Image Size:** 224 x 224 x 3
|
| 28 |
- **Framework:** TensorFlow 2.x / Keras
|
| 29 |
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
## 🏷️ Target Classes
|
| 33 |
|
| 34 |
1. **Glioma Tumor**
|
|
|
|
| 36 |
3. **No Tumor**
|
| 37 |
4. **Pituitary Tumor**
|
| 38 |
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+
## 🇹🇭 คู่มือการใช้งานและการติดตั้ง (Thai Guide)
|
| 42 |
+
|
| 43 |
+
### 🛠️ 1. การติดตั้งไลบรารีที่จำเป็น (Installation)
|
| 44 |
+
ก่อนเริ่มใช้งาน คุณจำเป็นต้องติดตั้งไลบรารีพื้นฐานด้วยคำสั่งนี้ใน Terminal หรือ Command Prompt:
|
| 45 |
+
|
| 46 |
+
```bash
|
| 47 |
+
pip install tensorflow pillow requests numpy
|
| 48 |
+
|
| 49 |
+
🚀 2. โค้ดตัวอย่างการโหลดโมเดลและพยากรณ์รูปภาพ (Usage Example)
|
| 50 |
+
import numpy as np
|
| 51 |
+
import tensorflow as tf
|
| 52 |
+
from PIL import Image
|
| 53 |
+
from tensorflow.keras.applications import EfficientNetB0
|
| 54 |
+
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout, BatchNormalization
|
| 55 |
+
from tensorflow.keras.models import Model
|
| 56 |
+
from huggingface_hub import hf_hub_download
|
| 57 |
+
|
| 58 |
+
# 1. นิยามโครงสร้างโมเดล (Model Architecture)
|
| 59 |
+
base_model = EfficientNetB0(weights=None, include_top=False, input_shape=(224, 224, 3))
|
| 60 |
+
x = base_model.output
|
| 61 |
+
x = GlobalAveragePooling2D()(x)
|
| 62 |
+
x = BatchNormalization()(x)
|
| 63 |
+
x = Dense(256, activation='relu')(x)
|
| 64 |
+
x = Dropout(0.4)(x)
|
| 65 |
+
outputs = Dense(4, activation='softmax')(x)
|
| 66 |
+
|
| 67 |
+
model = Model(inputs=base_model.input, outputs=outputs)
|
| 68 |
+
|
| 69 |
+
# 2. ดาวน์โหลดและโหลดน้ำหนักโมเดลจาก Hugging Face
|
| 70 |
+
model_path = hf_hub_download(repo_id="starpreeda/BrainTumorTest", filename="efficientnetb0_finetuned_brain_mri.keras")
|
| 71 |
+
model.load_weights(model_path)
|
| 72 |
+
|
| 73 |
+
# 3. กำหนดรายชื่อคลาส
|
| 74 |
+
class_names = ['Glioma', 'Meningioma', 'No Tumor', 'Pituitary']
|
| 75 |
+
|
| 76 |
+
# 4. ฟังก์ชันสำหรับเตรียมรูปภาพและพยากรณ์ผล
|
| 77 |
+
def predict_mri(image_path):
|
| 78 |
+
img = Image.open(image_path).convert('RGB')
|
| 79 |
+
img = img.resize((224, 224))
|
| 80 |
+
img_array = np.array(img, dtype=np.float32)
|
| 81 |
+
img_array = np.expand_dims(img_array, axis=0) # เพิ่ม Batch Dimension
|
| 82 |
+
|
| 83 |
+
predictions = model.predict(img_array)
|
| 84 |
+
predicted_class = class_names[np.argmax(predictions[0])]
|
| 85 |
+
confidence = np.max(predictions[0]) * 100
|
| 86 |
+
|
| 87 |
+
return predicted_class, confidence
|
| 88 |
+
|
| 89 |
+
# ตัวอย่างการเรียกใช้งาน:
|
| 90 |
+
# class_label, conf = predict_mri("path/to/your/mri_scan.jpg")
|
| 91 |
+
# print(f"ผลการทำนาย: {class_label} ({conf:.2f}%)")
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
## ⚙️ Training Details & Hyperparameters
|
| 96 |
|
| 97 |
- **Optimizer:** Adam (Learning Rate = `1e-4`)
|