Instructions to use medarc/Midnight-12k-SPECTRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use medarc/Midnight-12k-SPECTRA with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="medarc/Midnight-12k-SPECTRA")# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, AutoModel processor = AutoImageProcessor.from_pretrained("medarc/Midnight-12k-SPECTRA") model = AutoModel.from_pretrained("medarc/Midnight-12k-SPECTRA", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Midnight-12k-SPECTRA
MedARC · Sophont · Paper (coming soon)
Midnight-12k-SPECTRA is midnight adapted with SPECTRA by MedARC and Sophont. We trained on registered PLISM image tiles, aligning representations of the same tissue across scanners and stains with a contrastive objective. The learned updates are merged into the full model weights.
The model maps RGB histology tiles to 3,072-dimensional embeddings for downstream analysis. All inference weights are included; no separate base checkpoint, adapter, or cluster access is required.
Inference
In a Python environment:
uv pip install torch torchvision "transformers==4.57.6" huggingface_hub safetensors pillow
import torch
from PIL import Image
from torchvision import transforms as T
from transformers import AutoModel
device = "cuda" # Use "cpu" to run without a GPU.
model = AutoModel.from_pretrained("medarc/Midnight-12k-SPECTRA").eval().to(device)
transform = T.Compose([
T.Resize(224, interpolation=T.InterpolationMode.BILINEAR),
T.CenterCrop(224),
T.ToTensor(),
T.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5)),
])
image = Image.open("tile.png").convert("RGB")
batch = transform(image).unsqueeze(0).to(device)
with torch.inference_mode():
tokens = model(batch).last_hidden_state
embedding = torch.cat([tokens[:, 0], tokens[:, 1:].mean(dim=1)], dim=-1)
print(embedding.shape) # torch.Size([1, 3072])
The example uses bilinear resizing to 224 pixels, a 224 × 224 center crop, and mean/std (0.5, 0.5, 0.5). The embedding concatenates the CLS token and mean patch token.
These are tile embeddings. Slide-level predictions require a downstream model.
Paper
Coming soon. We will add the paper link and citation here.
- Downloads last month
- 18