Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 3d_segmentation/spleen_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
" RandCropByPosNegLabeld(\n",
Expand Down Expand Up @@ -318,7 +318,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
" ]\n",
Expand Down Expand Up @@ -690,7 +690,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
")\n",
"\n",
Expand Down Expand Up @@ -784,7 +784,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
")\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/spleen_segmentation_3d_lightning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" # randomly crop out patch samples from\n",
" # big image based on pos / neg ratio\n",
" # the image centers of negative samples\n",
Expand Down Expand Up @@ -321,7 +321,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
" )\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
" RandCropByPosNegLabeld(\n",
Expand Down Expand Up @@ -351,7 +351,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
" ]\n",
Expand Down Expand Up @@ -782,7 +782,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
")\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/swin_unetr_brats21_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
" keys=[\"image\", \"label\"],\n",
" source_key=\"image\",\n",
" k_divisible=[roi[0], roi[1], roi[2]],\n",
" allow_smaller=True,\n",
" ),\n",
" transforms.RandSpatialCropd(\n",
" keys=[\"image\", \"label\"],\n",
Expand Down Expand Up @@ -467,7 +468,6 @@
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
"\n",
"model = SwinUNETR(\n",
" img_size=roi,\n",
" in_channels=4,\n",
" out_channels=3,\n",
" feature_size=48,\n",
Expand Down
5 changes: 2 additions & 3 deletions 3d_segmentation/swin_unetr_btcv_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(\n",
" keys=[\"image\", \"label\"],\n",
Expand Down Expand Up @@ -292,7 +292,7 @@
" [\n",
" LoadImaged(keys=[\"image\", \"label\"], ensure_channel_first=True),\n",
" ScaleIntensityRanged(keys=[\"image\"], a_min=-175, a_max=250, b_min=0.0, b_max=1.0, clip=True),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(\n",
" keys=[\"image\", \"label\"],\n",
Expand Down Expand Up @@ -439,7 +439,6 @@
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
"\n",
"model = SwinUNETR(\n",
" img_size=(96, 96, 96),\n",
" in_channels=1,\n",
" out_channels=14,\n",
" feature_size=48,\n",
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/unetr_btcv_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" RandCropByPosNegLabeld(\n",
" keys=[\"image\", \"label\"],\n",
" label_key=\"label\",\n",
Expand Down Expand Up @@ -277,7 +277,7 @@
" mode=(\"bilinear\", \"nearest\"),\n",
" ),\n",
" ScaleIntensityRanged(keys=[\"image\"], a_min=-175, a_max=250, b_min=0.0, b_max=1.0, clip=True),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
")"
]
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/unetr_btcv_segmentation_3d_lightning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(\n",
" keys=[\"image\", \"label\"],\n",
Expand Down Expand Up @@ -522,7 +522,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(\n",
" keys=[\"image\", \"label\"],\n",
Expand Down
4 changes: 2 additions & 2 deletions acceleration/automatic_mixed_precision.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" # pre-compute foreground and background indexes\n",
" # and cache them to accelerate training\n",
" FgBgToIndicesd(\n",
Expand Down Expand Up @@ -241,7 +241,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
" )\n",
" return train_transforms, val_transforms"
Expand Down
4 changes: 2 additions & 2 deletions acceleration/dataset_type_performance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" # randomly crop out patch samples from big\n",
" # image based on pos / neg ratio\n",
" # the image centers of negative samples\n",
Expand Down Expand Up @@ -420,7 +420,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
" )\n",
" return train_transforms, val_transforms"
Expand Down
4 changes: 2 additions & 2 deletions acceleration/fast_training_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
" clip=True,\n",
" ),\n",
" ),\n",
" range_func(\"CropForeground\", CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\")),\n",
" range_func(\"CropForeground\", CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True)),\n",
" # pre-compute foreground and background indexes\n",
" # and cache them to accelerate training\n",
" range_func(\n",
Expand Down Expand Up @@ -368,7 +368,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
" if fast:\n",
" # convert the data to Tensor without meta, move to GPU and cache to avoid CPU -> GPU sync in every epoch\n",
Expand Down
7 changes: 6 additions & 1 deletion auto3dseg/docs/algorithm_generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ class DintsAlgo(BundleAlgo):
"b_max": 1.0,
"clip": True,
},
{"_target_": "CropForegroundd", "keys": ["@image_key", "@label_key"], "source_key": "@image_key"},
{
"_target_": "CropForegroundd",
"keys": ["@image_key", "@label_key"],
"source_key": "@image_key",
"allow_smaller:" True,
},
],
}

Expand Down
9 changes: 8 additions & 1 deletion auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ def __init__(
source_key="image",
box_size=[200, 200, 310],
allow_missing_keys=True,
allow_smaller=True,
**kwargs,
) -> None:
super().__init__(keys=keys, source_key=source_key, allow_missing_keys=allow_missing_keys, **kwargs)
super().__init__(
keys=keys,
source_key=source_key,
allow_missing_keys=allow_missing_keys,
allow_smaller=allow_smaller,
**kwargs,
)
self.box_size = box_size

def __call__(self, data, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion bundle/python_bundle_workflow/scripts/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class InferenceWorkflow(BundleWorkflow):
"""

def __init__(self, dataset_dir: str = "./infer"):
super().__init__(workflow="inference")
super().__init__(workflow_type="inference")
print_config()
# set root log level to INFO and init a evaluation logger, will be used in `StatsHandler`
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
Expand Down
2 changes: 1 addition & 1 deletion bundle/python_bundle_workflow/scripts/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TrainWorkflow(BundleWorkflow):
"""

def __init__(self, dataset_dir: str = "./train"):
super().__init__(workflow="train")
super().__init__(workflow_type="train")
print_config()
# set root log level to INFO and init a train logger, will be used in `StatsHandler`
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
Expand Down
6 changes: 1 addition & 5 deletions bundle/pythonic_usage_guidance/pythonic_bundle_access.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Here we specify `return_state_dict=False` to return an instantiated model only for compatibility, will remove after MONAI v1.5.\n",
"# directly get an instantiated network that loaded the weights.\n",
"model = load(name=\"brats_mri_segmentation\", bundle_dir=root_dir, source=\"monaihosting\", return_state_dict=False)\n",
"model = load(name=\"brats_mri_segmentation\", bundle_dir=root_dir, source=\"monaihosting\")\n",
"\n",
"# directly update the parameters for the model from the bundle.\n",
"model = load(\n",
Expand All @@ -408,7 +406,6 @@
" source=\"monaihosting\",\n",
" in_channels=3,\n",
" out_channels=1,\n",
" return_state_dict=False,\n",
")\n",
"\n",
"# using `exclude_vars` to filter loading weights.\n",
Expand All @@ -417,7 +414,6 @@
" bundle_dir=root_dir,\n",
" source=\"monaihosting\",\n",
" copy_model_args={\"exclude_vars\": \"convInit|conv_final\"},\n",
" return_state_dict=False,\n",
")\n",
"\n",
"# pass model and return an instantiated network that loaded the weights.\n",
Expand Down
2 changes: 1 addition & 1 deletion deepgrow/ignite/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_pre_transforms(roi_size, model_size, dimensions):
t = [
LoadImaged(keys=("image", "label")),
EnsureChannelFirstd(keys=("image", "label"), channel_dim="no_channel"),
SpatialCropForegroundd(keys=("image", "label"), source_key="label", spatial_size=roi_size),
SpatialCropForegroundd(keys=("image", "label"), source_key="label", spatial_size=roi_size, allow_smaller=True),
Resized(keys=("image", "label"), spatial_size=model_size, mode=("area", "nearest")),
NormalizeIntensityd(keys="image", subtrahend=208.0, divisor=388.0),
]
Expand Down
2 changes: 1 addition & 1 deletion deployment/Triton/models/monai_covid/1/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def initialize(self, args):
LoadImage(reader="NibabelReader", image_only=True, dtype=np.float32),
EnsureChannelFirst(channel_dim="no_channel"),
ScaleIntensityRange(a_min=-1000, a_max=500, b_min=0.0, b_max=1.0, clip=True),
CropForeground(margin=5),
CropForeground(margin=5, allow_smaller=True),
Resize([192, 192, 64], mode="area"),
EnsureChannelFirst(channel_dim="no_channel"),
ToTensor(),
Expand Down
4 changes: 2 additions & 2 deletions experiment_management/spleen_segmentation_aim.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" RandCropByPosNegLabeld(\n",
" keys=[\"image\", \"label\"],\n",
" label_key=\"label\",\n",
Expand Down Expand Up @@ -285,7 +285,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
")"
]
Expand Down
4 changes: 2 additions & 2 deletions experiment_management/spleen_segmentation_mlflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" RandCropByPosNegLabeld(\n",
" keys=[\"image\", \"label\"],\n",
" label_key=\"label\",\n",
Expand Down Expand Up @@ -283,7 +283,7 @@
" b_max=1.0,\n",
" clip=True,\n",
" ),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" ]\n",
")"
]
Expand Down
1 change: 0 additions & 1 deletion model_zoo/transfer_learning_with_bundle/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
AsDiscrete,
AsDiscreted,
Compose,
CropForegroundd,
EnsureChannelFirstd,
Invertd,
LoadImaged,
Expand Down
4 changes: 0 additions & 4 deletions model_zoo/transfer_learning_with_bundle/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@
from monai.transforms import (
Activations,
AsDiscrete,
AsDiscreted,
Compose,
CropForegroundd,
EnsureChannelFirstd,
Invertd,
LoadImaged,
Orientationd,
RandCropByPosNegLabeld,
SaveImaged,
ScaleIntensityRanged,
Spacingd,
)
Expand Down
4 changes: 2 additions & 2 deletions modules/dynunet_pipeline/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def __init__(
self.mean = normalize_values[0]
self.std = normalize_values[1]
self.training = False
self.crop_foreg = CropForegroundd(keys=["image", "label"], source_key="image")
self.crop_foreg = CropForegroundd(keys=["image", "label"], source_key="image", allow_smaller=True)
self.normalize_intensity = NormalizeIntensity(nonzero=True, channel_wise=True)
if model_mode in ["train"]:
self.training = True
Expand Down Expand Up @@ -310,7 +310,7 @@ def __call__(self, data):
image, label = cropped_data["image"], cropped_data["label"]
else:
d["original_shape"] = np.array(image.shape[1:])
box_start, box_end = generate_spatial_bounding_box(image)
box_start, box_end = generate_spatial_bounding_box(image, allow_smaller=True)
image = SpatialCrop(roi_start=box_start, roi_end=box_end)(image)
d["bbox"] = np.vstack([box_start, box_end])
d["crop_shape"] = np.array(image.shape[1:])
Expand Down
2 changes: 1 addition & 1 deletion modules/integrate_3rd_party_transforms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
" ScaleIntensityRanged(keys=[\"image\"], a_min=-57, a_max=164, b_min=0.0, b_max=1.0, clip=True),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
" EnsureTyped(keys=[\"image\", \"label\"], data_type=\"numpy\"),\n",
"]"
]
Expand Down
Loading
Loading