Siraja704 commited on
Commit
602b58b
·
verified ·
1 Parent(s): b8b24f2

Update README with comprehensive usage instructions and Flask API examples

Browse files
Files changed (1) hide show
  1. README.md +311 -19
README.md CHANGED
@@ -7,48 +7,340 @@ tags:
7
  - medical
8
  - dermatology
9
  - image-classification
 
 
 
10
  library_name: keras
 
11
  ---
12
 
13
- # DermaAI
14
 
15
- ## Model Description
16
 
17
- DermaAI - Dermatology AI Model
18
 
19
- This is a Keras model for dermatology AI applications, designed to assist in skin condition analysis.
20
 
21
- ## Model Details
 
 
 
 
22
 
23
- - **Model Type**: Keras/TensorFlow model
24
- - **Task**: Image Classification
 
 
25
  - **Domain**: Medical/Dermatology
26
  - **Framework**: TensorFlow/Keras
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- ## Usage
 
 
 
 
 
 
29
 
30
  ```python
 
 
31
  import tensorflow as tf
 
 
 
 
 
32
  from huggingface_hub import hf_hub_download
33
 
34
- # Download the model
35
- model_path = hf_hub_download(repo_id="your-username/dermaai", filename="DermaAI.keras")
36
 
37
- # Load the model
 
 
38
  model = tf.keras.models.load_model(model_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
- # Use the model for predictions
41
- # predictions = model.predict(your_image_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ```
43
 
44
- ## Training Data
 
 
 
 
 
 
 
 
45
 
46
- Please provide information about the training data used for this model.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- ## Limitations and Bias
49
 
50
- This model is intended for research and educational purposes. It should not be used as a substitute for professional medical diagnosis.
51
 
52
- ## Citation
53
 
54
- If you use this model, please cite appropriately.
 
 
 
7
  - medical
8
  - dermatology
9
  - image-classification
10
+ - skin-disease
11
+ - efficientnet
12
+ - healthcare
13
  library_name: keras
14
+ pipeline_tag: image-classification
15
  ---
16
 
17
+ # DermaAI - Skin Disease Classification Model
18
 
19
+ A deep learning model for classifying skin diseases using computer vision. This model can identify 5 different skin conditions with confidence scores and medical recommendations.
20
 
21
+ ## 🏥 Supported Skin Conditions
22
 
23
+ The model can classify the following skin diseases:
24
 
25
+ 1. **Atopic Dermatitis** - A chronic inflammatory skin condition
26
+ 2. **Eczema** - Inflammatory skin condition causing red, itchy patches
27
+ 3. **Psoriasis** - Autoimmune condition causing scaly skin patches
28
+ 4. **Seborrheic Keratoses** - Common benign skin growths
29
+ 5. **Tinea Ringworm Candidiasis** - Fungal skin infections
30
 
31
+ ## 🔧 Model Details
32
+
33
+ - **Model Type**: Keras/TensorFlow model based on EfficientNetV2
34
+ - **Task**: Image Classification (Multi-class)
35
  - **Domain**: Medical/Dermatology
36
  - **Framework**: TensorFlow/Keras
37
+ - **Input Size**: 224x224x3 (RGB images)
38
+ - **Output**: 5-class probability distribution
39
+ - **Preprocessing**: EfficientNetV2 preprocessing
40
+
41
+ ## 🚀 Quick Start
42
+
43
+ ### Basic Usage
44
+
45
+ ```python
46
+ import tensorflow as tf
47
+ from huggingface_hub import hf_hub_download
48
+ import numpy as np
49
+ from PIL import Image
50
+ from tensorflow.keras.applications.efficientnet_v2 import preprocess_input
51
+
52
+ # Download and load the model
53
+ model_path = hf_hub_download(repo_id="Siraja704/DermaAI", filename="DermaAI.keras")
54
+ model = tf.keras.models.load_model(model_path)
55
+
56
+ # Class names
57
+ class_names = [
58
+ 'Atopic Dermatitis',
59
+ 'Eczema',
60
+ 'Psoriasis',
61
+ 'Seborrheic Keratoses',
62
+ 'Tinea Ringworm Candidiasis'
63
+ ]
64
+
65
+ # Prediction function
66
+ def predict_skin_condition(image_path):
67
+ # Load and preprocess image
68
+ image = Image.open(image_path).convert('RGB')
69
+ image = image.resize((224, 224))
70
+ image_array = np.array(image)
71
+ image_array = preprocess_input(image_array)
72
+ image_array = np.expand_dims(image_array, axis=0)
73
+
74
+ # Make prediction
75
+ predictions = model.predict(image_array)
76
+ predicted_class_index = np.argmax(predictions[0])
77
+ predicted_class = class_names[predicted_class_index]
78
+ confidence = predictions[0][predicted_class_index] * 100
79
+
80
+ return predicted_class, confidence
81
+
82
+ # Example usage
83
+ prediction, confidence = predict_skin_condition("path/to/your/image.jpg")
84
+ print(f"Prediction: {prediction} ({confidence:.2f}% confidence)")
85
+ ```
86
+
87
+ ## 🌐 Flask API Usage
88
+
89
+ Create a complete web API for skin disease classification:
90
 
91
+ ### 1. Install Dependencies
92
+
93
+ ```bash
94
+ pip install flask numpy tensorflow pillow flask-cors huggingface-hub
95
+ ```
96
+
97
+ ### 2. Create Flask Application (`app.py`)
98
 
99
  ```python
100
+ from flask import Flask, request, jsonify
101
+ import numpy as np
102
  import tensorflow as tf
103
+ import base64
104
+ import io
105
+ from PIL import Image
106
+ from flask_cors import CORS
107
+ from tensorflow.keras.applications.efficientnet_v2 import preprocess_input
108
  from huggingface_hub import hf_hub_download
109
 
110
+ app = Flask(__name__)
111
+ CORS(app)
112
 
113
+ # Download and load the model from Hugging Face
114
+ print("Downloading model from Hugging Face...")
115
+ model_path = hf_hub_download(repo_id="Siraja704/DermaAI", filename="DermaAI.keras")
116
  model = tf.keras.models.load_model(model_path)
117
+ print("✅ Model loaded successfully!")
118
+
119
+ # Class names
120
+ class_names = [
121
+ 'Atopic Dermatitis',
122
+ 'Eczema',
123
+ 'Psoriasis',
124
+ 'Seborrheic Keratoses',
125
+ 'Tinea Ringworm Candidiasis'
126
+ ]
127
+
128
+ @app.route('/predict', methods=['POST'])
129
+ def predict():
130
+ try:
131
+ data = request.json
132
+ if not data or 'image' not in data:
133
+ return jsonify({'error': 'No image data provided'}), 400
134
+
135
+ # Process base64 image
136
+ image_data = data['image']
137
+ if 'base64,' in image_data:
138
+ image_data = image_data.split('base64,')[1]
139
+
140
+ # Decode and preprocess image
141
+ decoded_image = base64.b64decode(image_data)
142
+ image = Image.open(io.BytesIO(decoded_image)).convert('RGB')
143
+ image = image.resize((224, 224))
144
+ image_array = np.array(image)
145
+ image_array = preprocess_input(image_array)
146
+ image_array = np.expand_dims(image_array, axis=0)
147
+
148
+ # Make prediction
149
+ predictions = model.predict(image_array)
150
+ predicted_class_index = int(np.argmax(predictions[0]))
151
+ predicted_class = class_names[predicted_class_index]
152
+ confidence = float(predictions[0][predicted_class_index] * 100)
153
+
154
+ # Get top alternatives
155
+ top_indices = np.argsort(predictions[0])[-3:][::-1]
156
+ top_predictions = [
157
+ {
158
+ 'class': class_names[i],
159
+ 'confidence': float(predictions[0][i] * 100)
160
+ }
161
+ for i in top_indices if i != predicted_class_index
162
+ ]
163
+
164
+ # Generate medical recommendation
165
+ if confidence < 10:
166
+ recommendation = "Very low confidence. Please retake image with better lighting and focus."
167
+ elif confidence < 30:
168
+ recommendation = "Low confidence. Preliminary result only. Consult a dermatologist."
169
+ elif confidence < 60:
170
+ recommendation = "Moderate confidence. Consider alternatives and consult healthcare professional."
171
+ else:
172
+ recommendation = "High confidence prediction. Always consult healthcare professional for confirmation."
173
 
174
+ return jsonify({
175
+ 'prediction': predicted_class,
176
+ 'confidence': round(confidence, 2),
177
+ 'all_confidences': {
178
+ class_names[i]: float(pred * 100) for i, pred in enumerate(predictions[0])
179
+ },
180
+ 'top_alternatives': top_predictions,
181
+ 'recommendation': recommendation
182
+ })
183
+
184
+ except Exception as e:
185
+ return jsonify({'error': str(e)}), 500
186
+
187
+ @app.route('/health', methods=['GET'])
188
+ def health():
189
+ return jsonify({'status': 'healthy', 'model_loaded': True})
190
+
191
+ if __name__ == '__main__':
192
+ app.run(host='0.0.0.0', port=5001, debug=True)
193
  ```
194
 
195
+ ### 3. Run the API
196
+
197
+ ```bash
198
+ python app.py
199
+ ```
200
+
201
+ The API will be available at `http://localhost:5001`
202
+
203
+ ### 4. API Usage Examples
204
 
205
+ **Python Client:**
206
+ ```python
207
+ import requests
208
+ import base64
209
+
210
+ def predict_image(image_path, api_url="http://localhost:5001/predict"):
211
+ with open(image_path, "rb") as image_file:
212
+ encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
213
+
214
+ data = {"image": f"data:image/jpeg;base64,{encoded_string}"}
215
+ response = requests.post(api_url, json=data)
216
+ return response.json()
217
+
218
+ # Usage
219
+ result = predict_image("skin_image.jpg")
220
+ print(f"Prediction: {result['prediction']} ({result['confidence']}%)")
221
+ ```
222
+
223
+ **JavaScript Client:**
224
+ ```javascript
225
+ async function predictSkinCondition(imageFile) {
226
+ const base64 = await new Promise((resolve) => {
227
+ const reader = new FileReader();
228
+ reader.onload = () => resolve(reader.result);
229
+ reader.readAsDataURL(imageFile);
230
+ });
231
+
232
+ const response = await fetch('http://localhost:5001/predict', {
233
+ method: 'POST',
234
+ headers: {'Content-Type': 'application/json'},
235
+ body: JSON.stringify({image: base64})
236
+ });
237
+
238
+ return await response.json();
239
+ }
240
+ ```
241
+
242
+ **cURL:**
243
+ ```bash
244
+ curl -X POST http://localhost:5001/predict \
245
+ -H "Content-Type: application/json" \
246
+ -d '{"image": "data:image/jpeg;base64,YOUR_BASE64_IMAGE_HERE"}'
247
+ ```
248
+
249
+ ## 📋 API Response Format
250
+
251
+ ```json
252
+ {
253
+ "prediction": "Eczema",
254
+ "confidence": 85.23,
255
+ "all_confidences": {
256
+ "Atopic Dermatitis": 12.45,
257
+ "Eczema": 85.23,
258
+ "Psoriasis": 1.32,
259
+ "Seborrheic Keratoses": 0.67,
260
+ "Tinea Ringworm Candidiasis": 0.33
261
+ },
262
+ "top_alternatives": [
263
+ {
264
+ "class": "Atopic Dermatitis",
265
+ "confidence": 12.45
266
+ }
267
+ ],
268
+ "recommendation": "High confidence prediction. Always consult healthcare professional for confirmation."
269
+ }
270
+ ```
271
+
272
+ ## 🖼️ Image Requirements
273
+
274
+ - **Formats**: JPG, PNG, WebP, and other common formats
275
+ - **Size**: Automatically resized to 224x224 pixels
276
+ - **Quality**: High-resolution images with good lighting work best
277
+ - **Focus**: Ensure affected skin area is clearly visible
278
+
279
+ ## 🐳 Docker Deployment
280
+
281
+ **Dockerfile:**
282
+ ```dockerfile
283
+ FROM python:3.9-slim
284
+
285
+ WORKDIR /app
286
+ COPY requirements.txt .
287
+ RUN pip install -r requirements.txt
288
+ COPY app.py .
289
+ EXPOSE 5001
290
+ CMD ["python", "app.py"]
291
+ ```
292
+
293
+ **Requirements.txt:**
294
+ ```txt
295
+ flask>=2.0.0
296
+ numpy>=1.21.0
297
+ tensorflow>=2.13.0
298
+ pillow>=9.0.0
299
+ flask-cors>=3.0.0
300
+ huggingface-hub>=0.20.0
301
+ ```
302
+
303
+ **Build and Run:**
304
+ ```bash
305
+ docker build -t dermaai-api .
306
+ docker run -p 5001:5001 dermaai-api
307
+ ```
308
+
309
+ ## ⚕️ Important Medical Disclaimer
310
+
311
+ **This model is for educational and research purposes only. It should NOT be used as a substitute for professional medical diagnosis or treatment. Always consult qualified healthcare professionals for proper medical evaluation and treatment of skin conditions.**
312
+
313
+ ## 📊 Performance Notes
314
+
315
+ - **Input**: 224x224 RGB images
316
+ - **Preprocessing**: EfficientNetV2 normalization
317
+ - **Architecture**: Based on EfficientNetV2
318
+ - **Classes**: 5 skin disease categories
319
+ - **Confidence Levels**:
320
+ - Low: < 30% (requires professional consultation)
321
+ - Moderate: 30-60% (consider alternatives)
322
+ - High: > 60% (still requires medical confirmation)
323
+
324
+ ## 🤝 Citation
325
+
326
+ If you use this model in your research or applications, please cite appropriately:
327
+
328
+ ```bibtex
329
+ @misc{dermaai2024,
330
+ title={DermaAI: Deep Learning Model for Skin Disease Classification},
331
+ author={Siraja704},
332
+ year={2024},
333
+ publisher={Hugging Face},
334
+ url={https://huggingface.co/Siraja704/DermaAI}
335
+ }
336
+ ```
337
 
338
+ ## 📝 License
339
 
340
+ Licensed under the Apache 2.0 License. See the LICENSE file for details.
341
 
342
+ ## 🔗 Links
343
 
344
+ - **Model Repository**: [Siraja704/DermaAI](https://huggingface.co/Siraja704/DermaAI)
345
+ - **Framework**: [TensorFlow](https://tensorflow.org)
346
+ - **Base Architecture**: [EfficientNetV2](https://arxiv.org/abs/2104.00298)