Created
February 28, 2022 14:18
-
-
Save torridgristle/71a83d83f2a5494202dc5bd987321b7e to your computer and use it in GitHub Desktop.
Residual and Concatenate modules for PyTorch. Residual taken from https://github.com/lucidrains/denoising-diffusion-pytorch/blob/eb6e1b508e920efd840f2fa13e80d60ce19ed2c1/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py#L72 since it was very useful.
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
import torch | |
import torch.nn as nn | |
class Residual(nn.Module): | |
def __init__(self, fn): | |
super().__init__() | |
self.fn = fn | |
def forward(self, x, *args, **kwargs): | |
return self.fn(x, *args, **kwargs) + x | |
class Concat(nn.Module): | |
def __init__(self, fn): | |
super().__init__() | |
self.fn = fn | |
def forward(self, x, *args, **kwargs): | |
return torch.cat([x,self.fn(x, *args, **kwargs)],1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment