dmusingu commited on
Commit
e85b9de
Β·
verified Β·
1 Parent(s): ba5017c

Update README with model loading code

Browse files
Files changed (1) hide show
  1. README.md +42 -25
README.md CHANGED
@@ -13,37 +13,54 @@ Part of the [LAPVQA collection](https://huggingface.co/collections/dmusingu/lapv
13
 
14
  ## Description
15
 
16
- Phrase grounding heads trained on MIMIC-CXR, predicting the bounding box of a described
17
- abnormality given the image and a text phrase (e.g. "Pleural Effusion").
18
- Six frozen encoder backbones are covered; each file contains only the grounding head weights.
19
 
20
- ## Results (MIMIC-CXR test set)
 
 
 
 
 
 
 
 
 
21
 
22
- **Zero-shot (no fine-tuning):**
23
 
24
- | Encoder | mIoU | Acc@0.25 |
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
- | mIoU | Acc@0.25 | Acc@0.50 | Pointing Acc |
35
  |---|---|---|---|
36
- | 0.320 | 0.569 | 0.273 | 0.593 |
 
 
 
 
 
 
 
37
 
38
- Fine-tuning provides a ~4Γ— improvement over zero-shot across all encoders.
 
 
39
 
40
- ## Files
 
 
 
 
 
 
 
 
41
 
42
- | File | Encoder backbone |
43
- |---|---|
44
- | `clip-vit-l14.pt` | CLIP ViT-L/14 |
45
- | `siglip.pt` | SigLIP |
46
- | `florence2.pt` | Florence-2 |
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
+ ```