Chexpert-plus RRG
Collection
8 items
•
Updated
•
1
Usage:
import torch
from PIL import Image
from transformers import BertTokenizer, ViTImageProcessor, VisionEncoderDecoderModel, GenerationConfig
import requests
mode = "findings"
# Model
model = VisionEncoderDecoderModel.from_pretrained(f"IAMJB/chexpert-mimic-cxr-{mode}-baseline").eval()
tokenizer = BertTokenizer.from_pretrained(f"IAMJB/chexpert-mimic-cxr-{mode}-baseline")
image_processor = ViTImageProcessor.from_pretrained(f"IAMJB/chexpert-mimic-cxr-{mode}-baseline")
#
# Dataset
generation_args = {
"bos_token_id": model.config.bos_token_id,
"eos_token_id": model.config.eos_token_id,
"pad_token_id": model.config.pad_token_id,
"num_return_sequences": 1,
"max_length": 128,
"use_cache": True,
"beam_width": 2,
}
#
# Inference
refs = []
hyps = []
with torch.no_grad():
url = "https://huggingface.co./IAMJB/interpret-cxr-impression-baseline/resolve/main/effusions-bibasal.jpg"
image = Image.open(requests.get(url, stream=True).raw)
pixel_values = image_processor(image, return_tensors="pt").pixel_values
# Generate predictions
generated_ids = model.generate(
pixel_values,
generation_config=GenerationConfig(
**{**generation_args, "decoder_start_token_id": tokenizer.cls_token_id})
)
generated_texts = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
print(generated_texts)