mychen76 commited on
Commit
8957ff6
1 Parent(s): 9355f86

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +92 -70
README.md CHANGED
@@ -33,76 +33,98 @@ This is the model card of a 🤗 transformers model that has been pushed on the
33
  - **Paper [optional]:** [More Information Needed]
34
  - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  ### Testing Data, Factors & Metrics
108
 
 
33
  - **Paper [optional]:** [More Information Needed]
34
  - **Demo [optional]:** [More Information Needed]
35
 
36
+ ## Usage
37
+
38
+ import os
39
+ from datasets import load_dataset
40
+
41
+ ***Load dataset***
42
+ ```
43
+ ds = load_dataset("mychen76/medtrinity_brain_408_hf")
44
+ train=ds["train"]
45
+
46
+ idx=20
47
+ test_image = test_ds[idx]["image"]
48
+ test_image.resize([350, 350])
49
+ ```
50
+ ***Load Model***
51
+ ```
52
+ import torch
53
+ from PIL import Image
54
+ import matplotlib.pyplot as plt
55
+ import textwrap
56
+ from transformers import AutoModelForCausalLM, AutoProcessor
57
+
58
+ # Set device
59
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
60
+ mode_id_or_path = "mychen76/Florence2-FT-Med-brain-408"
61
+
62
+ # Load fine-tuned model and processor
63
+ model = AutoModelForCausalLM.from_pretrained(model_id_or_path, trust_remote_code=True).to(device)
64
+ processor = AutoProcessor.from_pretrained(model_id_or_path, trust_remote_code=True)
65
+ ```
66
+ ***Test Model***
67
+ ```
68
+ # Function to run the model on an example
69
+ def run_model_inference(task_prompt, text_input, image, device="cpu"):
70
+
71
+ if text_input is None:
72
+ prompt = task_prompt
73
+ else:
74
+ prompt = task_prompt + text_input
75
+
76
+ # print("PROMPT=",prompt)
77
+ # Ensure the image is in RGB mode
78
+ if image.mode != "RGB":
79
+ image = image.convert("RGB")
80
+
81
+ inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
82
+ generated_ids = model.generate(
83
+ input_ids=inputs["input_ids"],
84
+ pixel_values=inputs["pixel_values"],
85
+ max_new_tokens=1024,
86
+ num_beams=3
87
+ )
88
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
89
+ parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
90
+ return parsed_answer
91
+ ```
92
+ ***Task-1 CAPTION***
93
+ ```
94
+ results = run_model_inference("<CAPTION>",None,test_image)
95
+ print(results)
96
+ ```
97
+ Results
98
+ ```
99
+ <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.'
100
+ ```
101
+ ***Task-2 CAPTION_DETAILS***
102
+ ```
103
+ results = run_model_inference("<CAPTION_DETAILS>",None,test_image)
104
+ print(results)
105
+ ```
106
+ Results
107
+ ```
108
+ <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.
109
+ ```
110
+ ***Task-3 REGION_OF_INTEREST***
111
+ ```
112
+ results = run_model_inference("<REGION_OF_INTEREST>",None,test_image)
113
+ print(results)
114
+ ```
115
+ Results
116
+ ```
117
+ <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.
118
+ ```
119
+ ***Task-4 OBSERVATION***
120
+ ```
121
+ results = run_model_inference("<REGION_OF_INTEREST>",None,test_image)
122
+ print(results)
123
+ ```
124
+ Results
125
+ ```
126
+ <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.
127
+ ```
128
 
129
  ### Testing Data, Factors & Metrics
130