Spaces:
Paused
Paused
updated prompt and documentation
Browse files- README.md +61 -4
- medrax/tools/medsam2.py +3 -0
README.md
CHANGED
|
@@ -22,7 +22,7 @@ MedRAX is built on a robust technical foundation:
|
|
| 22 |
|
| 23 |
### Integrated Tools
|
| 24 |
- **Visual QA**: Utilizes CheXagent and LLaVA-Med for complex visual understanding and medical reasoning
|
| 25 |
-
- **Segmentation**: Employs
|
| 26 |
- **Grounding**: Uses Maira-2 for localizing specific findings in medical images
|
| 27 |
- **Report Generation**: Implements SwinV2 Transformer trained on CheXpert Plus for detailed medical reporting
|
| 28 |
- **Disease Classification**: Leverages DenseNet-121 from TorchXRayVision for detecting 18 pathology classes
|
|
@@ -227,10 +227,17 @@ XRayVQATool(
|
|
| 227 |
```
|
| 228 |
- CheXagent weights download automatically
|
| 229 |
|
| 230 |
-
###
|
| 231 |
-
```
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
```
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
### Python Sandbox Tool
|
| 236 |
```python
|
|
@@ -256,6 +263,56 @@ WebBrowserTool() # Requires Google Search API credentials
|
|
| 256 |
|
| 257 |
## Manual Setup Required
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
### Image Generation Tool
|
| 260 |
```python
|
| 261 |
ChestXRayGeneratorTool(
|
|
|
|
| 22 |
|
| 23 |
### Integrated Tools
|
| 24 |
- **Visual QA**: Utilizes CheXagent and LLaVA-Med for complex visual understanding and medical reasoning
|
| 25 |
+
- **Segmentation**: Employs MedSAM2 (advanced medical image segmentation) and PSPNet model trained on ChestX-Det for precise anatomical structure identification
|
| 26 |
- **Grounding**: Uses Maira-2 for localizing specific findings in medical images
|
| 27 |
- **Report Generation**: Implements SwinV2 Transformer trained on CheXpert Plus for detailed medical reporting
|
| 28 |
- **Disease Classification**: Leverages DenseNet-121 from TorchXRayVision for detecting 18 pathology classes
|
|
|
|
| 227 |
```
|
| 228 |
- CheXagent weights download automatically
|
| 229 |
|
| 230 |
+
### MedSAM2 Tool
|
| 231 |
+
```python
|
| 232 |
+
MedSAM2Tool(
|
| 233 |
+
model_dir=model_dir,
|
| 234 |
+
device=device,
|
| 235 |
+
temp_dir=temp_dir
|
| 236 |
+
)
|
| 237 |
```
|
| 238 |
+
- Advanced medical image segmentation using MedSAM2 (adapted from Meta's SAM2)
|
| 239 |
+
- Supports interactive prompting with box coordinates, point clicks, or automatic segmentation
|
| 240 |
+
- **Requires manual setup** - see setup instructions below
|
| 241 |
|
| 242 |
### Python Sandbox Tool
|
| 243 |
```python
|
|
|
|
| 263 |
|
| 264 |
## Manual Setup Required
|
| 265 |
|
| 266 |
+
### MedSAM2 Tool
|
| 267 |
+
```python
|
| 268 |
+
MedSAM2Tool(
|
| 269 |
+
model_dir=model_dir,
|
| 270 |
+
device=device,
|
| 271 |
+
temp_dir=temp_dir,
|
| 272 |
+
model_cfg="sam2.1_hiera_t512.yaml", # Optional: model configuration
|
| 273 |
+
checkpoint="MedSAM2_latest.pt" # Optional: specific checkpoint
|
| 274 |
+
)
|
| 275 |
+
```
|
| 276 |
+
|
| 277 |
+
**MedSAM2 Manual Setup Instructions:**
|
| 278 |
+
|
| 279 |
+
1. **Clone MedSAM2 Repository**:
|
| 280 |
+
```bash
|
| 281 |
+
cd model-weights
|
| 282 |
+
git clone https://github.com/bowang-lab/MedSAM2.git
|
| 283 |
+
cd MedSAM2
|
| 284 |
+
```
|
| 285 |
+
|
| 286 |
+
2. **Install Dependencies**:
|
| 287 |
+
```bash
|
| 288 |
+
# Install PyTorch with CUDA support (adjust CUDA version as needed)
|
| 289 |
+
pip install torch==2.5.1 torchvision==0.20.1 --index-url https://download.pytorch.org/whl/cu124
|
| 290 |
+
|
| 291 |
+
# Install MedSAM2 package
|
| 292 |
+
pip install -e ".[dev]"
|
| 293 |
+
```
|
| 294 |
+
|
| 295 |
+
3. **Download Model Checkpoints**:
|
| 296 |
+
```bash
|
| 297 |
+
# Run the download script to get all MedSAM2 checkpoints
|
| 298 |
+
bash download.sh
|
| 299 |
+
```
|
| 300 |
+
This downloads:
|
| 301 |
+
- `MedSAM2_latest.pt` (recommended) - Latest general-purpose model
|
| 302 |
+
- `MedSAM2_CTLesion.pt` - Specialized for CT lesion segmentation
|
| 303 |
+
- `MedSAM2_MRI_LiverLesion.pt` - Specialized for liver lesion MRI
|
| 304 |
+
- `MedSAM2_US_Heart.pt` - Specialized for heart ultrasound
|
| 305 |
+
- Additional EfficientTAM and SAM2 base checkpoints
|
| 306 |
+
|
| 307 |
+
**Configuration Options:**
|
| 308 |
+
- `model_cfg`: Model configuration file (default: `"sam2.1_hiera_t512.yaml"`)
|
| 309 |
+
- `checkpoint`: Checkpoint file to use:
|
| 310 |
+
- `"MedSAM2_latest.pt"` - Best general-purpose model (recommended)
|
| 311 |
+
- `"MedSAM2_CTLesion.pt"` - For CT lesion segmentation
|
| 312 |
+
- `"MedSAM2_MRI_LiverLesion.pt"` - For liver MRI segmentation
|
| 313 |
+
- `"MedSAM2_US_Heart.pt"` - For heart ultrasound segmentation
|
| 314 |
+
|
| 315 |
+
|
| 316 |
### Image Generation Tool
|
| 317 |
```python
|
| 318 |
ChestXRayGeneratorTool(
|
medrax/tools/medsam2.py
CHANGED
|
@@ -50,6 +50,9 @@ class MedSAM2Tool(BaseTool):
|
|
| 50 |
"Supports interactive prompting with box coordinates, point clicks, or automatic segmentation. "
|
| 51 |
"Can handle 2D medical images and 3D volumes. Returns segmentation masks and visualization overlays. "
|
| 52 |
"Prompt types: 'box' with [x1,y1,x2,y2] coordinates, 'point' with [x,y] coordinates, or 'auto' for automatic. "
|
|
|
|
|
|
|
|
|
|
| 53 |
"Example: {'image_path': '/path/to/image.png', 'prompt_type': 'box', 'prompt_coords': [100,100,200,200]}"
|
| 54 |
)
|
| 55 |
args_schema: Type[BaseModel] = MedSAM2Input
|
|
|
|
| 50 |
"Supports interactive prompting with box coordinates, point clicks, or automatic segmentation. "
|
| 51 |
"Can handle 2D medical images and 3D volumes. Returns segmentation masks and visualization overlays. "
|
| 52 |
"Prompt types: 'box' with [x1,y1,x2,y2] coordinates, 'point' with [x,y] coordinates, or 'auto' for automatic. "
|
| 53 |
+
"Don't use auto segmentation for everything, try to use point or box prompts by estimating the coordinates of the object you want to segment."
|
| 54 |
+
"Think step by step and reason about the coordinates carefully, also consider the size of the image itself and the object in the image."
|
| 55 |
+
"Also be aware of the mirroring effect (e.g. the right lung is on the left side of the image, the left lung is on the right side of the image)."
|
| 56 |
"Example: {'image_path': '/path/to/image.png', 'prompt_type': 'box', 'prompt_coords': [100,100,200,200]}"
|
| 57 |
)
|
| 58 |
args_schema: Type[BaseModel] = MedSAM2Input
|