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

Clean tuto dcnet + drunet #199

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spyrit/drunet/
!spyrit/images/tuto/*.png
docs/source/html
docs/source/_autosummary
docs/source/_templates
docs/source/_static
docs/source/api
docs/source/gallery
Binary file added docs/source/fig/drunet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions spyrit/external/drunet.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,63 @@ def forward(self, x0):
return x


class DRUNet(UNetRes):
def __init__(
self,
noise_level=5,
n_channels=1,
nc=[64, 128, 256, 512],
nb=4,
act_mode="R",
downsample_mode="strideconv",
upsample_mode="convtranspose",
):
super(DRUNet, self).__init__(
n_channels + 1, n_channels, nc, nb, act_mode, downsample_mode, upsample_mode
)
self.register_buffer("noise_level", torch.FloatTensor([noise_level / 255.0]))

def forward(self, x):
# Image domain denoising
x = self.concat_noise_map(x)

# Pass input images through the network
x = super(DRUNet, self).forward(x)
return x

def concat_noise_map(self, x):
r"""Concatenation of noise level map to reconstructed images

Args:
:attr:`x`: reconstructed images from the reconstruction layer

Shape:
:attr:`x`: reconstructed images with shape :math:`(BC,1,H,W)`

:attr:`output`: reconstructed images with concatenated noise level map with shape :math:`(BC,2,H,W)`
"""

b, c, h, w = x.shape
x = 0.5 * (x + 1)
x = torch.cat((x, self.noise_level.expand(b, 1, h, w)), dim=1)
return x

def set_noise_level(self, noise_level):
r"""Reset noise level value

Args:
:attr:`noise_level`: noise level value in the range [0, 255]

Shape:
:attr:`noise_level`: float value noise level :math:`(1)`

:attr:`output`: noise level tensor with shape :math:`(1)`
"""
self.noise_level = torch.FloatTensor([noise_level / 255.0]).to(
self.noise_level.device
)


# ----------------------------------------------
# Functions taken from basicblock.py
# https://github.com/cszn/DPIR/tree/master/models
Expand Down
Loading