A `LightAdapterResnetBlock` is a helper model that implements a ResNet-like block with a slightly different architecture than `AdapterResnetBlock`. Parameters: channels (`int`): Number of channels of LightAdapterResnetBlock's input and output.
| 557 | |
| 558 | |
| 559 | class LightAdapterResnetBlock(nn.Module): |
| 560 | """ |
| 561 | A `LightAdapterResnetBlock` is a helper model that implements a ResNet-like block with a slightly different |
| 562 | architecture than `AdapterResnetBlock`. |
| 563 | |
| 564 | Parameters: |
| 565 | channels (`int`): |
| 566 | Number of channels of LightAdapterResnetBlock's input and output. |
| 567 | """ |
| 568 | |
| 569 | def __init__(self, channels: int): |
| 570 | super().__init__() |
| 571 | self.block1 = nn.Conv2d(channels, channels, kernel_size=3, padding=1) |
| 572 | self.act = nn.ReLU() |
| 573 | self.block2 = nn.Conv2d(channels, channels, kernel_size=3, padding=1) |
| 574 | |
| 575 | def forward(self, x: torch.Tensor) -> torch.Tensor: |
| 576 | r""" |
| 577 | This function takes input tensor x and processes it through one convolutional layer, ReLU activation, and |
| 578 | another convolutional layer and adds it to input tensor. |
| 579 | """ |
| 580 | |
| 581 | h = self.act(self.block1(x)) |
| 582 | h = self.block2(h) |
| 583 | |
| 584 | return h + x |