-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inputs to BMZ should not be normalized (#132)
### Description The inputs to the BMZ model should not be normalized, as the BMZ core applies the normalization itself. Since all our tests were using tensors with values [-1, 1], this went unnoticed. This PR uses a quick fix by applying denormalization to the patches extracted from the datamodules. This part of the code was refactored into a tested member function of `CAREamist`. I also scaled all tensors in `CAREamit` tests to [0, 255] to be more realistic. - **What**: Add denormalization to BMZ export input data. - **Why**: The current code export normalized tensors, which leads to failing validation of the BMZ archive - **How**: `Denormalize` is now called in a the (refactored) `_create_data_for_bmz` method in `CAREamist`. ### Changes Made - **Added**: `_create_data_for_bmz` method in `CAREamist`, specific tests. - **Modified**: Existing `CAREamist` tests. ### Related Issues Issues reported by users. ### Additional Notes and Examples The choice here is **quick fix** one. The current way example inputs are generated prior to exporting to the BMZ format is by pulling patches from the existing dataloaders (either prediction, or training one): https://github.com/CAREamics/careamics/blob/f613d724fd7e9f8f6ea102ee108701bb44dfae44/src/careamics/careamist.py#L694 This fix here is to simply call `Denormalize` on the array: ```python # unpack a batch, ignore masks or targets input_patch, *_ = next(iter(self.pred_datamodule.predict_dataloader())) # convert torch.Tensor to numpy input_patch = input_patch.numpy() # denormalize denormalize = Denormalize( mean=self.cfg.data_config.mean, std=self.cfg.data_config.std ) input_patch, _ = denormalize(input_patch) ``` An alternative would be to find a way to create a new Dataloader with the data and remove normalization, but this seems possible only after training because the `CAREamist` remembers the source data (unless it is a DataLoader). However, we want to be able to export after loading a checkpoint for instance (choosing best model, loading it, exporting to BMZ). So I think this is the best pragmatic choice. --- **Please ensure your PR meets the following requirements:** - [x] Code builds and passes tests locally, including doctests - [x] New tests have been added (for bug fixes/features) - [x] Pre-commit passes - [x] No change to the documentation needed
- Loading branch information
1 parent
a19a770
commit 763d965
Showing
4 changed files
with
259 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.