Skip to content

Commit 0ab98bc

Browse files
authored
Update Pathology Pipelines for MetaTensor Changes (#905)
* Update tumor detection pipeline Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update MIL pipeline for MetaTensor changes Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
1 parent de12b79 commit 0ab98bc

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

pathology/multiple_instance_learning/panda_mil_train_evaluate_pytorch_gpu.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
RandGridPatchd,
2525
RandRotate90d,
2626
ScaleIntensityRanged,
27+
SplitDimd,
2728
ToTensord,
2829
)
2930
from sklearn.metrics import cohen_kappa_score
@@ -235,9 +236,10 @@ def list_data_collate(batch: collections.abc.Sequence):
235236
"""
236237

237238
for i, item in enumerate(batch):
239+
# print(f"{i} = {item['image'].shape=} >> {item['image'].keys=}")
238240
data = item[0]
239241
data["image"] = torch.stack([ix["image"] for ix in item], dim=0)
240-
data["patch_location"] = torch.stack([ix["patch_location"] for ix in item], dim=0)
242+
# data["patch_location"] = torch.stack([ix["patch_location"] for ix in item], dim=0)
241243
batch[i] = data
242244
return default_collate(batch)
243245

@@ -289,6 +291,7 @@ def main_worker(gpu, args):
289291
pad_mode=None,
290292
constant_values=255,
291293
),
294+
SplitDimd(keys=["image"], dim=0, keepdim=False, list_output=True),
292295
RandFlipd(keys=["image"], spatial_axis=0, prob=0.5),
293296
RandFlipd(keys=["image"], spatial_axis=1, prob=0.5),
294297
RandRotate90d(keys=["image"], prob=0.5),
@@ -308,6 +311,7 @@ def main_worker(gpu, args):
308311
pad_mode=None,
309312
constant_values=255,
310313
),
314+
SplitDimd(keys=["image"], dim=0, keepdim=False, list_output=True),
311315
ScaleIntensityRanged(keys=["image"], a_min=np.float32(255), a_max=np.float32(0)),
312316
ToTensord(keys=["image", "label"]),
313317
]

pathology/tumor_detection/ignite/camelyon_train_evaluate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def train(cfg):
115115
# Create MONAI dataset
116116
train_data_list = CSVDataset(
117117
cfg["train_file"],
118-
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
118+
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
119119
kwargs_read_csv={"header": None},
120120
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
121121
)
@@ -129,7 +129,7 @@ def train(cfg):
129129

130130
valid_data_list = CSVDataset(
131131
cfg["valid_file"],
132-
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
132+
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
133133
kwargs_read_csv={"header": None},
134134
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
135135
)

pathology/tumor_detection/ignite/camelyon_train_evaluate_nvtx_profiling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def train(cfg):
117117
# Create MONAI dataset
118118
train_data_list = CSVDataset(
119119
cfg["train_file"],
120-
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
120+
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
121121
kwargs_read_csv={"header": None},
122122
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
123123
)
@@ -131,7 +131,7 @@ def train(cfg):
131131

132132
valid_data_list = CSVDataset(
133133
cfg["valid_file"],
134-
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
134+
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
135135
kwargs_read_csv={"header": None},
136136
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
137137
)

pathology/tumor_detection/torch/camelyon_train_evaluate_pytorch_gpu.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def main(cfg):
308308
# Create train dataset and dataloader
309309
train_data_list = CSVDataset(
310310
cfg["train_file"],
311-
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
311+
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
312312
kwargs_read_csv={"header": None},
313313
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
314314
)
@@ -327,7 +327,7 @@ def main(cfg):
327327
if not cfg["no_validate"]:
328328
valid_data_list = CSVDataset(
329329
cfg["valid_file"],
330-
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
330+
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
331331
kwargs_read_csv={"header": None},
332332
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
333333
)
@@ -361,7 +361,7 @@ def main(cfg):
361361
# Deep Learning Model and Configurations
362362
# -------------------------------------------------------------------------
363363
# Initialize model
364-
model = TorchVisionFCModel("resnet18", n_classes=1, use_conv=True, pretrained=cfg["pretrain"])
364+
model = TorchVisionFCModel("resnet18", num_classes=1, use_conv=True, pretrained=cfg["pretrain"])
365365
model = model.to(device)
366366

367367
# Loss function

0 commit comments

Comments
 (0)