ezAhmed commited on
Commit
5852205
·
verified ·
1 Parent(s): 4a7faac

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. README.md +112 -0
  3. config.json +28 -0
  4. inference_example.py +53 -0
  5. model.keras +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,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - vision
5
+ - medical
6
+ - gerd
7
+ - vision-transformer
8
+ - tensorflow
9
+ - image-classification
10
+ datasets:
11
+ - custom-gerd-dataset
12
+ metrics:
13
+ - accuracy
14
+ - precision
15
+ - recall
16
+ - f1
17
+ model-index:
18
+ - name: GERD Lightweight ViT
19
+ results:
20
+ - task:
21
+ type: image-classification
22
+ name: Image Classification
23
+ dataset:
24
+ name: GERD Augmented Dataset
25
+ type: custom
26
+ metrics:
27
+ - type: accuracy
28
+ value: 0.95
29
+ name: Accuracy
30
+ ---
31
+
32
+ # GERD Lightweight Vision Transformer 🔬
33
+
34
+ This is a lightweight Vision Transformer (ViT) model trained to classify gastroesophageal images into 4 categories:
35
+ - **Esophagitis**: Inflammation of the esophagus
36
+ - **GERD**: Gastroesophageal Reflux Disease
37
+ - **Normal**: Healthy esophagus
38
+ - **Ulcer**: Esophageal ulceration
39
+
40
+ ## Model Details
41
+
42
+ ### Architecture
43
+ - **Model Type**: Lightweight Vision Transformer (ViT)
44
+ - **Input Size**: 224x224x3 (RGB)
45
+ - **Patch Size**: 8x8
46
+ - **Projection Dimension**: 64
47
+ - **Transformer Layers**: 4
48
+ - **Attention Heads**: 4
49
+ - **MLP Head Units**: [128, 64]
50
+ - **Output Classes**: 4
51
+
52
+ ### Training
53
+ - Trained using 5-Fold Cross-Validation
54
+ - Optimizer: Adam (lr=1e-4)
55
+ - Loss: Categorical Crossentropy with Label Smoothing (0.1)
56
+ - Early Stopping with patience=20
57
+ - Data Augmentation applied
58
+
59
+ ### Performance
60
+ - High accuracy on GERD classification tasks
61
+ - Optimized for medical image analysis
62
+ - Efficient inference with reduced parameters
63
+
64
+ ## Intended Use
65
+
66
+ This model is designed for **research and educational purposes** in medical image analysis. It should **NOT** be used as the sole diagnostic tool in clinical settings.
67
+
68
+ ### Direct Use
69
+ ```python
70
+ import tensorflow as tf
71
+ from PIL import Image
72
+ import numpy as np
73
+
74
+ # Load model
75
+ model = tf.keras.models.load_model('model.keras')
76
+
77
+ # Prepare image
78
+ image = Image.open('your_image.jpg').resize((224, 224))
79
+ image_array = np.array(image) / 255.0
80
+ image_array = np.expand_dims(image_array, axis=0)
81
+
82
+ # Predict
83
+ predictions = model.predict(image_array)
84
+ class_names = ['Esophagitis', 'GERD', 'Normal', 'Ulcer']
85
+ predicted_class = class_names[np.argmax(predictions)]
86
+ confidence = np.max(predictions)
87
+
88
+ print(f"Predicted: {predicted_class} (Confidence: {confidence:.2%})")
89
+ ```
90
+
91
+ ## Limitations and Bias
92
+
93
+ ⚠️ **Important Disclaimers:**
94
+ - This model is trained on a specific dataset and may not generalize to all populations
95
+ - Medical imaging interpretation requires clinical expertise
96
+ - Always consult healthcare professionals for medical decisions
97
+ - The model may have biases based on the training data distribution
98
+
99
+ ## Training Data
100
+
101
+ The model was trained on an augmented GERD dataset containing gastroesophageal images across 4 categories.
102
+
103
+ ## Citation
104
+
105
+ If you use this model, please cite appropriately and acknowledge the original dataset sources.
106
+
107
+ ## Contact
108
+
109
+ For questions or issues, please open an issue in the model repository.
110
+
111
+ ---
112
+ *Developed for medical image classification research*
config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "vision-transformer",
3
+ "task": "image-classification",
4
+ "image_size": 224,
5
+ "patch_size": 8,
6
+ "projection_dim": 64,
7
+ "transformer_layers": 4,
8
+ "num_heads": 4,
9
+ "mlp_head_units": [
10
+ 128,
11
+ 64
12
+ ],
13
+ "num_classes": 4,
14
+ "class_names": [
15
+ "Esophagitis",
16
+ "GERD",
17
+ "Normal",
18
+ "Ulcer"
19
+ ],
20
+ "framework": "tensorflow",
21
+ "preprocessing": {
22
+ "resize": [
23
+ 224,
24
+ 224
25
+ ],
26
+ "normalize": "scale_0_1"
27
+ }
28
+ }
inference_example.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+ import requests
6
+ from io import BytesIO
7
+
8
+ # Load model
9
+ model = tf.keras.models.load_model('model.keras')
10
+
11
+ # Class names
12
+ CLASS_NAMES = ['Esophagitis', 'GERD', 'Normal', 'Ulcer']
13
+
14
+ def predict_from_url(image_url):
15
+ response = requests.get(image_url)
16
+ image = Image.open(BytesIO(response.content))
17
+ return predict_image(image)
18
+
19
+ def predict_from_path(image_path):
20
+ image = Image.open(image_path)
21
+ return predict_image(image)
22
+
23
+ def predict_image(image):
24
+ # Preprocess
25
+ image = image.convert('RGB')
26
+ image = image.resize((224, 224))
27
+ image_array = np.array(image) / 255.0
28
+ image_array = np.expand_dims(image_array, axis=0)
29
+
30
+ # Predict
31
+ predictions = model.predict(image_array)[0]
32
+
33
+ # Format results
34
+ results = {
35
+ CLASS_NAMES[i]: float(predictions[i])
36
+ for i in range(len(CLASS_NAMES))
37
+ }
38
+
39
+ predicted_class = CLASS_NAMES[np.argmax(predictions)]
40
+ confidence = float(np.max(predictions))
41
+
42
+ return {
43
+ 'predicted_class': predicted_class,
44
+ 'confidence': confidence,
45
+ 'all_predictions': results
46
+ }
47
+
48
+ # Example usage
49
+ if __name__ == "__main__":
50
+ result = predict_from_path('test_image.jpg')
51
+ print(f"Prediction: {result['predicted_class']}")
52
+ print(f"Confidence: {result['confidence']:.2%}")
53
+ print(f"All probabilities: {result['all_predictions']}")
model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4844c0a050a78acfd92126786d682a7f189b7ad1953ee77385f0fdbf5b2aec3b
3
+ size 938108