efecelik commited on
Commit
6001c99
·
verified ·
1 Parent(s): 9d18df6

Add model card with training details and usage instructions

Browse files
Files changed (1) hide show
  1. README.md +169 -191
README.md CHANGED
@@ -1,199 +1,177 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
  ## Model Details
13
 
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
+ library_name: peft
3
+ license: other
4
+ license_name: health-ai-developer-foundations
5
+ license_link: https://developers.google.com/health-ai-developer-foundations/terms
6
+ base_model: google/medgemma-4b-it
7
+ tags:
8
+ - medgemma
9
+ - lora
10
+ - medical-ai
11
+ - abdominal-ct
12
+ - organ-classification
13
+ - hai-def
14
+ - medmnist
15
+ datasets:
16
+ - satwatbashir/organamnist
17
+ language:
18
+ - en
19
+ pipeline_tag: image-text-to-text
20
  ---
21
 
22
+ # MedGemma Abdominal CT LoRA
 
 
23
 
24
+ **Abdominal organ classification adapter fine-tuned on OrganAMNIST (MedMNIST) using MedGemma 4B.**
25
 
26
+ Identifies the primary organ or anatomical structure visible in abdominal CT axial slices across 11 classes.
27
 
28
  ## Model Details
29
 
30
+ | Property | Value |
31
+ |----------|-------|
32
+ | **Base Model** | [google/medgemma-4b-it](https://huggingface.co/google/medgemma-4b-it) |
33
+ | **Method** | LoRA (Low-Rank Adaptation) |
34
+ | **Task** | Multi-class organ classification (11 classes) |
35
+ | **Modality** | Abdominal CT (axial 2D slices) |
36
+ | **Framework** | PyTorch + HuggingFace Transformers + PEFT |
37
+
38
+ ## Training Dataset
39
+
40
+ **[OrganAMNIST](https://huggingface.co/datasets/satwatbashir/organamnist)** from the MedMNIST v2 benchmark — standardized 2D axial CT slices for organ classification.
41
+
42
+ Reference: Yang et al. 2023, *Scientific Data* - "MedMNIST v2: A Large-Scale Lightweight Benchmark for 2D and 3D Biomedical Image Classification"
43
+
44
+ - **Original dataset:** ~58,850 images
45
+ - **Train samples:** 10,000 (curated subset)
46
+ - **Validation samples:** 1,000
47
+ - **Image size:** 28x28 pixels (MedMNIST standard, resized by processor)
48
+
49
+ ### Class Distribution
50
+
51
+ | ID | Organ | Description |
52
+ |:---:|-------|-------------|
53
+ | 0 | Bladder | Urinary bladder in the pelvis |
54
+ | 1 | Femur (left) | Proximal left femur and femoral head |
55
+ | 2 | Femur (right) | Proximal right femur and femoral head |
56
+ | 3 | Heart | Cardiac silhouette with chambers and great vessels |
57
+ | 4 | Kidney (left) | Left kidney with cortex and medulla |
58
+ | 5 | Kidney (right) | Right kidney (slightly lower due to liver) |
59
+ | 6 | Liver | Largest solid abdominal organ, right upper quadrant |
60
+ | 7 | Lung (left) | Left hemithorax pulmonary tissue |
61
+ | 8 | Lung (right) | Right hemithorax, three lobes |
62
+ | 9 | Spleen | Left upper quadrant, posterior to stomach |
63
+ | 10 | Pancreas | Retroperitoneal organ crossing midline |
64
+
65
+ ## Training Configuration
66
+
67
+ ### LoRA Parameters
68
+
69
+ | Parameter | Value |
70
+ |-----------|-------|
71
+ | Rank (r) | 16 |
72
+ | Alpha | 32 |
73
+ | Dropout | 0.05 |
74
+ | Target Modules | all-linear |
75
+ | Task Type | CAUSAL_LM |
76
+ | Trainable Params | 1.38B / 5.68B (24.3%) |
77
+
78
+ ### Hyperparameters
79
+
80
+ | Parameter | Value |
81
+ |-----------|-------|
82
+ | Epochs | 1 |
83
+ | Per-device Batch Size | 1 |
84
+ | Gradient Accumulation Steps | 8 (effective batch = 8) |
85
+ | Learning Rate | 2e-4 |
86
+ | LR Scheduler | Linear with warmup |
87
+ | Warmup Ratio | 0.03 |
88
+ | Max Grad Norm | 0.3 |
89
+ | Precision | bfloat16 |
90
+ | Gradient Checkpointing | Enabled |
91
+ | Seed | 42 |
92
+
93
+ ### Infrastructure
94
+
95
+ | Property | Value |
96
+ |----------|-------|
97
+ | GPU | NVIDIA L4 (24 GB VRAM) |
98
+ | Cloud Platform | [Modal](https://modal.com) serverless GPU |
99
+ | Training Time | ~45-60 minutes |
100
+
101
+ ## Prompt Format
102
+
103
+ **Input:**
104
+ > Identify the primary organ or structure visible in this abdominal CT slice.
105
+
106
+ **Output:**
107
+ > This abdominal CT slice primarily shows the **Liver**.
108
+ >
109
+ > Liver (largest solid organ in the abdomen, occupying the right upper quadrant with homogeneous parenchymal density).
110
+
111
+ ## Usage
112
+
113
+ ```python
114
+ from transformers import AutoProcessor, AutoModelForImageTextToText
115
+ from peft import PeftModel
116
+ from PIL import Image
117
+
118
+ base_model_id = "google/medgemma-4b-it"
119
+ adapter_id = "efecelik/medgemma-abdominal-ct-lora"
120
+
121
+ processor = AutoProcessor.from_pretrained(base_model_id)
122
+ model = AutoModelForImageTextToText.from_pretrained(
123
+ base_model_id, torch_dtype="bfloat16", device_map="auto"
124
+ )
125
+ model = PeftModel.from_pretrained(model, adapter_id)
126
+
127
+ image = Image.open("abdominal_ct.jpg").convert("RGB")
128
+ messages = [
129
+ {"role": "user", "content": [
130
+ {"type": "image"},
131
+ {"type": "text", "text": "Identify the primary organ or structure visible in this abdominal CT slice."}
132
+ ]}
133
+ ]
134
+
135
+ inputs = processor.apply_chat_template(
136
+ messages, add_generation_prompt=True, tokenize=True,
137
+ return_dict=True, return_tensors="pt", images=[image]
138
+ ).to(model.device)
139
+
140
+ output = model.generate(**inputs, max_new_tokens=256)
141
+ print(processor.decode(output[0], skip_special_tokens=True))
142
+ ```
143
+
144
+ ## Intended Use
145
+
146
+ This adapter is part of the **MedVision AI** platform built for the [MedGemma Impact Challenge](https://www.kaggle.com/competitions/med-gemma-impact-challenge). It is designed for:
147
+
148
+ - **Medical education**: Helping students learn abdominal CT anatomy and organ identification
149
+ - **Clinical decision support**: Assisting radiologists with organ localization
150
+ - **Research**: Exploring fine-tuned medical VLMs for abdominal imaging
151
+
152
+ ## Limitations
153
+
154
+ - **Not for clinical diagnosis.** This model is for educational and research purposes only.
155
+ - **Organ identification only:** Classifies visible organ, does not detect pathology within organs.
156
+ - **Low resolution source:** MedMNIST images are 28x28 pixels, limiting fine structural detail.
157
+ - **Normal anatomy only:** Trained on healthy organ appearances, not pathological variants.
158
+ - **Single epoch:** Trained for 1 epoch; further training may improve performance.
159
+
160
+ ## Citation
161
+
162
+ ```bibtex
163
+ @article{yang2023medmnist,
164
+ title={MedMNIST v2-A large-scale lightweight benchmark for 2D and 3D biomedical image classification},
165
+ author={Yang, Jiancheng and Shi, Rui and Wei, Donglai and Liu, Zequan and Zhao, Lin and Ke, Bilian and Pfister, Hanspeter and Ni, Bingbing},
166
+ journal={Scientific Data},
167
+ volume={10},
168
+ number={1},
169
+ pages={41},
170
+ year={2023},
171
+ publisher={Nature Publishing Group UK London}
172
+ }
173
+ ```
174
+
175
+ ## Disclaimer
176
+
177
+ This model is for **educational and research purposes only**. It is NOT intended for clinical diagnosis or patient care decisions. Always consult qualified medical professionals for medical advice.