astroanand commited on
Commit
b05be91
·
verified ·
1 Parent(s): afab61d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +275 -3
README.md CHANGED
@@ -1,3 +1,275 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model:
4
+ - facebook/sam2-hiera-tiny
5
+ - facebook/sam2-hiera-small
6
+ - facebook/sam2-hiera-base-plus
7
+ - facebook/sam2-hiera-large
8
+ pipeline_tag: image-segmentation
9
+ ---
10
+ # Model Card: CoronarySAM2 - Fine-tuned SAM2 for Coronary Artery Segmentation
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ CoronarySAM2 is a collection of fine-tuned Segment Anything Model 2 (SAM2) variants specifically optimized for coronary artery segmentation in X-ray angiography images. The models use point-based prompting to enable interactive and precise segmentation of coronary arteries from medical imaging data.
17
+
18
+ - **Developed by:** Research Team
19
+ - **Model Type:** Computer Vision - Image Segmentation
20
+ - **Base Architecture:** SAM2 (Segment Anything Model 2) with Hiera backbone
21
+ - **Language(s):** Python
22
+ - **License:** [Specify License]
23
+ - **Fine-tuned from:** [facebook/segment-anything-2](https://github.com/facebookresearch/segment-anything-2)
24
+
25
+ ### Model Variants
26
+
27
+ Four model variants are available, offering different trade-offs between speed and accuracy:
28
+
29
+ | Model | Parameters | Checkpoint | Speed | Accuracy | Use Case |
30
+ |-------|-----------|------------|-------|----------|----------|
31
+ | **SAM2 Hiera Tiny** | ~38M | `sam2_t/best_model.pt` | ⚡⚡⚡ Fast | ⭐⭐⭐ Good | Quick experiments, real-time feedback |
32
+ | **SAM2 Hiera Small** | ~46M | `sam2_s/checkpoint_epoch_70.pt` | ⚡⚡ Medium | ⭐⭐⭐⭐ Very Good | Balanced performance, general use |
33
+ | **SAM2 Hiera Base Plus** | ~80M | `sam2_b+/best_model.pt` | ⚡ Slower | ⭐⭐⭐⭐⭐ Excellent | High-quality results, clinical evaluation |
34
+ | **SAM2 Hiera Large** | ~224M | `sam2_l/final_model.pt` | ⚡ Slowest | ⭐⭐⭐⭐⭐ Best | Maximum accuracy, research purposes |
35
+
36
+ ### Model Architecture
37
+
38
+ The models follow the SAM2 architecture with the following components:
39
+
40
+ 1. **Image Encoder**: Hiera hierarchical vision transformer backbone
41
+ 2. **Prompt Encoder**: Encodes point prompts (positive/negative) as spatial embeddings
42
+ 3. **Mask Decoder**: Transformer-based decoder that generates high-quality segmentation masks
43
+ 4. **Preprocessing Pipeline**:
44
+ - X-ray image normalization using Gaussian blur
45
+ - CLAHE (Contrast Limited Adaptive Histogram Equalization) for vessel enhancement
46
+ - Fixed resolution resizing to 1024×1024 pixels
47
+
48
+ ## Intended Use
49
+
50
+ ### Primary Use Cases
51
+
52
+ - **Interactive Coronary Artery Segmentation**: Point-based annotation for precise artery delineation
53
+ - **Medical Image Analysis**: Automated assistance for cardiologists and radiologists
54
+ - **Research**: Computer-aided diagnosis and treatment planning research
55
+ - **Educational Purposes**: Training and demonstration of medical image segmentation
56
+
57
+ ### Out-of-Scope Use
58
+
59
+ - ❌ Clinical diagnosis without expert oversight
60
+ - ❌ Automated treatment decisions
61
+ - ❌ Real-time interventional guidance without validation
62
+ - ❌ Non-coronary vessel segmentation (not trained for this task)
63
+ - ❌ Modalities other than X-ray angiography (CT, MRI, etc.)
64
+
65
+ ## Training Data
66
+
67
+ ### Dataset
68
+
69
+ The models were fine-tuned on coronary X-ray angiography images with annotations for coronary artery structures.
70
+
71
+ **Training Specifications:**
72
+ - **Modality**: X-ray Angiography
73
+ - **Target**: Coronary Arteries
74
+ - **Annotation Type**: Binary segmentation masks
75
+ - **Resolution**: Images resized to 1024×1024 for training
76
+
77
+ ### Preprocessing
78
+
79
+ All training images underwent the following preprocessing pipeline:
80
+
81
+ 1. **Normalization**: Gaussian blur-based intensity normalization
82
+ 2. **CLAHE Enhancement**: Adaptive histogram equalization (clip limit: 2.0, tile grid: 8×8)
83
+ 3. **Resizing**: Fixed 1024×1024 resolution
84
+ 4. **Format**: RGB format (grayscale images converted to RGB)
85
+
86
+ ## Evaluation
87
+
88
+ ### Metrics
89
+
90
+ The models should be evaluated using the following metrics:
91
+
92
+ - **Dice Coefficient**: Measures overlap between predicted and ground truth masks
93
+ - **IoU (Intersection over Union)**: Pixel-wise accuracy metric
94
+ - **Precision & Recall**: For detecting true vessel pixels
95
+ - **Hausdorff Distance**: Measures boundary accuracy
96
+ - **Inference Time**: Speed benchmarks on various hardware
97
+
98
+ ### Performance Considerations
99
+
100
+ - **Point Prompt Quality**: Model performance heavily depends on the quality and number of point prompts
101
+ - **Image Quality**: Better results with high-contrast angiography images
102
+ - **Vessel Complexity**: Performance may vary with vessel overlap and bifurcations
103
+ - **Model Selection**: Larger models generally provide better accuracy but slower inference
104
+
105
+ ## How to Use
106
+
107
+ ### Installation
108
+
109
+ ```bash
110
+ # Create conda environment
111
+ conda create -n sam2_FT_env python=3.10.0 -y
112
+ conda activate sam2_FT_env
113
+
114
+ # Install SAM2
115
+ git clone https://github.com/facebookresearch/segment-anything-2.git
116
+ cd segment-anything-2
117
+ pip install -e .
118
+ cd ..
119
+
120
+ # Install dependencies
121
+ pip install gradio opencv-python-headless torch torchvision torchaudio
122
+ ```
123
+
124
+ ### Basic Usage
125
+
126
+ ```python
127
+ import torch
128
+ import numpy as np
129
+ from sam2.build_sam import build_sam2
130
+ from sam2.sam2_image_predictor import SAM2ImagePredictor
131
+
132
+ # Load model
133
+ checkpoint_path = "ft_models/sam2_s/checkpoint_epoch_70.pt"
134
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
135
+
136
+ checkpoint = torch.load(checkpoint_path, map_location=device)
137
+ model_cfg = checkpoint['model_cfg']
138
+ sam2_model = build_sam2(model_cfg, checkpoint_path=None, device=device)
139
+
140
+ # Load state dict
141
+ state_dict = checkpoint['model_state_dict']
142
+ new_state_dict = {k[7:] if k.startswith('module.') else k: v
143
+ for k, v in state_dict.items()}
144
+ sam2_model.load_state_dict(new_state_dict)
145
+ sam2_model.eval()
146
+
147
+ # Create predictor
148
+ predictor = SAM2ImagePredictor(sam2_model)
149
+
150
+ # Set image (preprocessed, 1024x1024, RGB, uint8)
151
+ predictor.set_image(preprocessed_image)
152
+
153
+ # Add point prompts
154
+ point_coords = np.array([[512, 300], [520, 310]]) # x, y coordinates
155
+ point_labels = np.array([1, 1]) # 1 = positive, 0 = negative
156
+
157
+ # Predict
158
+ masks, scores, logits = predictor.predict(
159
+ point_coords=point_coords,
160
+ point_labels=point_labels,
161
+ multimask_output=True
162
+ )
163
+ ```
164
+
165
+ ### Interactive Application
166
+
167
+ Launch the Gradio interface:
168
+
169
+ ```bash
170
+ python app.py
171
+ ```
172
+
173
+ Access at `http://127.0.0.1:7860`
174
+
175
+ ## Limitations
176
+
177
+ ### Technical Limitations
178
+
179
+ - **Fixed Input Size**: Models expect 1024×1024 input (automatic resizing may affect small vessels)
180
+ - **Memory Requirements**: Large model requires significant GPU memory (~8GB VRAM recommended)
181
+ - **Point Dependency**: Requires manual point prompts; not fully automatic
182
+ - **Single Modality**: Optimized only for X-ray angiography
183
+
184
+ ### Medical Limitations
185
+
186
+ - **Not FDA Approved**: Not cleared for clinical diagnostic use
187
+ - **Requires Expert Review**: All outputs must be validated by qualified professionals
188
+ - **Variability**: Performance may vary across different imaging protocols and equipment
189
+ - **Edge Cases**: May struggle with severe vessel overlap, calcifications, or poor image quality
190
+
191
+ ### Known Issues
192
+
193
+ - High-contrast regions may cause over-segmentation
194
+ - Thin vessel branches may be missed without precise point placement
195
+ - Performance degradation on low-quality or motion-blurred images
196
+
197
+ ## Ethical Considerations
198
+
199
+ ### Medical AI Responsibility
200
+
201
+ - **Human Oversight Required**: This tool is designed to assist, not replace, medical professionals
202
+ - **No Autonomous Decisions**: Should never be used for automated clinical decisions
203
+ - **Training Data Bias**: Model performance may reflect biases present in training data
204
+ - **Privacy**: Ensure patient data is handled according to HIPAA/GDPR regulations
205
+
206
+ ### Fairness & Bias
207
+
208
+ - Model performance across different patient demographics should be validated
209
+ - Imaging equipment and protocols may affect performance
210
+ - Consider potential biases in training dataset composition
211
+
212
+ ### Transparency
213
+
214
+ - Model predictions should be explainable to medical professionals
215
+ - Segmentation boundaries should be reviewable and editable
216
+ - Point prompt influence on outputs should be clear to users
217
+
218
+ ## Citation
219
+
220
+ ### Base Model (SAM2)
221
+
222
+ ```bibtex
223
+ @article{ravi2024sam2,
224
+ title={SAM 2: Segment Anything in Images and Videos},
225
+ author={Ravi, Nikhila and Gabeur, Valentin and Hu, Yuan-Ting and Hu, Ronghang and Ryali, Chaitanya and Ma, Tengyu and Khedr, Haitham and R{\"a}dle, Roman and Rolland, Chloe and Gustafson, Laura and others},
226
+ journal={arXiv preprint arXiv:2408.00714},
227
+ year={2024}
228
+ }
229
+ ```
230
+
231
+ ### This Work
232
+
233
+ If you use CoronarySAM2 in your research, please cite:
234
+
235
+ ```bibtex
236
+ @software{coronarysam2_2025,
237
+ title={CoronarySAM2: Fine-tuned SAM2 for Coronary Artery Segmentation},
238
+ author={[Your Name/Team]},
239
+ year={2025},
240
+ url={[Repository URL]}
241
+ }
242
+ ```
243
+
244
+ ## Model Card Authors
245
+
246
+ - [Primary Author Names]
247
+ - Last Updated: November 2025
248
+
249
+ ## Contact
250
+
251
+ For questions, issues, or collaboration inquiries:
252
+
253
+ - **GitHub Issues**: [Repository URL]/issues
254
+ - **Email**: [Contact Email]
255
+
256
+ ## Disclaimer
257
+
258
+ **⚠️ IMPORTANT MEDICAL DISCLAIMER ⚠️**
259
+
260
+ This software is provided for **research and educational purposes only**. It is not intended for clinical use, medical diagnosis, or treatment planning. The models have not been validated for clinical deployment and are not FDA-approved or CE-marked medical devices.
261
+
262
+ **Always consult qualified healthcare professionals** for medical image interpretation and clinical decisions. The developers assume no liability for any clinical use or consequences resulting from the use of this software.
263
+
264
+ ## Additional Resources
265
+
266
+ - [SAM2 Paper](https://arxiv.org/abs/2408.00714)
267
+ - [SAM2 GitHub Repository](https://github.com/facebookresearch/segment-anything-2)
268
+ - [Project README](README.md)
269
+ - [Application Interface](app.py)
270
+
271
+ ---
272
+
273
+ **Version**: 1.0
274
+ **Last Updated**: November 18, 2025
275
+ **Status**: Research/Development