Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
28 changes: 18 additions & 10 deletions auto3dseg/algorithm_templates/swinunetr/scripts/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,24 +640,29 @@ def run(config_file: Optional[Union[str, Sequence[str]]] = None, **override):
metric = metric.tolist()
if torch.cuda.device_count() == 1 or dist.get_rank() == 0:
for _c in range(metric_dim):
logger.debug(f"Evaluation metric - class {_c + 1}: {metric[2 * _c] / metric[2 * _c + 1]}")
if metric[2 * _c +1] == 0:
logger.debug(f"Warning: class {_c + 1} has no samples in validation fold, skipping.")
logger.debug(f"Evaluation metric - class {_c + 1}: {metric[2 * _c] / metric[2 * _c + 1] if metric[2 * _c + 1] != 0 else float('nan')}")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
try:
writer.add_scalar(
f"val_class/acc_{class_names[_c]}", metric[2 * _c] / metric[2 * _c + 1], epoch
f"val_class/acc_{class_names[_c]}", metric[2 * _c] / metric[2 * _c + 1]if metric[2 * _c + 1] != 0 else float('nan'), epoch
)
mlflow.log_metric(
f"val_class/acc_{class_names[_c]}", metric[2 * _c] / metric[2 * _c + 1], step=epoch
f"val_class/acc_{class_names[_c]}", metric[2 * _c] / metric[2 * _c + 1]if metric[2 * _c + 1] != 0 else float('nan'), step=epoch
)
except BaseException:
writer.add_scalar(f"val_class/acc_{_c}", metric[2 * _c] / metric[2 * _c + 1], epoch)
writer.add_scalar(f"val_class/acc_{_c}", metric[2 * _c] / metric[2 * _c + 1]if metric[2 * _c + 1] != 0 else float('nan'), epoch)
mlflow.log_metric(
f"val_class/acc_{_c}", metric[2 * _c] / metric[2 * _c + 1], step=epoch
f"val_class/acc_{_c}", metric[2 * _c] / metric[2 * _c + 1]if metric[2 * _c + 1] != 0 else float('nan'), step=epoch
)

avg_metric = 0
count = 0
for _c in range(metric_dim):
avg_metric += metric[2 * _c] / metric[2 * _c + 1]
avg_metric = avg_metric / float(metric_dim)
if metric[2 * _c + 1] != 0:
avg_metric += metric[2 * _c] / metric[2 * _c + 1]
count +=1
avg_metric = avg_metric / float(count)
Comment thread
daxellwells marked this conversation as resolved.
Outdated
logger.debug(f"Avg_metric: {avg_metric}")

writer.add_scalar("val/acc", avg_metric, epoch)
Expand Down Expand Up @@ -801,13 +806,16 @@ def run(config_file: Optional[Union[str, Sequence[str]]] = None, **override):
if torch.cuda.device_count() == 1 or dist.get_rank() == 0:
for _c in range(metric_dim):
logger.debug(
f"Evaluation metric at original resolution - class {_c + 1}: {metric[2 * _c] / metric[2 * _c + 1]}"
f"Evaluation metric at original resolution - class {_c + 1}: {metric[2 * _c] / metric[2 * _c + 1] if metric[2 * _c + 1] != 0 else float('nan')}"
)

avg_metric = 0
count = 0
for _c in range(metric_dim):
avg_metric += metric[2 * _c] / metric[2 * _c + 1]
avg_metric = avg_metric / float(metric_dim)
if metric[2 * _c + 1] != 0:
avg_metric += metric[2 * _c] / metric[2 * _c + 1]
count += 1
avg_metric = avg_metric / float(count)
logger.debug(f"Avg_metric at original resolution: {avg_metric}")

with open(os.path.join(ckpt_path, "progress.yaml"), "r") as out_file:
Expand Down
3 changes: 2 additions & 1 deletion auto3dseg/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "0.0.8",
"version": "0.0.9",
"changelog": {
"0.0.9": "Fix ZeroDivisionError in swinunetr training script for missing classes in validation fold.",
"0.0.8": "Update swin unetr pretrained weights link",
"0.0.7": "Add support for MLFlow experiment name.",
"0.0.6": "Move metadata.json under 'configs' to be consistent with bundles.",
Expand Down