Skip to content

Instantly share code, notes, and snippets.

@clementpoiret
Created August 26, 2021 12:20
Show Gist options
  • Save clementpoiret/c257e024ffde904f4169b13ed4ed449c to your computer and use it in GitHub Desktop.
Save clementpoiret/c257e024ffde904f4169b13ed4ed449c to your computer and use it in GitHub Desktop.
Individual Metrics
import torch
import pymia.evaluation.evaluator as eval_
import pymia.evaluation.metric as metric
y = torch.randint(0, 4, (1, 16, 16, 16))
y_hat = y * .8 - 1
metrics = [
metric.DiceCoefficient(),
metric.VolumeSimilarity(),
metric.MahalanobisDistance()
]
labels = {
0: 'background',
1: 'edema',
2: 'non-enhancing tumor',
3: 'enhancing tumor'
}
evaluator = eval_.SegmentationEvaluator(metrics, labels)
evaluator.evaluate(y_hat, y, "sub00")
{
r.label.title() + " " + r.metric.title(): r.value
for r in evaluator.results
if r.label != 'background'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment