Skip to content

Commit 7e2de0e

Browse files
authored
Merge pull request #907 from MicrosoftDocs/release-preview-health-ai-models
Release preview health ai models -> main -- 10/20 - 6:00 AM PST
2 parents 6a22326 + 8be4b9d commit 7e2de0e

12 files changed

+754
-0
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
---
2+
title: How to deploy and use CXRReportGen healthcare AI model with AI Studio
3+
titleSuffix: Azure AI Studio
4+
description: Learn how to use CXRReportGen Healthcare AI Model with Azure AI Studio.
5+
ms.service: azure-ai-studio
6+
manager: scottpolly
7+
ms.topic: how-to
8+
ms.date: 10/20/2024
9+
ms.reviewer: itarapov
10+
reviewer: ivantarapov
11+
ms.author: mopeakande
12+
author: msakande
13+
#Customer intent: As a Data Scientist I want to learn how to use the CXRReportGen healthcare AI model to generate grounded findings.
14+
15+
---
16+
17+
# How to use CXRReportGen Healthcare AI model to generate grounded findings
18+
19+
[!INCLUDE [Feature preview](~/reusable-content/ce-skilling/azure/includes/ai-studio/includes/feature-preview.md)]
20+
21+
[!INCLUDE [health-ai-models-meddev-disclaimer](../../includes/health-ai-models-meddev-disclaimer.md)]
22+
23+
In this article, you learn how to deploy CXRReportGen as an online endpoint for real-time inference and issue a basic call to the API. The steps you take are:
24+
25+
* Deploy the model to a self-hosted managed compute.
26+
* Grant permissions to the endpoint.
27+
* Send test data to the model, receive, and interpret results
28+
29+
## CXRReportGen - grounded report generation model for chest X-rays
30+
Radiology reporting demands detailed image understanding, integration of multiple inputs (including comparisons with prior imaging), and precise language generation, making it an ideal candidate for generative multimodal models. CXRReportGen generates a list of findings from a chest X-ray study and also perform a _grounded report generation_ or _grounding_ task. That is, the CXRReportGen model also incorporates the localization of individual findings on the image. Grounding enhances the clarity of image interpretation and the transparency of AI-generated text, which end up improving the utility of automated report drafting.
31+
32+
The following animation demonstrates the conceptual architecture of the CXRReportGen model, which consists of an embedding model paired with a general reasoner large language model (LLM).
33+
34+
:::image type="content" source="../../media/how-to/healthcare-ai/healthcare-reportgen.gif" alt-text="Animation of CXRReportGen architecture and data flow.":::
35+
36+
The CXRReportGen model combines a radiology-specific image encoder with a large language model and takes as inputs a more comprehensive set of data than many traditional approaches. The input data includes the current frontal image, the current lateral image, the prior frontal image, the prior report, and the indication, technique, and comparison sections of the current report. These additions significantly enhance report quality and reduce incorrect information, ultimately demonstrating the feasibility of grounded reporting as a novel and richer task in automated radiology.
37+
38+
## Prerequisites
39+
40+
To use CXRReportGen model with Azure AI Studio or Azure Machine Learning studio, you need the following prerequisites:
41+
42+
### A model deployment
43+
44+
**Deployment to a self-hosted managed compute**
45+
46+
CXRReportGen model can be deployed to our self-hosted managed inference solution, which allows you to customize and control all the details about how the model is served. You can deploy the model through the model catalog UI or programmatically.
47+
48+
To __deploy the model through the UI__:
49+
50+
1. Go to the [model card in the catalog](https://aka.ms/cxrreportgenmodelcard).
51+
1. On the model's overview page, select __Deploy__.
52+
1. If given the option to choose between serverless API deployment and deployment using a managed compute, select **Managed Compute**.
53+
1. Fill out the details in the deployment window.
54+
55+
> [!NOTE]
56+
> For deployment to a self-hosted managed compute, you must have enough quota in your subscription. If you don't have enough quota available, you can use our temporary quota access by selecting the option **I want to use shared quota and I acknowledge that this endpoint will be deleted in 168 hours.**
57+
1. Select __Deploy__.
58+
59+
To __deploy the model programmatically__, see [How to deploy and inference a managed compute deployment with code](../deploy-models-managed.md).
60+
61+
62+
## Work with a grounded report generation model for chest X-ray analysis
63+
64+
In this section, you consume the model and make basic calls to it.
65+
66+
### Use REST API to consume the model
67+
68+
Consume the CXRReportGen report generation model as a REST API, using simple GET requests or by creating a client as follows:
69+
70+
```python
71+
from azure.ai.ml import MLClient
72+
from azure.identity import DeviceCodeCredential
73+
74+
credential = DefaultAzureCredential()
75+
76+
ml_client_workspace = MLClient.from_config(credential)
77+
```
78+
79+
In the deployment configuration, you get to choose the authentication method. This example uses Azure Machine Learning token-based authentication. For more authentication options, see the [corresponding documentation page](../../../machine-learning/how-to-setup-authentication.md). Also, note that the client is created from a configuration file that is created automatically for Azure Machine Learning virtual machines (VMs). Learn more on the [corresponding API documentation page](/python/api/azure-ai-ml/azure.ai.ml.mlclient#azure-ai-ml-mlclient-from-config).
80+
81+
### Make basic calls to the model
82+
83+
Once the model is deployed, use the following code to send data and retrieve a list of findings and corresponding bounding boxes.
84+
85+
```python
86+
input_data = {
87+
"frontal_image": base64.encodebytes(read_image(frontal_path)).decode("utf-8"),
88+
"lateral_image": base64.encodebytes(read_image(lateral_path)).decode("utf-8"),
89+
"indication": indication,
90+
"technique": technique,
91+
"comparison": comparison,
92+
}
93+
94+
data = {
95+
"input_data": {
96+
"columns": list(input_data.keys()),
97+
# IMPORANT: Modify the index as needed
98+
"index": [0], # 1, 2],
99+
"data": [
100+
list(input_data.values()),
101+
],
102+
}
103+
}
104+
105+
# Create request json
106+
request_file_name = "sample_request_data.json"
107+
with open(request_file_name, "w") as request_file:
108+
json.dump(data, request_file)
109+
110+
response = ml_client_workspace.online_endpoints.invoke(
111+
endpoint_name=endpoint_name,
112+
deployment_name=deployment_name,
113+
request_file=request_file_name,
114+
)
115+
```
116+
117+
## Use CXRReportGen REST API
118+
CXRReportGen model assumes a simple single-turn interaction where one request produces one response.
119+
120+
### Request schema
121+
122+
Request payload is a JSON formatted string containing the following parameters:
123+
124+
| Key | Type | Required/Default | Description |
125+
| ------------- | -------------- | :-----------------:| ----------------- |
126+
| `input_data` | `[object]` | Y | An object containing the input data payload |
127+
128+
The `input_data` object contains the following fields:
129+
130+
| Key | Type | Required/Default | Allowed values | Description |
131+
| ------------- | -------------- | :-----------------:| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132+
| `columns` | `list[string]` | Y | `"frontal_image"`, `"lateral_image"`, `"prior_image"`,`"indication"`, `"technique"`, `"comparison"`, `"prior_report"` | An object containing the strings mapping data to inputs passed to the model.|
133+
| `index` | `integer` | Y | 0 - 10 | Count of inputs passed to the model. You're limited by how much GPU RAM you have on the VM where CxrReportGen is hosted, and by how much data can be passed in a single POST request—which depends on the size of your images. Therefore, it's reasonable to keep this number under 10. Check model logs if you're getting errors when passing multiple inputs. |
134+
| `data` | `list[list[string]]` | Y | "" | The list contains the list of items passed to the model. The length of the list is defined by the index parameter. Each item is a list of several strings. The order and meaning are defined by the `columns` parameter. The text strings contain text. The image strings are the image bytes encoded using base64 and decoded as utf-8 string |
135+
136+
137+
### Request example
138+
139+
**A simple inference requesting list of findings for a single frontal image with no indication provided**
140+
```JSON
141+
{
142+
"input_data": {
143+
"columns": [
144+
"frontal_image"
145+
],
146+
"index":[0],
147+
"data": [
148+
["iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAAARnQU1BAACx\njwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAAbSURBVBhXY/gUoPS/fhfDfwaGJe///9/J8B8A\nVGwJ5VDvPeYAAAAASUVORK5CYII=\n"]
149+
]
150+
}
151+
}
152+
```
153+
154+
**More complex request passing frontal, lateral, indication and technique**
155+
```JSON
156+
{
157+
"input_data": {
158+
"columns": [
159+
"frontal_image",
160+
"lateral_image",
161+
"indication",
162+
"technique"
163+
],
164+
"index":[0],
165+
"data": [
166+
["iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAAARnQU1BAACx\njwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAAbSURBVBhXY/gUoPS/fhfDfwaGJe///9/J8B8A\nVGwJ5VDvPeYAAAAASUVORK5CYII=\n",
167+
"iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAAARnQU1BAACx\njwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAAbSURBVBhXY/gUoPS/fhfDfwaGJe///9/J8B8A\nVGwJ5VDvPeYAAAAASUVORK5CYII=\n",
168+
"Cough and wheezing for 5 months",
169+
"PA and lateral views of the chest were obtained"]
170+
]
171+
}
172+
}
173+
```
174+
175+
### Response schema
176+
177+
Response payload is a JSON formatted string containing the following fields:
178+
179+
| Key | Type | Description |
180+
| ------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
181+
| `output` | `list[list[string, list[list[float]]]]` | The list of findings. Each finding is an item in a list represented by a list that contains a string with the text of finding and a list that contains bounding boxes. Each bounding box is represented by a list of four coordinates of the bounding box related to the finding in the following order: `x_min`, `y_min`, `x_max`, `y_max`. Each coordinate value is between 0 and 1, thus to obtain coordinates in the space of the image for rendering or processing these values need to be multiplied by image width or height accordingly|
182+
183+
### Response example
184+
**A simple inference requesting embedding of a single string**
185+
```JSON
186+
{
187+
"output": [
188+
["The heart size is normal.", null],
189+
["Lungs demonstrate blunting of both costophrenic angles.", [[0.005, 0.555, 0.965, 0.865]]],
190+
["There is an area of increased radiodensity overlying the left lower lung.", [[0.555, 0.405, 0.885, 0.745]]],
191+
["Healed fractures of the left fourth, fifth, sixth, seventh, and eighth posterior ribs are noted.", [[0.585, 0.135, 0.925, 0.725]]]
192+
]
193+
}
194+
```
195+
196+
### Supported image formats
197+
198+
The deployed model API supports images encoded in PNG or JPEG formats. For optimal results, we recommend using uncompressed/lossless PNGs with 8-bit monochromatic images.
199+
200+
## Learn more from samples
201+
202+
CXRReportGen is a versatile model that can be applied to a wide range of tasks and imaging modalities. For more examples see the following interactive Python notebook:
203+
204+
* [Deploying and Using CXRReportGen](https://aka.ms/healthcare-ai-examples-cxr-deploy): Learn how to deploy the CXRReportGen model and integrate it into your workflow. This notebook also covers bounding-box parsing and visualization techniques.
205+
206+
## Related content
207+
208+
* [MedImageParse for medical image segmentation](deploy-medimageparse.md)
209+
* [MedImageInsight for grounded report generation](deploy-medimageinsight.md)

0 commit comments

Comments
 (0)