Skip to content
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

Merge util.metrics.py from CerebNet and FastSurferCNN into one file #590

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

taha-abdullah
Copy link
Contributor

  • Deleted CerebNet.utils.metrics.py and merged all functionality into FastSurferCNN.utils.metrics.py
  • refactoring usage across files
  • changed dice score implementation to numpy (tried MONAI and Ignite, didn't work out)
  • added support for multiple images in test_images
  • nested parameterization (subjects and test files) in test_images and test_stats

requirements.txt Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
.github/workflows/quicktest.yaml Outdated Show resolved Hide resolved
Copy link
Member

@dkuegler dkuegler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do another iteration on metrics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why these changes are required. I think the previous version (before your changes here) was better. It has the whole pipeline grouped into one job.

I guess the "on" variable should be uncommented :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented out the on pull requests to dev and stable. These should only be added at the very end, when everything works (if at all). Until then it should be triggered manually for testing.
Even later I think - given the computational overhead - it makes sense to trigger this only for specific pull requests, that even touch any of the files involved in testing, and not just modification to doc strings etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out trigger on pull request and changed it back to last iteration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-reuter One major disadvantage for this is that such workflows can only be triggered for branches that are part of the repository. I.e. we can no longer run them on all pull requests when we want to. At least I have not found a way to tigger them. The best solution is probably to always trigger them, but have a label in the PR that needs to be set to actually run this workflow.

FastSurferCNN/utils/metrics.py Outdated Show resolved Hide resolved
FastSurferCNN/utils/metrics.py Outdated Show resolved Hide resolved
FastSurferCNN/utils/metrics.py Outdated Show resolved Hide resolved
Comment on lines 118 to 122
device : str of torch.device, optional
Device specification in case of distributed computation usage.
In most of the cases, it can be defined as "cuda:local_rank" or "cuda"
if already set `torch.cuda.set_device(local_rank)`. By default, if a distributed process group is
initialized and available, device is set to `cuda`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that this metrics functionality of this class was previously implemented here and is now lost. Was this ever really used before. We should double-check. It might have been used for multi-gpu support or something.

It seems to me like FastSurfer still uses this (so at a minimum, it needs to be adapted there)

self.dice_score = DiceScore(cfg.MODEL.NUM_CLASSES, device=device)

This device variable is being passed through the pipeline including utils/train.py but it only seems to be self.device which is initialized in init

self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

In the end you will need to test the train script with a minimal dataset to make sure it does not get broken. I will find such a dataset for you, but if can also be generated with generate_dataset.py

)
self.union[i, j] = self.union[i, j] + torch.sum(gt) + torch.sum(pred)

def update(self, output):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me like update always calls _update_union_intersection.

Comment on lines +181 to +191
for i, c1 in enumerate(self.class_ids):
gt = (labels_batch == c1).float()
for j, c2 in enumerate(self.class_ids):
pred = (batch_output == c2).float()
self.intersection[i, j] = self.intersection[i, j] + torch.sum(
torch.mul(gt, pred)
)
self.union[i, j] = self.union[i, j] + torch.sum(gt) + torch.sum(pred)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it seems like the original implementation had a condition here that would only compute the full confusion matrix if explicitly required. Most times, the diagonal of the confusion matrix is enough (see previous). And always computing the full confusion matrix is EXTREMELY computationally expensive. (Prohibitively so). So we should only compute the full confusion matrix if it is explicitly requested.


def comput_dice_cnf(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be the confusion matrix :)

also added test configuration files for new filetypes

rebased pytest-feture onto merge-metrics

adding support for multiple images in test_images.py
…ferCNN.utils.metrics.py

- Deleting CerebNet.utils.metrics.py

- refactoring usage across files

- Changing back to numpy dice score implementation

- removing CerebNet.utils.metrics.py from docs
- quicktest.yaml: commenting out trigger on pull request
- FastSurferCNN.utils.metrics.py: docstring changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants