Skip to content

Commit

Permalink
auto updates (#294)
Browse files Browse the repository at this point in the history
Signed-off-by: monai-bot <[email protected]>

Signed-off-by: monai-bot <[email protected]>
  • Loading branch information
monai-bot authored Aug 7, 2023
1 parent 7306d8d commit d02865b
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 97 deletions.
108 changes: 54 additions & 54 deletions prostate-mri-lesion-seg/LICENSE
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
Prostate-MRI_Lesion_Detection, v2.0 (Release date: August 2, 2023)
• DEFINITIONS: AUTHOR(S) NVIDIA Corp. and National Cancer Institute, NIH
• PROVIDER: the National Cancer Institute (NCI), a participating institute of the
National Institutes of Health (NIH), and an agency of the United States Government.
• SOFTWARE: the machine readable, binary, object code form,
and the related documentation for the modules of the Prostate-MRI_Lesion_Detection, v2.0
software package, which is a collection of operators which accept (T2, ADC, and High
b-value DICOM images) and produce prostate organ and lesion segmentation files
• RECIPIENT: the party that downloads the software.
By downloading or otherwise receiving the SOFTWARE, RECIPIENT may
use and/or redistribute the SOFTWARE, with or without modification,
subject to RECIPIENT’s agreement to the following terms:
1. THE SOFTWARE SHALL NOT BE USED IN THE TREATMENT OR DIAGNOSIS
OF HUMAN SUBJECTS. RECIPIENT is responsible for
compliance with all laws and regulations applicable to the use
of the SOFTWARE.
2. THE SOFTWARE is distributed for NON-COMMERCIAL RESEARCH PURPOSES ONLY. RECIPIENT is
responsible for appropriate-use compliance.
3. RECIPIENT agrees to acknowledge PROVIDER’s contribution and
the name of the author of the SOFTWARE in all written publications
containing any data or information regarding or resulting from use
of the SOFTWARE.
4. THE SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE PROVIDER OR THE INDIVIDUAL DEVELOPERS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
5. RECIPIENT agrees not to use any trademarks, service marks, trade names,
logos or product names of NVIDIA, NCI or NIH to endorse or promote products derived
from the SOFTWARE without specific, prior and written permission.
6. For sake of clarity, and not by way of limitation, RECIPIENT may add its
own copyright statement to its modifications or derivative works of the SOFTWARE
and may provide additional or different license terms and conditions in its
sublicenses of modifications or derivative works of the SOFTWARE provided that
RECIPIENT’s use, reproduction, and distribution of the SOFTWARE otherwise complies
with the conditions stated in this Agreement. Whenever Recipient distributes or
redistributes the SOFTWARE, a copy of this Agreement must be included with
each copy of the SOFTWARE.
Prostate-MRI_Lesion_Detection, v2.0 (Release date: August 2, 2023)
• DEFINITIONS: AUTHOR(S) NVIDIA Corp. and National Cancer Institute, NIH

• PROVIDER: the National Cancer Institute (NCI), a participating institute of the
National Institutes of Health (NIH), and an agency of the United States Government.

• SOFTWARE: the machine readable, binary, object code form,
and the related documentation for the modules of the Prostate-MRI_Lesion_Detection, v2.0
software package, which is a collection of operators which accept (T2, ADC, and High
b-value DICOM images) and produce prostate organ and lesion segmentation files

• RECIPIENT: the party that downloads the software.

By downloading or otherwise receiving the SOFTWARE, RECIPIENT may
use and/or redistribute the SOFTWARE, with or without modification,
subject to RECIPIENT’s agreement to the following terms:

1. THE SOFTWARE SHALL NOT BE USED IN THE TREATMENT OR DIAGNOSIS
OF HUMAN SUBJECTS. RECIPIENT is responsible for
compliance with all laws and regulations applicable to the use
of the SOFTWARE.

2. THE SOFTWARE is distributed for NON-COMMERCIAL RESEARCH PURPOSES ONLY. RECIPIENT is
responsible for appropriate-use compliance.

3. RECIPIENT agrees to acknowledge PROVIDER’s contribution and
the name of the author of the SOFTWARE in all written publications
containing any data or information regarding or resulting from use
of the SOFTWARE.

4. THE SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE PROVIDER OR THE INDIVIDUAL DEVELOPERS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.

5. RECIPIENT agrees not to use any trademarks, service marks, trade names,
logos or product names of NVIDIA, NCI or NIH to endorse or promote products derived
from the SOFTWARE without specific, prior and written permission.

6. For sake of clarity, and not by way of limitation, RECIPIENT may add its
own copyright statement to its modifications or derivative works of the SOFTWARE
and may provide additional or different license terms and conditions in its
sublicenses of modifications or derivative works of the SOFTWARE provided that
RECIPIENT’s use, reproduction, and distribution of the SOFTWARE otherwise complies
with the conditions stated in this Agreement. Whenever Recipient distributes or
redistributes the SOFTWARE, a copy of this Agreement must be included with
each copy of the SOFTWARE.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Prostate-MRI_Lesion_Detection, v2.0 (Release date: August 2, 2023)
DEFINITIONS: AUTHOR(S) NVIDIA Corp. and National Cancer Institute, NIH
Expand Down Expand Up @@ -52,7 +52,7 @@
RECIPIENT’s use, reproduction, and distribution of the SOFTWARE otherwise complies
with the conditions stated in this Agreement. Whenever Recipient distributes or
redistributes the SOFTWARE, a copy of this Agreement must be included with
each copy of the SOFTWARE.'''
each copy of the SOFTWARE."""

from app import AIProstateLesionSegApp

Expand Down
30 changes: 20 additions & 10 deletions prostate-mri-lesion-seg/prostate_mri_lesion_seg_app/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Prostate-MRI_Lesion_Detection, v2.0 (Release date: August 2, 2023)
DEFINITIONS: AUTHOR(S) NVIDIA Corp. and National Cancer Institute, NIH
Expand Down Expand Up @@ -52,20 +52,21 @@
RECIPIENT’s use, reproduction, and distribution of the SOFTWARE otherwise complies
with the conditions stated in this Agreement. Whenever Recipient distributes or
redistributes the SOFTWARE, a copy of this Agreement must be included with
each copy of the SOFTWARE.'''
each copy of the SOFTWARE."""

import logging

from custom_lesion_seg_operator import CustomProstateLesionSegOperator

# Local imports
from organ_seg_operator import ProstateSegOperator

# MONAI Deploy SDK imports
from monai.deploy.core import Application, resource
from monai.deploy.operators.dicom_data_loader_operator import DICOMDataLoaderOperator
from monai.deploy.operators.dicom_series_selector_operator import DICOMSeriesSelectorOperator
from monai.deploy.operators.dicom_series_to_volume_operator import DICOMSeriesToVolumeOperator

# Local imports
from organ_seg_operator import ProstateSegOperator
from custom_lesion_seg_operator import CustomProstateLesionSegOperator

# This is a sample series selection rule in JSON, simply selecting MRI series.
# Please see more details in DICOMSeriesSelectorOperator.
# Sample_Rules_Text = """
Expand Down Expand Up @@ -140,6 +141,7 @@
}
"""


@resource(cpu=1, gpu=1, memory="7Gi")
class AIProstateLesionSegApp(Application):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -178,10 +180,17 @@ def compose(self):
self.add_flow(study_loader_op, series_selector_T2_op, {"dicom_study_list": "dicom_study_list"})
self.add_flow(study_loader_op, series_selector_ADC_op, {"dicom_study_list": "dicom_study_list"})
self.add_flow(study_loader_op, series_selector_HIGHB_op, {"dicom_study_list": "dicom_study_list"})
self.add_flow(series_selector_T2_op, series_to_vol_T2_op, {"study_selected_series_list": "study_selected_series_list"})
self.add_flow(series_selector_ADC_op, series_to_vol_ADC_op, {"study_selected_series_list": "study_selected_series_list"})
self.add_flow(series_selector_HIGHB_op, series_to_vol_HIGHB_op, {"study_selected_series_list": "study_selected_series_list"})

self.add_flow(
series_selector_T2_op, series_to_vol_T2_op, {"study_selected_series_list": "study_selected_series_list"}
)
self.add_flow(
series_selector_ADC_op, series_to_vol_ADC_op, {"study_selected_series_list": "study_selected_series_list"}
)
self.add_flow(
series_selector_HIGHB_op,
series_to_vol_HIGHB_op,
{"study_selected_series_list": "study_selected_series_list"},
)

# Organ inference
self.add_flow(series_to_vol_T2_op, organ_seg_op, {"image": "image"})
Expand All @@ -195,6 +204,7 @@ def compose(self):

self._logger.debug(f"End {self.compose.__name__}")


if __name__ == "__main__":
# Creates the app and test it standalone. When running is this mode, please note the following:
# -i <DICOM folder>, for input DICOM CT series folder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Prostate-MRI_Lesion_Detection, v2.0 (Release date: August 2, 2023)
DEFINITIONS: AUTHOR(S) NVIDIA Corp. and National Cancer Institute, NIH
Expand Down Expand Up @@ -52,31 +52,33 @@
RECIPIENT’s use, reproduction, and distribution of the SOFTWARE otherwise complies
with the conditions stated in this Agreement. Whenever Recipient distributes or
redistributes the SOFTWARE, a copy of this Agreement must be included with
each copy of the SOFTWARE.'''
each copy of the SOFTWARE."""

import os
import copy
import logging
import os
from typing import Optional

import nibabel as nib
import numpy as np

# AI/CV imports
import SimpleITK as sitk
import torch

# Local imports
from network import RRUNet3D
from skimage.transform import resize
from torch.utils.data import Dataset

# MONAI Deploy App SDK imports
import monai.deploy.core as md
from monai.deploy.core import ExecutionContext, Image, InputContext, IOType, Operator, OutputContext

# MONAI imports
from monai.data import MetaTensor
from monai.deploy.core import ExecutionContext, Image, InputContext, IOType, Operator, OutputContext
from monai.transforms import SaveImage

# AI/CV imports
import SimpleITK as sitk
from skimage.transform import resize
import nibabel as nib
import torch
from torch.utils.data import Dataset

# Local imports
from network import RRUNet3D

def bbox2_3D(img):
r = np.any(img, axis=(1, 2))
Expand All @@ -89,6 +91,7 @@ def bbox2_3D(img):

return [rmin, rmax, cmin, cmax, zmin, zmax]


def standard_normalization_multi_channel(nda):
for _i in range(nda.shape[0]):
if np.amax(np.abs(nda[_i, ...])) < 1e-7:
Expand All @@ -97,6 +100,7 @@ def standard_normalization_multi_channel(nda):

return nda


class SegmentationDataset(Dataset):
def __init__(self, output_path, data_purpose):
self.data_purpose = data_purpose
Expand Down Expand Up @@ -232,14 +236,12 @@ class CustomProstateLesionSegOperator(Operator):
"""Performs Prostate Lesion segmentation with a 3D image converted from a mp-DICOM MRI series."""

def __init__(self, model_name: Optional[str] = ""):

self.logger = logging.getLogger("{}.{}".format(__name__, type(self).__name__))
super().__init__()

self._model_name = model_name.strip() if isinstance(model_name, str) else ""

def compute(self, op_input: InputContext, op_output: OutputContext, context: ExecutionContext):

output_path = context.output.get().path

# Load inputs
Expand Down Expand Up @@ -411,7 +413,6 @@ def custom_inference(self, data, inputs, inputs_shape, net, output_path, tag, mo
for rx in ranges_x:
for ry in ranges_y:
for rz in ranges_z:

output_patch = net(inputs[..., rx[0] : rx[1], ry[0] : ry[1], rz[0] : rz[1]])
output_patch = output_patch.cpu().detach().numpy()
output_patch = np.squeeze(output_patch)
Expand Down
18 changes: 7 additions & 11 deletions prostate-mri-lesion-seg/prostate_mri_lesion_seg_app/network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Prostate-MRI_Lesion_Detection, v2.0 (Release date: August 2, 2023)
DEFINITIONS: AUTHOR(S) NVIDIA Corp. and National Cancer Institute, NIH
Expand Down Expand Up @@ -52,26 +52,24 @@
RECIPIENT’s use, reproduction, and distribution of the SOFTWARE otherwise complies
with the conditions stated in this Agreement. Whenever Recipient distributes or
redistributes the SOFTWARE, a copy of this Agreement must be included with
each copy of the SOFTWARE.'''
each copy of the SOFTWARE."""

import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F

__all__ = [
"RRUNet3D"
]
__all__ = ["RRUNet3D"]


class RecurrentBlock(nn.Module):
def __init__(self, out_channels, t=2):
super(RecurrentBlock,self).__init__()
super(RecurrentBlock, self).__init__()
self.t = t
self.conv = nn.Sequential(
nn.Conv3d(out_channels, out_channels,kernel_size=3,stride=1,padding=1,bias=True),
nn.BatchNorm3d(out_channels),
nn.ReLU(inplace=True)
nn.Conv3d(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=True),
nn.BatchNorm3d(out_channels),
nn.ReLU(inplace=True),
)

def forward(self, x):
Expand Down Expand Up @@ -223,7 +221,6 @@ def __init__(
self.output_conv = nn.Conv3d(num_init_kernels, out_channels, 1, stride=1, padding=0, bias=False)
self.output_activation = nn.Softmax(dim=1)


self.blocks_down = list(map(int, blocks_down.split(",")))
self.blocks_up = list(map(int, blocks_up.split(",")))
self.blocks_up = self.blocks_up[::-1]
Expand All @@ -243,7 +240,6 @@ def __init__(
self.levels_down = len(self.blocks_down)
self.encoders = []
for _i in range(self.levels_down):

in_c = num_init_kernels * 2**_i if _i == 0 else num_init_kernels * 2 ** (_i - 1)
out_c = num_init_kernels * 2**_i
# if self.debug:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Prostate-MRI_Lesion_Detection, v2.0 (Release date: August 2, 2023)
DEFINITIONS: AUTHOR(S) NVIDIA Corp. and National Cancer Institute, NIH
Expand Down Expand Up @@ -52,7 +52,7 @@
RECIPIENT’s use, reproduction, and distribution of the SOFTWARE otherwise complies
with the conditions stated in this Agreement. Whenever Recipient distributes or
redistributes the SOFTWARE, a copy of this Agreement must be included with
each copy of the SOFTWARE.'''
each copy of the SOFTWARE."""

import logging
from os import path
Expand Down Expand Up @@ -88,15 +88,13 @@ class ProstateSegOperator(Operator):
"""Performs Prostate segmentation with a 3D image converted from a DICOM MRI (T2) series."""

def __init__(self, model_name: Optional[str] = ""):

self.logger = logging.getLogger("{}.{}".format(__name__, type(self).__name__))
super().__init__()
self._input_dataset_key = "image"
self._pred_dataset_key = "label"
self._model_name = model_name.strip() if isinstance(model_name, str) else ""

def compute(self, op_input: InputContext, op_output: OutputContext, context: ExecutionContext):

input_image = op_input.get("image")
if not input_image:
raise ValueError("Input image is not found.")
Expand Down

0 comments on commit d02865b

Please sign in to comment.