Skip to content

Commit

Permalink
add suppor t of trt inference of the pathology nuclei segmentation cl…
Browse files Browse the repository at this point in the history
…assification bundle

Signed-off-by: binliu <[email protected]>
  • Loading branch information
binliunls committed Aug 20, 2023
1 parent 1ac569b commit 934e839
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
"hovernet_mode": "fast",
"patch_size": 256,
"out_size": 164,
"non_trt_inference": true,
"use_list_output": "$not @non_trt_inference",
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
"network_def": {
"_target_": "HoVerNet",
"mode": "@hovernet_mode",
"adapt_standard_resnet": true,
"in_channels": 3,
"out_classes": 5
"out_classes": 5,
"use_list_output": "@use_list_output"
},
"network": "$@network_def.to(@device)",
"preprocessing": {
Expand Down Expand Up @@ -77,6 +80,16 @@
"postprocessing": {
"_target_": "Compose",
"transforms": [
{
"_target_": "ExtendSubKeysd",
"_disabled_": "@non_trt_inference",
"keys": "pred",
"map_names": [
"horizontal_vertical",
"nucleus_prediction",
"type_prediction"
]
},
{
"_target_": "FlattenSubKeysd",
"keys": "pred",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"imports": [
"$import glob",
"$import os",
"$import torch_tensorrt"
],
"non_trt_inference": false,
"handlers#0#_disabled_": true,
"network_def": "$torch.jit.load(@bundle_root + '/models/model_trt.ts')",
"evaluator#amp": false
}
12 changes: 12 additions & 0 deletions models/pathology_nuclei_segmentation_classification/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ python -m monai.bundle run --config_file "['configs/train.json','configs/evaluat
python -m monai.bundle run --config_file configs/inference.json
```

#### Export checkpoint to TensorRT based models with fp32 or fp16 precision:

```
python -m monai.bundle trt_export --net_id network_def --filepath models/model_trt.ts --ckpt_file models/model.pt --meta_file configs/metadata.json --config_file configs/inference.json --precision <fp32/fp16> --use_trace "True" --use_onnx "True" --dynamic_batchsize "[1, 16, 16]" --onnx_output_names "['output_0', 'output_1', 'output_2']" --use_list_output "True"
```

#### Execute inference with the TensorRT model:

```
python -m monai.bundle run --config_file "['configs/inference.json', 'configs/inference_trt.json']"
```

# References
[1] Simon Graham, Quoc Dang Vu, Shan E Ahmed Raza, Ayesha Azam, Yee Wah Tsang, Jin Tae Kwak, Nasir Rajpoot, Hover-Net: Simultaneous segmentation and classification of nuclei in multi-tissue histology images, Medical Image Analysis, 2019 https://doi.org/10.1016/j.media.2019.101563

Expand Down

0 comments on commit 934e839

Please sign in to comment.