-
Notifications
You must be signed in to change notification settings - Fork 1
ENH adding new tasks (MRI, demoisaicing) #5
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
Open
tomMoral
wants to merge
29
commits into
main
Choose a base branch
from
new-tasks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
12cd68b
WIP add FastMRI dataset and demosaicing task
Melvin-klein 6a8108f
WIP
Melvin-klein 80f232b
WIP Add ifft2 as baseline
Melvin-klein 217436c
WIP skip ifft2 solver on datasets that are not FastMRI
Melvin-klein 5b7602f
WIP
Melvin-klein 65beb1a
WIP
Melvin-klein 4525802
WIP : Add new denoiser for DPIR
Melvin-klein 92e8791
Removed unused files
Melvin-klein a0227e5
Add DPIR_2C to handle imaginary images
Melvin-klein b8fa8ee
Refactor code
Melvin-klein 2a1a435
Update DiffPIR for imaginary images
Melvin-klein 5c1ea37
Every solvers run on SimpleFastMIR
Melvin-klein 7442ff1
WIP: Change SimpleFastMRISliceDataset to FastMRISliceDataset
Melvin-klein c508509
WIP
27a3f07
WIP
4f9e189
WIP
0737ca6
WIP
386be6a
WIP
Melvin-klein ecc81ae
WIP
Melvin-klein 8029157
WIP
Melvin-klein 25b1375
UNet working
Melvin-klein ac88628
UNet, DPIR, DiffPIR working
Melvin-klein 7a55efd
WIP
Melvin-klein be94a63
WIP
Melvin-klein 23baf2b
WIP
Melvin-klein 4af546b
Added inpainting, fix bugs
Melvin-klein 65c1f65
Add inference time per degraded image to metrics
Melvin-klein 32526b3
Fix U-Net solver's scheduler
Melvin-klein 8ca02b8
Fix comments
Melvin-klein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ benchopt.ini | |
|
||
.DS_Store | ||
coverage.xml | ||
|
||
tmp |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from deepinv.models import UNet | ||
|
||
class MRIUNet(UNet): | ||
def __init__(self, in_channels, out_channels, scales=3, batch_norm=False): | ||
self.name = "MRIUNet" | ||
self.in_channels = in_channels | ||
|
||
super().__init__(in_channels=in_channels, out_channels=out_channels, scales=scales, batch_norm=batch_norm) | ||
|
||
def forward(self, x, sigma=None, **kwargs): | ||
# Reshape for MRI specific processing | ||
x = x.reshape(1, self.in_channels, x.shape[3], x.shape[4]) | ||
|
||
x = super().forward(x, sigma=sigma, **kwargs) | ||
|
||
return x |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
import torch | ||
from deepinv.models import DRUNet | ||
from deepinv.models import Denoiser | ||
|
||
class Denoiser_2c(Denoiser): | ||
def __init__(self, device): | ||
super(Denoiser_2c, self).__init__() | ||
self.model_c1 = DRUNet(in_channels=1, out_channels=1, pretrained="download", device=device) | ||
self.model_c2 = DRUNet(in_channels=1, out_channels=1, pretrained="download", device=device) | ||
|
||
def forward(self, y, sigma): | ||
y1, y2 = torch.split(y, 1, dim=1) | ||
|
||
x_hat_1 = self.model_c1(y1, sigma=sigma) | ||
x_hat_2 = self.model_c2(y2, sigma=sigma) | ||
|
||
x_hat = torch.cat([x_hat_1, x_hat_2], dim=1) | ||
|
||
return x_hat |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import torch | ||
from torch.utils.data import Dataset | ||
from deepinv.datasets import FastMRISliceDataset | ||
import torch.nn.functional as F | ||
import deepinv as dinv | ||
|
||
class FastMRIDataset(Dataset): | ||
def __init__(self, dataset: FastMRISliceDataset, mask, max_coils=32): | ||
self.dataset = dataset | ||
self.max_coils = max_coils | ||
self.mask = mask | ||
|
||
def __len__(self): | ||
return len(self.dataset) | ||
|
||
def __getitem__(self, idx): | ||
x, y = self.dataset[idx] | ||
x, y = x.to(device=self.mask.device), y.to(device=self.mask.device) | ||
|
||
# Pad the width | ||
target_width = 400 | ||
pad_total = target_width - y.shape[3] | ||
pad_left = pad_total // 2 | ||
pad_right = pad_total - pad_left | ||
y = F.pad(y, (pad_left, pad_right, 0, 0), mode='constant', value=0) | ||
|
||
# Pad the height | ||
target_height = 700 | ||
pad_total = target_height - y.shape[2] | ||
pad_left = pad_total // 2 | ||
pad_right = pad_total - pad_left | ||
y = F.pad(y, (0, 0, pad_left, pad_right), mode='constant', value=0) | ||
|
||
# Transform the mask to match the kspace shape | ||
mask = self.mask.repeat(y.shape[0], y.shape[1], 1, 1) | ||
|
||
# Apply the mask to the k-space data | ||
y = y * mask | ||
|
||
# Add an imaginary part of zeros | ||
x = torch.cat([x, torch.zeros_like(x)], dim=0) | ||
|
||
# Pad the coil dimension if necessary | ||
coil_dim = y.shape[1] | ||
if coil_dim < self.max_coils: | ||
pad_size = self.max_coils - coil_dim | ||
y = F.pad(y, (0, 0, 0, 0, 0, pad_size)) | ||
|
||
return x, y |
This file contains hidden or 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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import deepinv as dinv | ||
|
||
class CustomMSE(dinv.metric.MSE): | ||
|
||
transform = lambda x: x | ||
|
||
def forward(self, x_net=None, x=None, *args, **kwargs): | ||
return super().forward(self.transform(x_net), x, *args, **kwargs) | ||
|
||
|
||
class CustomPSNR(dinv.metric.PSNR): | ||
|
||
transform = lambda x: x | ||
|
||
def forward(self, x_net=None, x=None, *args, **kwargs): | ||
return super().forward(self.transform(x_net), x, *args, **kwargs) | ||
|
||
class CustomSSIM(dinv.metric.SSIM): | ||
|
||
transform = lambda x: x | ||
|
||
def forward(self, x_net=None, x=None, *args, **kwargs): | ||
return super().forward(self.transform(x_net), x, *args, **kwargs) | ||
|
||
class CustomLPIPS(dinv.metric.LPIPS): | ||
|
||
transform = lambda x: x | ||
|
||
def forward(self, x_net=None, x=None, *args, **kwargs): | ||
return super().forward(self.transform(x_net), x, *args, **kwargs) |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
data_home: /Users/melvinenargeot/Data/benchmark_inverse_problems | ||
data_home: /home/mind/mnargeot/benchmarks/benchmark_inverse_problems/data_tmp | ||
data_paths: | ||
generated_datasets: generated_datasets | ||
generated_trainings: generated_training | ||
BSD500: BSD500/BSR/BSDS500/data/images | ||
BSD500: /data/parietal/store3/data/BSD500 | ||
fastmri_train: /data/parietal/store3/data/fastMRI-multicoil/multicoil_train | ||
fastmri_test: /data/parietal/store3/data/fastMRI-multicoil/multicoil_val |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it forcing the batch_size to be
1
? why notx.shape[0]
? Why do you need to reshape at all actually?