HuggingFace镜像/hibou-b
模型介绍文件和版本分析
下载使用量0

Hibou-B - 一个基于数字病理学的基础视觉Transformer,使用DINOv2框架在私有数据集上进行预训练。

有关更多信息和使用示例,请访问 https://github.com/HistAI/hibou 并阅读 论文。

Hibou-L 也可在 https://modelers.cn/models/CICC/hibou-b 获取。

基本用法:

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)

我们使用了来自 transformers 库的 DINOv2 架构的定制实现,以添加对寄存器的支持,这需要 trust_remote_code=True 标志。