Created
February 3, 2023 15:45
-
-
Save nathansutton/c085080d2e58ba09e1f255036c3fb068 to your computer and use it in GitHub Desktop.
blip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
from transformers import BlipForConditionalGeneration, BlipProcessor | |
# read in the model | |
processor = BlipProcessor.from_pretrained("nathansutton/generate-cxr") | |
model = BlipForConditionalGeneration.from_pretrained("nathansutton/generate-cxr") | |
# your data | |
my_image = 'my-chest-x-ray.jpg' | |
my_indication = 'RLL crackles, eval for pneumonia' | |
# process the inputs | |
inputs = processor( | |
images=Image.open(my_image), | |
text='indication:' + my_indication, | |
return_tensors="pt" | |
) | |
# generate an entire radiology report | |
output = model.generate(**inputs,max_length=512) | |
report = processor.decode(output[0], skip_special_tokens=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment