r""" See [`T2IAdapter`] for more information.
| 289 | |
| 290 | |
| 291 | class FullAdapter(nn.Module): |
| 292 | r""" |
| 293 | See [`T2IAdapter`] for more information. |
| 294 | """ |
| 295 | |
| 296 | def __init__( |
| 297 | self, |
| 298 | in_channels: int = 3, |
| 299 | channels: List[int] = [320, 640, 1280, 1280], |
| 300 | num_res_blocks: int = 2, |
| 301 | downscale_factor: int = 8, |
| 302 | ): |
| 303 | super().__init__() |
| 304 | |
| 305 | in_channels = in_channels * downscale_factor**2 |
| 306 | |
| 307 | self.unshuffle = nn.PixelUnshuffle(downscale_factor) |
| 308 | self.conv_in = nn.Conv2d(in_channels, channels[0], kernel_size=3, padding=1) |
| 309 | |
| 310 | self.body = nn.ModuleList( |
| 311 | [ |
| 312 | AdapterBlock(channels[0], channels[0], num_res_blocks), |
| 313 | *[ |
| 314 | AdapterBlock(channels[i - 1], channels[i], num_res_blocks, down=True) |
| 315 | for i in range(1, len(channels)) |
| 316 | ], |
| 317 | ] |
| 318 | ) |
| 319 | |
| 320 | self.total_downscale_factor = downscale_factor * 2 ** (len(channels) - 1) |
| 321 | |
| 322 | def forward(self, x: torch.Tensor) -> List[torch.Tensor]: |
| 323 | r""" |
| 324 | This method processes the input tensor `x` through the FullAdapter model and performs operations including |
| 325 | pixel unshuffling, convolution, and a stack of AdapterBlocks. It returns a list of feature tensors, each |
| 326 | capturing information at a different stage of processing within the FullAdapter model. The number of feature |
| 327 | tensors in the list is determined by the number of downsample blocks specified during initialization. |
| 328 | """ |
| 329 | x = self.unshuffle(x) |
| 330 | x = self.conv_in(x) |
| 331 | |
| 332 | features = [] |
| 333 | |
| 334 | for block in self.body: |
| 335 | x = block(x) |
| 336 | features.append(x) |
| 337 | |
| 338 | return features |
| 339 | |
| 340 | |
| 341 | class FullAdapterXL(nn.Module): |