starpreeda commited on
Commit
61b1ddc
·
verified ·
1 Parent(s): c3ef54d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +13 -5
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
- model_path = hf_hub_download(repo_id="starpreeda/BrainTumorTest", filename="efficientnetb0_finetuned_brain_mri.keras")
63
- model.load_weights(model_path)
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"ผลการทำนาย: {class_label} ({conf:.2f}%)")
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