Instructions to use microsoft/rad-dino with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/rad-dino with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="microsoft/rad-dino")# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, AutoModel processor = AutoImageProcessor.from_pretrained("microsoft/rad-dino") model = AutoModel.from_pretrained("microsoft/rad-dino", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download src/rad_dino/utils.py from microsoft/rad-dino: direct link, hf CLI and curl.
- Browser
- Download file 783 Bytes
-
https://huggingface.co/microsoft/rad-dino/resolve/main/src/rad_dino/utils.py
- Command line
-
hf download hf://microsoft/rad-dino/src/rad_dino/utils.py
-
curl -L -o utils.py https://huggingface.co/microsoft/rad-dino/resolve/main/src/rad_dino/utils.py
783 Bytes
| import requests | |
| import torch | |
| from PIL import Image | |
| from safetensors import safe_open | |
| def download_sample_image() -> Image.Image: | |
| """Download chest X-ray with CC license.""" | |
| base_url = "https://upload.wikimedia.org/wikipedia/commons" | |
| path = "2/20/Chest_X-ray_in_influenza_and_Haemophilus_influenzae.jpg" | |
| image_url = f"{base_url}/{path}" | |
| headers = {"User-Agent": "RAD-DINO"} | |
| response = requests.get(image_url, headers=headers, stream=True) | |
| return Image.open(response.raw) | |
| def safetensors_to_state_dict(checkpoint_path: str) -> dict[str, torch.Tensor]: | |
| state_dict = {} | |
| with safe_open(checkpoint_path, framework="pt") as ckpt_file: | |
| for key in ckpt_file.keys(): | |
| state_dict[key] = ckpt_file.get_tensor(key) | |
| return state_dict | |