-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
139 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import torch | ||
|
||
|
||
class BilinearSR(torch.nn.Module): | ||
""" | ||
A simple super-resolution model that uses bilinear interpolation. | ||
Attributes: | ||
scale_factor (int): The upscaling factor. | ||
""" | ||
|
||
def __init__(self, device: str = "cpu", scale_factor: int = 4, **kwargs) -> None: | ||
super(BilinearSR, self).__init__() | ||
self.scale_factor = scale_factor | ||
self.device = device | ||
|
||
def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
""" | ||
Forward pass that applies bilinear interpolation. | ||
Args: | ||
x (torch.Tensor): Input tensor. | ||
Returns: | ||
torch.Tensor: Output tensor after applying bilinear interpolation. | ||
""" | ||
return torch.nn.functional.interpolate( | ||
x, | ||
scale_factor=self.scale_factor, | ||
mode="bilinear", | ||
antialias=True, | ||
) | ||
|
||
|
||
class BicubicSR(torch.nn.Module): | ||
""" A simple super-resolution model that uses bicubic interpolation. | ||
Attributes: | ||
scale_factor (int): The upscaling factor. | ||
""" | ||
|
||
def __init__(self, device: str = "cpu", scale_factor: int = 4, **kwargs) -> None: | ||
super(BicubicSR, self).__init__() | ||
self.scale_factor = scale_factor | ||
self.device = device | ||
|
||
def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
""" | ||
Forward pass that applies bicubic interpolation. | ||
Args: | ||
x (torch.Tensor): Input tensor. | ||
Returns: | ||
torch.Tensor: Output tensor after applying bicubic interpolation. | ||
""" | ||
return torch.nn.functional.interpolate( | ||
x, | ||
scale_factor=self.scale_factor, | ||
mode="bicubic", | ||
antialias=True, | ||
) |
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