Yuesai commited on
Commit
d1eebe9
·
verified ·
1 Parent(s): 2b25d12

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +15 -3
README.md CHANGED
@@ -36,12 +36,24 @@ image = Image.open("hand_xray.png").convert("RGB")
36
  inputs = processor(images=image, return_tensors="pt")
37
 
38
  with torch.no_grad():
39
- outputs = model(**inputs)
40
 
41
- cls_embedding = outputs.last_hidden_state[:, 0] # [1, 768]
42
- print(cls_embedding.shape)
 
 
 
 
 
 
 
 
 
 
43
  ```
44
 
 
 
45
  **Intended use:** Research on hand radiographs. Not validated for direct clinical diagnosis or treatment decisions. The model weights are distributed subject to the [DINOv3 License](https://github.com/facebookresearch/dinov3/blob/main/LICENSE.md); see the accompanying license file.
46
 
47
  ## Citation
 
36
  inputs = processor(images=image, return_tensors="pt")
37
 
38
  with torch.no_grad():
39
+ tokens = model(**inputs).last_hidden_state
40
 
41
+ # DINOv3 token order: [CLS, register tokens, patch tokens]
42
+ num_register_tokens = getattr(model.config, "num_register_tokens", 0)
43
+ cls_embedding = tokens[:, 0, :] # [B, 768]
44
+ patch_embeddings = tokens[:, 1 + num_register_tokens:, :] # [B, 196, 768] for 224x224
45
+
46
+ # Optional: mean-pool CLS + patch tokens (excluding register tokens)
47
+ features = torch.cat([cls_embedding.unsqueeze(1), patch_embeddings], dim=1)
48
+ pooled_embedding = features.mean(dim=1) # [B, 768]
49
+
50
+ print("CLS:", cls_embedding.shape)
51
+ print("Patches:", patch_embeddings.shape)
52
+ print("Pooled:", pooled_embedding.shape)
53
  ```
54
 
55
+ Use `cls_embedding` for global image features, `patch_embeddings` for spatial features, or `pooled_embedding` for a single pooled representation. Register tokens are excluded from patch features.
56
+
57
  **Intended use:** Research on hand radiographs. Not validated for direct clinical diagnosis or treatment decisions. The model weights are distributed subject to the [DINOv3 License](https://github.com/facebookresearch/dinov3/blob/main/LICENSE.md); see the accompanying license file.
58
 
59
  ## Citation