Model Card for Model ID
Radiography - Brain CT Image Caption and Region of Interest Detection
Model Details
Model Description
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
- Developed by: [More Information Needed]
- Funded by [optional]: [More Information Needed]
- Shared by [optional]: [More Information Needed]
- Model type: [More Information Needed]
- Language(s) (NLP): [More Information Needed]
- License: [More Information Needed]
- Finetuned from model [optional]: [More Information Needed]
Model Sources [optional]
- Repository: [More Information Needed]
- Paper [optional]: [More Information Needed]
- Demo [optional]: [More Information Needed]
Usage
import os from datasets import load_dataset
Load dataset
ds = load_dataset("mychen76/medtrinity_brain_408_hf")
train=ds["train"]
idx=20
test_image = test_ds[idx]["image"]
test_image.resize([350, 350])
Load Model
import torch
from PIL import Image
import matplotlib.pyplot as plt
import textwrap
from transformers import AutoModelForCausalLM, AutoProcessor
# Set device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
mode_id_or_path = "mychen76/Florence2-FT-Med-brain-408"
# Load fine-tuned model and processor
model = AutoModelForCausalLM.from_pretrained(model_id_or_path, trust_remote_code=True).to(device)
processor = AutoProcessor.from_pretrained(model_id_or_path, trust_remote_code=True)
Test Model
# Function to run the model on an example
def run_model_inference(task_prompt, text_input, image, device="cpu"):
if text_input is None:
prompt = task_prompt
else:
prompt = task_prompt + text_input
# print("PROMPT=",prompt)
# Ensure the image is in RGB mode
if image.mode != "RGB":
image = image.convert("RGB")
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
generated_ids = model.generate(
input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=1024,
num_beams=3
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
return parsed_answer
Task-1 CAPTION
results = run_model_inference("<CAPTION>",None,test_image)
print(results)
Results
<CAPTION>The image is a non-contrasted CT scan of the brain, showing the abnormal abnormal density, located approximately 1.5% of the image area and appears to have a different density compared to the surrounding brain tissue, which may indicate an intracranial pressure. The region of interest, located adjacent to the adjacent brain, is indicative of a brain tissue. This abnormal area could be related to the brain structures due to the presence of blood or a mass effect, which is a common feature of adjacent brain structures.'
Task-2 CAPTION_DETAILS
results = run_model_inference("<CAPTION_DETAILS>",None,test_image)
print(results)
Results
<CAPTION_DETAILS>The image is a non-contrasted CT scan of the brain, showing the intracranial structures without any medical devices present.\n\nREGION OF INTEREST\nThe region of interest, located brain tissue, occupies approximately 1.5% of the image area and appears to have a different density compared to the surrounding brain tissue.\nCONDITION\nThis region's proximity to other brain structures could be related to a mass effect or as a result of a massage, which is indicative of a intracronial pressure.\nThis abnormal area could be indicative of an abnormal area, potentially potentially leading to a potential mass effect on adjacent brain structures.
Task-3 REGION_OF_INTEREST
results = run_model_inference("<REGION_OF_INTEREST>",None,test_image)
print(results)
Results
<REGION_OF_INTEREST>The region of interest, located adjacent to the brain, occupies approximately 1.5% of the image area and appears to have a different density compared to the surrounding brain tissue, which may indicate an intracranial pressure.
Task-4 OBSERVATION
results = run_model_inference("<REGION_OF_INTEREST>",None,test_image)
print(results)
Results
<OBSERVATION>The region of interest, located approximately 1.5% of the image area and appears to have a different density compared to the surrounding brain tissue, which may indicate an intracranial pressure.
Testing Data, Factors & Metrics
Testing Data
[More Information Needed]
Factors
[More Information Needed]
Metrics
[More Information Needed]
Results
[More Information Needed]
Summary
Model Examination [optional]
[More Information Needed]
Environmental Impact
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
- Hardware Type: [More Information Needed]
- Hours used: [More Information Needed]
- Cloud Provider: [More Information Needed]
- Compute Region: [More Information Needed]
- Carbon Emitted: [More Information Needed]
Technical Specifications [optional]
Model Architecture and Objective
[More Information Needed]
Compute Infrastructure
[More Information Needed]
Hardware
[More Information Needed]
Software
[More Information Needed]
Citation [optional]
BibTeX:
[More Information Needed]
APA:
[More Information Needed]
Glossary [optional]
[More Information Needed]
More Information [optional]
[More Information Needed]
Model Card Authors [optional]
[More Information Needed]
Model Card Contact
[More Information Needed]
- Downloads last month
- 18