Update README.md
Browse files
README.md
CHANGED
|
@@ -6,17 +6,140 @@ tags:
|
|
| 6 |
- transformers
|
| 7 |
- unsloth
|
| 8 |
- gemma3n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
license: cc-by-4.0
|
|
|
|
|
|
|
| 10 |
language:
|
| 11 |
- en
|
| 12 |
---
|
| 13 |
|
| 14 |
-
# Uploaded finetuned model
|
| 15 |
|
| 16 |
-
- **Developed by:** yasserrmd
|
| 17 |
-
- **License:** apache-2.0
|
| 18 |
-
- **Finetuned from model :** unsloth/gemma-3n-e2b-it-unsloth-bnb-4bit
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
| 6 |
- transformers
|
| 7 |
- unsloth
|
| 8 |
- gemma3n
|
| 9 |
+
- medical
|
| 10 |
+
- vision-language
|
| 11 |
+
- gemma
|
| 12 |
+
- ecg
|
| 13 |
+
- cardiology
|
| 14 |
+
- healthcare
|
| 15 |
license: cc-by-4.0
|
| 16 |
+
datasets:
|
| 17 |
+
- yasserrmd/pulse-ecg-instruct-subset
|
| 18 |
language:
|
| 19 |
- en
|
| 20 |
---
|
| 21 |
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# yasserrmd/GemmaECG-Vision
|
| 25 |
+
|
| 26 |
+
`GemmaECG-Vision` is a fine-tuned vision-language model built on `google/gemma-3n-e2b`, designed for ECG image interpretation tasks. The model accepts a medical ECG image along with a clinical instruction prompt and generates a structured analysis suitable for triage or documentation use cases.
|
| 27 |
+
|
| 28 |
+
This model was developed using **Unsloth** for efficient fine-tuning and supports **image + text** inputs with medical task-specific prompt formatting. It is designed to run in **offline or edge environments**, enabling healthcare triage in resource-constrained settings.
|
| 29 |
+
|
| 30 |
+
## Model Objective
|
| 31 |
+
|
| 32 |
+
To assist healthcare professionals and emergency responders by providing AI-generated ECG analysis directly from medical images, without requiring internet access or cloud resources.
|
| 33 |
+
|
| 34 |
+
## Usage
|
| 35 |
+
|
| 36 |
+
This model expects:
|
| 37 |
+
- An ECG image (`PIL.Image`)
|
| 38 |
+
- A textual instruction such as:
|
| 39 |
+
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
You are a clinical assistant specialized in ECG interpretation. Given an ECG image, generate a concise, structured, and medically accurate report.
|
| 43 |
+
|
| 44 |
+
Use this exact format:
|
| 45 |
+
|
| 46 |
+
Rhythm:
|
| 47 |
+
PR Interval:
|
| 48 |
+
QRS Duration:
|
| 49 |
+
Axis:
|
| 50 |
+
Bundle Branch Blocks:
|
| 51 |
+
Atrial Abnormalities:
|
| 52 |
+
Ventricular Hypertrophy:
|
| 53 |
+
Q Wave or QS Complexes:
|
| 54 |
+
T Wave Abnormalities:
|
| 55 |
+
ST Segment Changes:
|
| 56 |
+
Final Impression:
|
| 57 |
+
|
| 58 |
+
````
|
| 59 |
+
|
| 60 |
+
### Inference Example (Python)
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
from transformers import AutoProcessor, Gemma3nForConditionalGeneration
|
| 64 |
+
from PIL import Image
|
| 65 |
+
import torch
|
| 66 |
+
|
| 67 |
+
model_id = "yasserrmd/GemmaECG-Vision"
|
| 68 |
+
model = Gemma3nForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16).eval().to("cuda")
|
| 69 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 70 |
+
|
| 71 |
+
image = Image.open("example_ecg.png").convert("RGB")
|
| 72 |
+
|
| 73 |
+
messages = [
|
| 74 |
+
{
|
| 75 |
+
"role": "user",
|
| 76 |
+
"content": [
|
| 77 |
+
{"type": "image"},
|
| 78 |
+
{"type": "text", "text": "Interpret this ECG and provide a structured triage report."}
|
| 79 |
+
]
|
| 80 |
+
}
|
| 81 |
+
]
|
| 82 |
+
|
| 83 |
+
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
|
| 84 |
+
|
| 85 |
+
inputs = processor(image, prompt, return_tensors="pt").to("cuda")
|
| 86 |
+
|
| 87 |
+
outputs = model.generate(
|
| 88 |
+
**inputs,
|
| 89 |
+
max_new_tokens=256,
|
| 90 |
+
temperature=1.0,
|
| 91 |
+
top_p=0.95,
|
| 92 |
+
top_k=64,
|
| 93 |
+
use_cache=True
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
result = processor.decode(outputs[0], skip_special_tokens=True)
|
| 97 |
+
print(result)
|
| 98 |
+
````
|
| 99 |
+
|
| 100 |
+
## Training Details
|
| 101 |
+
|
| 102 |
+
* **Framework**: Unsloth + TRL SFTTrainer
|
| 103 |
+
* **Hardware**: Google Colab Pro (L4)
|
| 104 |
+
* **Batch Size**: 2
|
| 105 |
+
* **Epochs**: 1
|
| 106 |
+
* **Learning Rate**: 2e-4
|
| 107 |
+
* **Scheduler**: Cosine
|
| 108 |
+
* **Loss**: CrossEntropy
|
| 109 |
+
* **Precision**: bfloat16
|
| 110 |
+
|
| 111 |
+
## Dataset
|
| 112 |
+
|
| 113 |
+
The training dataset is a curated subset of the [PULSE-ECG/ECGInstruct](https://huggingface.co/datasets/PULSE-ECG/ECGInstruct) dataset, reformatted for VLM instruction tuning.
|
| 114 |
+
|
| 115 |
+
* 3,272 samples of ECG image + structured instruction + clinical output
|
| 116 |
+
* Focused on realistic and medically relevant triage cases
|
| 117 |
+
|
| 118 |
+
Dataset link: [`yasserrmd/pulse-ecg-instruct-subset`](https://huggingface.co/datasets/yasserrmd/pulse-ecg-instruct-subset)
|
| 119 |
+
|
| 120 |
+
## Intended Use
|
| 121 |
+
|
| 122 |
+
* Emergency triage in offline settings
|
| 123 |
+
* On-device ECG assessment
|
| 124 |
+
* Integration with medical edge devices (Jetson, Pi, Android)
|
| 125 |
+
* Rapid analysis during disaster response
|
| 126 |
+
|
| 127 |
+
## Limitations
|
| 128 |
+
|
| 129 |
+
* Not intended to replace licensed medical professionals
|
| 130 |
+
* Accuracy may vary depending on image quality
|
| 131 |
+
* Model outputs should be reviewed by a clinician before action
|
| 132 |
+
|
| 133 |
+
## License
|
| 134 |
+
|
| 135 |
+
This model is licensed under **CC BY 4.0**. You are free to use, modify, and distribute it with attribution.
|
| 136 |
+
|
| 137 |
+
## Author
|
| 138 |
+
|
| 139 |
+
Mohamed Yasser
|
| 140 |
+
[Hugging Face Profile](https://huggingface.co/yasserrmd)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
|
| 144 |
|
| 145 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|