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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
RandGridPatchd,
RandRotate90d,
ScaleIntensityRanged,
SplitDimd,
ToTensord,
)
from sklearn.metrics import cohen_kappa_score
Expand Down Expand Up @@ -235,9 +236,10 @@ def list_data_collate(batch: collections.abc.Sequence):
"""

for i, item in enumerate(batch):
# print(f"{i} = {item['image'].shape=} >> {item['image'].keys=}")
data = item[0]
data["image"] = torch.stack([ix["image"] for ix in item], dim=0)
data["patch_location"] = torch.stack([ix["patch_location"] for ix in item], dim=0)
# data["patch_location"] = torch.stack([ix["patch_location"] for ix in item], dim=0)
batch[i] = data
return default_collate(batch)

Expand Down Expand Up @@ -289,6 +291,7 @@ def main_worker(gpu, args):
pad_mode=None,
constant_values=255,
),
SplitDimd(keys=["image"], dim=0, keepdim=False, list_output=True),
RandFlipd(keys=["image"], spatial_axis=0, prob=0.5),
RandFlipd(keys=["image"], spatial_axis=1, prob=0.5),
RandRotate90d(keys=["image"], prob=0.5),
Expand All @@ -308,6 +311,7 @@ def main_worker(gpu, args):
pad_mode=None,
constant_values=255,
),
SplitDimd(keys=["image"], dim=0, keepdim=False, list_output=True),
ScaleIntensityRanged(keys=["image"], a_min=np.float32(255), a_max=np.float32(0)),
ToTensord(keys=["image", "label"]),
]
Expand Down
4 changes: 2 additions & 2 deletions pathology/tumor_detection/ignite/camelyon_train_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def train(cfg):
# Create MONAI dataset
train_data_list = CSVDataset(
cfg["train_file"],
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
kwargs_read_csv={"header": None},
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
)
Expand All @@ -129,7 +129,7 @@ def train(cfg):

valid_data_list = CSVDataset(
cfg["valid_file"],
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
kwargs_read_csv={"header": None},
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def train(cfg):
# Create MONAI dataset
train_data_list = CSVDataset(
cfg["train_file"],
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
kwargs_read_csv={"header": None},
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
)
Expand All @@ -131,7 +131,7 @@ def train(cfg):

valid_data_list = CSVDataset(
cfg["valid_file"],
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
kwargs_read_csv={"header": None},
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def main(cfg):
# Create train dataset and dataloader
train_data_list = CSVDataset(
cfg["train_file"],
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
kwargs_read_csv={"header": None},
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
)
Expand All @@ -327,7 +327,7 @@ def main(cfg):
if not cfg["no_validate"]:
valid_data_list = CSVDataset(
cfg["valid_file"],
col_groups={"image": 0, "patch_location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
col_groups={"image": 0, "location": [2, 1], "label": [3, 6, 9, 4, 7, 10, 5, 8, 11]},
kwargs_read_csv={"header": None},
transform=Lambdad("image", lambda x: os.path.join(cfg["root"], "training/images", x + ".tif")),
)
Expand Down Expand Up @@ -361,7 +361,7 @@ def main(cfg):
# Deep Learning Model and Configurations
# -------------------------------------------------------------------------
# Initialize model
model = TorchVisionFCModel("resnet18", n_classes=1, use_conv=True, pretrained=cfg["pretrain"])
model = TorchVisionFCModel("resnet18", num_classes=1, use_conv=True, pretrained=cfg["pretrain"])
model = model.to(device)

# Loss function
Expand Down