Hibou-B - a Foundational Vision Transformer for digital pathology pretrained on a private dataset using DINOv2 framework.
For more information and examples of usage visit https://github.com/HistAI/hibou and read the paper.
Hibou-L is also available at https://modelers.cn/models/CICC/hibou-b.
Basic usage:
import torch, torchvision
import matplotlib.pyplot as plt
from PIL import Image
import torch_npu
import os
from openmind import AutoImageProcessor, AutoModel
from openmind import pipeline, is_torch_npu_available
import argparse
from openmind_hub import snapshot_download
parser = argparse.ArgumentParser()
parser.add_argument("--model_name_or_path", type=str, default="./")
args = parser.parse_args()
if args.model_name_or_path:
model_path = args.model_name_or_path
else:
model_path = snapshot_download(
"CICC/hibou-b",
revision="main",
resume_download=True,
ignore_patterns=["*.h5", "*.ot", " *.msgpack"]
)
if is_torch_npu_available():
device = "npu:0"
else:
device = "cpu"
image = Image.open("./sample.png").convert("RGB")
plt.imshow(image)
plt.axis('off')
plt.show()
processor = AutoImageProcessor.from_pretrained("./", trust_remote_code=True)
hf_model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
hf_data = processor(images=image, return_tensors="pt").to(device)
hf_model = hf_model.to(device)
hf_model.eval()
with torch.no_grad():
hf_output = hf_model(**hf_data)
print(hf_output.pooler_output)We use a customized implementation of the DINOv2 architecture from the transformers library to add support for registers, which requires the trust_remote_code=True flag.