Skip to content

Fix evaluation in HoVerNet tutorial #1127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
04e79ed
Merge remote-tracking branch 'origin/main' into main
KumoLiu Jul 21, 2022
4c2b7b3
Merge remote-tracking branch 'origin/main' into main
KumoLiu Jul 22, 2022
078a770
Merge remote-tracking branch 'origin/main' into main
KumoLiu Jul 22, 2022
38de0d2
Merge remote-tracking branch 'origin/main' into main
KumoLiu Jul 25, 2022
4726117
Merge remote-tracking branch 'origin/main' into main
KumoLiu Jul 26, 2022
79dd41f
Merge remote-tracking branch 'origin/main' into main
KumoLiu Aug 6, 2022
5ac6c2d
Merge remote-tracking branch 'origin/main' into main
KumoLiu Aug 18, 2022
9138bcd
Merge remote-tracking branch 'origin/main' into main
KumoLiu Aug 22, 2022
fd6a6b1
easy-integrate-bundle-v1
KumoLiu Aug 22, 2022
58ce3ca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 22, 2022
7b69b3a
add multigpu implementation
KumoLiu Aug 23, 2022
567da73
Merge remote-tracking branch 'yliu/easy-integrate-bundle' into main
KumoLiu Aug 23, 2022
a152924
Merge remote-tracking branch 'yliu/easy-integrate-bundle' into easy-i…
KumoLiu Aug 23, 2022
e4fd544
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 23, 2022
e40cf40
Merge remote-tracking branch 'yliu/easy-integrate-bundle' into main
KumoLiu Aug 23, 2022
a4f29d1
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Sep 9, 2022
4494091
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Sep 9, 2022
1c88106
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Sep 9, 2022
82590de
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Sep 21, 2022
396edfd
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Sep 21, 2022
fbd9059
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Nov 8, 2022
2c713f6
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Dec 12, 2022
6592118
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Dec 16, 2022
5af0f34
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Dec 17, 2022
f26b216
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Dec 20, 2022
8ee00c3
Merge branch 'main' of https://github.com/Project-MONAI/tutorials int…
KumoLiu Dec 26, 2022
c51dd70
fix bug in evaluation
KumoLiu Dec 26, 2022
da4dad4
minor fix
KumoLiu Dec 28, 2022
43b0bce
add license info
KumoLiu Dec 28, 2022
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
18 changes: 16 additions & 2 deletions pathology/hovernet/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import glob
import logging
Expand All @@ -8,7 +19,9 @@
from monai.engines import SupervisedEvaluator
from monai.transforms import (
LoadImaged,
EnsureChannelFirstd,
Lambdad,
AsDiscreted,
Activationsd,
Compose,
CastToTyped,
Expand Down Expand Up @@ -54,6 +67,7 @@ def run(cfg):
val_transforms = Compose(
[
LoadImaged(keys=["image", "label_inst", "label_type"], image_only=True),
EnsureChannelFirstd(keys=["image", "label_inst", "label_type"], channel_dim=-1),
Lambdad(keys="label_inst", func=lambda x: measure.label(x)),
CastToTyped(keys=["image", "label_inst"], dtype=torch.int),
CenterSpatialCropd(
Expand Down Expand Up @@ -92,14 +106,14 @@ def run(cfg):
post_process_np = Compose(
[
Activationsd(keys=HoVerNetBranch.NP.value, softmax=True),
Lambdad(keys=HoVerNetBranch.NP.value, func=lambda x: x[1:2, ...] > 0.5),
AsDiscreted(keys=HoVerNetBranch.NP.value, argmax=True),
]
)
post_process = Lambdad(keys="pred", func=post_process_np)

# Evaluator
val_handlers = [
CheckpointLoader(load_path=cfg["ckpt"], load_dict={"net": model}),
CheckpointLoader(load_path=cfg["ckpt"], load_dict={"model": model}),
StatsHandler(output_transform=lambda x: None),
]
evaluator = SupervisedEvaluator(
Expand Down
14 changes: 12 additions & 2 deletions pathology/hovernet/inference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import time
from argparse import ArgumentParser
from glob import glob

Expand Down Expand Up @@ -176,7 +186,7 @@ def main():
parser.add_argument(
"--root",
type=str,
default="/workspace/Data/Pathology/CoNSeP/Test/Images",
default="/workspace/Data/CoNSeP/Test/Images",
help="Images root dir",
)
parser.add_argument("--output", type=str, default="./eval/", dest="output", help="log directory")
Expand Down
11 changes: 11 additions & 0 deletions pathology/hovernet/prepare_patches.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import glob
import math
import os
Expand Down
12 changes: 11 additions & 1 deletion pathology/hovernet/training.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import glob
import time
import logging
import torch
import numpy as np
Expand Down