Instructions to use lhphillips/cellrepDINO with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lhphillips/cellrepDINO with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="lhphillips/cellrepDINO", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("lhphillips/cellrepDINO", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from lhphillips/cellrepDINO: direct link, hf CLI and curl.
- Browser
- Download file 2.35 kB
-
https://huggingface.co/lhphillips/cellrepDINO/resolve/refs%2Fpr%2F13/README.md
- Command line
-
hf download hf://lhphillips/cellrepDINO@refs/pr/13/README.md
-
curl -L -H "Authorization: Bearer $HF_TOKEN" -o README.md https://huggingface.co/lhphillips/cellrepDINO/resolve/refs%2Fpr%2F13/README.md
2.35 kB
| library_name: transformers | |
| tags: | |
| - vision | |
| - cell-biology | |
| - dino | |
| pipeline_tag: image-feature-extraction | |
| model-index: | |
| - name: cellrepDINO | |
| results: [] | |
| # CellrepDINO Model | |
| This is a custom DINO model for extracting rich representations of cell microscopy in condensed vector/array form. The forward method of the cellrepDINO model gives embeddings that can be used | |
| for relevant downstream tasks like perturbation prediction, mechanism of action (MoA) classification, nuclei size shape estimation, etc. Simply train a basic linear or logistic model using the embeddings. | |
| ## Model Details | |
| - Architecture: DINOv2 | |
| - Type: Vision Transformer | |
| - Input Size: 518x518 | |
| - Patch Size: 14 | |
| - Image Size: 1024 | |
| - Center Crop: 518 | |
| ## Setup | |
| Please git clone the repository via `git clone --filter=blob:none https://huggingface.co/lhphillips/cellrepDINO`. Then `cd` to the directory, and run `pip install -e .` | |
| ## Example Usage | |
| There are different types of embeddings of embeddings one can extract, we recommend the mean/median embeddings over the patch tokens or the class token embedding. | |
| The code below is an example of the mean of the patch token embeddings. To get the median simply replace `batch_outputs['x_norm_patchtokens'].mean(dim=1)` with `batch_outputs['x_norm_patchtokens'].median(dim=1)`. | |
| To get the class token embeddings: `batch_embeddings = batch_outputs['x_norm_clstoken']['x_norm_clstoken']`. | |
| ``` | |
| from transformers import AutoModel, AutoProcessor | |
| from PIL import Image | |
| import torch | |
| # Set up device | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| # Load model and processor | |
| model = AutoModel.from_pretrained("LPhilllips/cellrepDINO", trust_remote_code=True) | |
| processor = AutoProcessor.from_pretrained("LPhilllips/cellrepDINO", trust_remote_code=True) | |
| # Move model to device | |
| model = model.to(device) | |
| model.eval() | |
| # For multiple images: | |
| image_paths = ["image1.png", "image2.png"] | |
| images = [Image.open(path) for path in image_paths] | |
| # Process batch of images | |
| batch_inputs = processor.preprocess(images=images, return_tensors="pt") | |
| batch_inputs = {k: v.to(device) if isinstance(v, torch.Tensor) else v for k, v in batch_inputs.items()} | |
| # Generate embeddings for batch | |
| with torch.no_grad(): | |
| batch_outputs = model(**batch_inputs) | |
| batch_embeddings = batch_outputs['x_norm_patchtokens'].mean(dim=1) | |
| ``` |