BioLoom-models / README.md
Ruler138's picture
Initial commit
30c0e8b
|
Raw History Blame Contribute Delete
14 kB
metadata
library_name: open_clip
pipeline_tag: zero-shot-image-classification
tags:
  - biomedical
  - contrastive-learning
  - image-text-retrieval
  - zero-shot-classification

BioLoom Models

arXiv 2611.33151 GitHub code Project page Loom52M dataset Evaluation suite

BioLoom is a biomedical dual encoder for image鈥搕ext retrieval and zero-shot classification, trained on 52.4 million image鈥搕ext pairs from Loom52M. It uses whole figures, panels, captions, and relationships within scientific articles to supervise contrastive learning. The main models share a BioClinical ModernBERT text encoder and a ViT-L/14 vision encoder, with either randomly initialized or DFN-2B-initialized visual weights.

馃摝 Model weights

Each model directory contains the weights, architecture configuration, and evaluation files.

馃捇 Inference

Install the project鈥檚 OpenCLIP implementation and its inference dependencies. From its checkout:

pip install -r src/requirements.txt "transformers>=4.48,<5"
export PYTHONPATH="$PWD/src:$PYTHONPATH"

Choose a model folder in the table. Set folder in the example to load its weights and configuration together. The variant name is also the value for --model in the evaluation CLI.

Variant Model folder
scratch Main/Scratch
dfn2b Main/DFN-2B
commonpool Initialization/CommonPool
dinov2 Initialization/DINOv2
vit-s Model-size/ViT-S-14
vit-b Model-size/ViT-B-14
vit-h Model-size/ViT-H-14
import json
from pathlib import Path

import open_clip
import torch
from huggingface_hub import snapshot_download
from open_clip.tokenizer import HFTokenizer
from PIL import Image

folder = "Main/DFN-2B"
files = ["open_clip_pytorch_model.bin", "open_clip_config.json"]
snapshot = snapshot_download(
    "ChartFoundation/BioLoom-models",
    allow_patterns=[f"{folder}/{name}" for name in files],
)
directory = Path(snapshot) / folder
device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = open_clip.create_model_from_pretrained(
    f"local-dir:{directory}", device=device
)
model.eval()
text_cfg = json.loads((directory / "open_clip_config.json").read_text())["model_cfg"]["text_cfg"]
tokenizer = HFTokenizer(text_cfg["hf_tokenizer_name"], context_length=text_cfg["context_length"])

image = preprocess(Image.open("figure.jpg").convert("RGB")).unsqueeze(0).to(device)
tokens = tokenizer(["a microscopy image", "a radiograph"]).to(device)
with torch.inference_mode():
    scores = model.encode_image(image, normalize=True) @ model.encode_text(tokens, normalize=True).T
print(scores.cpu())

馃И Evaluation

For example, evaluate the downloaded DFN-2B model on the full BioLoomBench gallery from the BioLoom checkout. Set MODEL_DIR to the directory printed by print(directory) in the loading example.

python -m evaluation --model dfn2b --benchmark bioloombench --download \
  --checkpoint "$MODEL_DIR/open_clip_pytorch_model.bin" --output results/dfn2b.json

To evaluate a checkpoint, use the data and protocols in BioLoom-EvalSuite. Load the checkpoint and its matching architecture as shown above, then follow the zero-shot classification, BioMedFlickr, or BioLoomBench guide. Each model鈥檚 results/ folder contains three files: zero-shot.json for all 67 classification tasks, biomedflickr-retrieval.json for BioMedFlickr, and bioloom-retrieval.json for BioLoomBench.