Update README with model loading code
Browse files
README.md
CHANGED
|
@@ -13,37 +13,54 @@ Part of the [LAPVQA collection](https://huggingface.co/collections/dmusingu/lapv
|
|
| 13 |
|
| 14 |
## Description
|
| 15 |
|
| 16 |
-
|
| 17 |
-
abnormality given the
|
| 18 |
-
|
| 19 |
|
| 20 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|---|---|---|
|
| 26 |
-
| SigLIP | 0.086 | 0.042 |
|
| 27 |
-
| Florence-2 | 0.089 | 0.046 |
|
| 28 |
-
| CLIP ViT-L/14 | 0.085 | 0.028 |
|
| 29 |
-
| CoCa | 0.082 | 0.023 |
|
| 30 |
-
| OWLv2 | 0.082 | 0.023 |
|
| 31 |
|
| 32 |
-
**Fine-tuned (MAE-ViT-L/16):**
|
| 33 |
|
| 34 |
-
|
|
| 35 |
|---|---|---|---|
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
| `coca.pt` | CoCa |
|
| 48 |
-
| `owlv2.pt` | OWLv2 |
|
| 49 |
-
| `mae-vit-l16.pt` | MAE ViT-L/16 (fine-tuned) |
|
|
|
|
| 13 |
|
| 14 |
## Description
|
| 15 |
|
| 16 |
+
TransVG-style phrase grounding heads trained on MIMIC-CXR, predicting the bounding
|
| 17 |
+
box of a described abnormality given the chest X-ray and a text phrase.
|
| 18 |
+
Each checkpoint is a dict: `{state_dict, vis_dim, txt_dim, d_model, num_layers, encoder, epoch, val_miou, val_acc50}`.
|
| 19 |
|
| 20 |
+
## Architecture β `VisualGroundingHead`
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
vis_proj : Linear(vis_dim β 256)
|
| 24 |
+
txt_proj : Linear(txt_dim β 256)
|
| 25 |
+
reg_token : Parameter [1, 1, 256]
|
| 26 |
+
sequence : [REG | vis_tokens | txt_token]
|
| 27 |
+
transformer: 3 Γ TransformerEncoderLayer (self-attn, pre-norm)
|
| 28 |
+
box_head : MLP(256 β 256 β 4) # sigmoid β (cx,cy,w,h) β [0,1]
|
| 29 |
+
```
|
| 30 |
|
| 31 |
+
## Results (MIMIC-CXR test set)
|
| 32 |
|
| 33 |
+
**Zero-shot:** mIoU β 0.082β0.089 across all encoders.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
**Fine-tuned (MAE-ViT-L/16):** mIoU 0.320, Acc@0.25 0.569, Pointing Acc 0.593.
|
| 36 |
|
| 37 |
+
| File | Encoder | vis_dim | txt_dim |
|
| 38 |
|---|---|---|---|
|
| 39 |
+
| `clip-vit-l14.pt` | CLIP ViT-L/14 | 1024 | 768 |
|
| 40 |
+
| `siglip.pt` | SigLIP | 1152 | 1152 |
|
| 41 |
+
| `florence2.pt` | Florence-2 | 1024 | 768 |
|
| 42 |
+
| `coca.pt` | CoCa | 768 | 768 |
|
| 43 |
+
| `owlv2.pt` | OWLv2 | 1024 | 768 |
|
| 44 |
+
| `mae-vit-l16.pt` | MAE ViT-L/16 | 1024 | 768 |
|
| 45 |
+
|
| 46 |
+
## Loading
|
| 47 |
|
| 48 |
+
```python
|
| 49 |
+
import torch
|
| 50 |
+
from lapvqa.pg.heads import VisualGroundingHead
|
| 51 |
|
| 52 |
+
ckpt = torch.load("mae-vit-l16.pt", map_location="cpu")
|
| 53 |
+
head = VisualGroundingHead(
|
| 54 |
+
vis_dim = ckpt["vis_dim"],
|
| 55 |
+
txt_dim = ckpt["txt_dim"],
|
| 56 |
+
d_model = ckpt["d_model"],
|
| 57 |
+
num_layers = ckpt["num_layers"],
|
| 58 |
+
)
|
| 59 |
+
head.load_state_dict(ckpt["state_dict"])
|
| 60 |
+
head.eval()
|
| 61 |
|
| 62 |
+
with torch.no_grad():
|
| 63 |
+
# vis_tokens: [B, HW, vis_dim] β spatial patch tokens from frozen encoder
|
| 64 |
+
# txt_vec: [B, txt_dim] β pooled text representation from frozen encoder
|
| 65 |
+
pred_boxes = head(vis_tokens, txt_vec) # [B, 4] (cx,cy,w,h) in [0,1]
|
| 66 |
+
```
|
|
|
|
|
|
|
|
|