Skip to content

Commit fa7c06a

Browse files
slbrysonpre-commit-ci[bot]wyli
authored
slbryson/update Triton MedNIST demo (#926)
* 925 Update Triton Signed-off-by: Sidney L. Bryson <[email protected]> * 925 Update to monai 1.0.0rc1 Signed-off-by: Sidney L. Bryson <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Signed-off-by: Sidney L. Bryson <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Wenqi Li <[email protected]>
1 parent f6b9257 commit fa7c06a

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

deployment/Triton/README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,18 @@ $ pip install nvidia-pyindex
9696
$ pip install tritonclient[all]
9797
```
9898
5. Run the client program
99-
The [client](./client/client.py) program will take an optional file input and perform classification to determine whether the study shows COVID-19 or not COVID-19. See the [NVIDIA COVID-19 Classification ](https://ngc.nvidia.com/catalog/models/nvidia:med:clara_pt_covid19_3d_ct_classification) example in NGC for more background.
99+
The [client](./client/client_mednist.py) program will take an optional file input and perform classification on body parts using the MedNIST data set. A small subset of the database is included.
100100
```
101-
$ python -u client/client.py [filename/directory]
101+
$ mkdir -p client/test_data/MedNist
102+
$ python -u client/client_mednist.py client/test_data/MedNist
102103
```
103-
and the program returns
104-
``` Default input for the client is client/test_data/prostate_24.nii.gz
105-
$ Classification result: ['Prostate segmented']
104+
Alternatively, the user can just run the shell script provided the previous steps 1 -4 in the [Quick Start](#quick-start) were followed.
106105
```
106+
$ ./mednist_client_run.sh
107+
```
108+
The expected result is variety of classification results for body images and local inference times.
109+
```
110+
107111
## Examples:
108112
The example demonstrates running a Triton Python Backend on a single image classification problem.
109113
1. First, a Dockerfile and build script is used to build a container to Run the Triton Service and copy the model specific files in the container.
@@ -171,7 +175,7 @@ filename = 'client/test_data/volume-covid19-A-0000.nii.gz'
171175
```
172176
- The client calls the Triton Service using the external port configured previously.
173177
```python:
174-
with httpclient.InferenceServerClient("localhost:7555") as client:
178+
with httpclient.InferenceServerClient("localhost:8000") as client:
175179
```
176180
- The Triton inference response is returned :
177181
```python:
@@ -199,6 +203,18 @@ $ ./mednist_client_run.sh
199203
```
200204
The expected result is variety of classification results for body images and local inference times.
201205

206+
## Notes about the `requirements.txt` file and installed CUDA Drivers
207+
- The requirements.txt file is used to place requirements into the Triton Server Container, but also for the client environment.
208+
- Take care with the version of PyTorch (torch) used based on the specific GPU and installed driver versions. The --extra-index-url flag may need to be modified to correspond with the CUDA version installed on the local GPU.
209+
- Determine your driver and CUDA version with the following command:
210+
```
211+
nvidia-smi
212+
```
213+
- Then choose the appropriate library to load for PyTorch by adding the helper flag in the `requirements.txt` file.
214+
```
215+
--extra-index-url https://download.pytorch.org/whl/cu116
216+
```
217+
- Note: in the above example the cu116 instructs to install the latest torch version that supports CUDA 11.6
202218
-------
203219
## Usage
204220
[See Triton Inference Server/python_backend documentation](https://github.com/triton-inference-server/python_backend#usage)

deployment/Triton/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def open_nifti_files(input_path):
8585
print("No valid inputs provided")
8686
sys.exit(1)
8787

88-
with httpclient.InferenceServerClient("localhost:7555") as client:
88+
with httpclient.InferenceServerClient("localhost:8000") as client:
8989
image_bytes = b''
9090
for nifti_file in nifti_files:
9191
with open(nifti_file, 'rb') as f:

deployment/Triton/client/client_mednist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import glob
5050

5151
from monai.apps.utils import download_and_extract
52-
from monai.transforms.utils import convert_to_numpy
52+
from monai.utils.type_conversion import convert_to_numpy
5353

5454
MEDNIST_CLASSES = ["AbdomenCT", "BreastMRI", "CXR", "ChestCT", "Hand", "HeadCT"]
5555

@@ -90,7 +90,7 @@ def open_jpeg_files(input_path):
9090
print("No valid inputs provided")
9191
sys.exit(1)
9292

93-
with httpclient.InferenceServerClient("localhost:7555") as client:
93+
with httpclient.InferenceServerClient("localhost:8000") as client:
9494
image_bytes = b''
9595
for jpeg_file in jpeg_files:
9696
with open(jpeg_file, 'rb') as f:

deployment/Triton/models/monai_covid/1/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def initialize(self, args):
110110
Lambda(func=lambda x: x.to(device="cpu")),
111111
Activations(sigmoid=True),
112112
ToNumpy(),
113-
AsDiscrete(threshold_values=True, logit_thresh=0.5),
113+
AsDiscrete(threshold=True),
114114
])
115115

116116
self.inferer = SimpleInferer()

deployment/Triton/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3636
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3737
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
--extra-index-url https://download.pytorch.org/whl/cu116
3839

39-
monai==0.6.0
40+
monai==1.0.0rc1
4041
nibabel==3.2.1
4142
numpy==1.22.0;
4243
packaging==20.9

deployment/Triton/run_triton_local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ demo_app_image_name="monai_triton:class"
4141

4242
docker run \
4343
--rm \
44-
-p7555:8000 -p 8001:8001 -p 8002:8002 \
44+
-p 8000:8000 -p 8001:8001 -p 8002:8002 \
4545
--runtime=nvidia \
4646
--shm-size=1g \
4747
--ulimit memlock=-1 \

0 commit comments

Comments
 (0)