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