MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / T2IAdapter

Class T2IAdapter

diffusers/src/diffusers/models/adapter.py:217–285  ·  view source on GitHub ↗

r""" A simple ResNet-like model that accepts images containing control signals such as keyposes and depth. The model generates multiple feature maps that are used as additional conditioning in [`UNet2DConditionModel`]. The model's architecture follows the original implementation of [

Source from the content-addressed store, hash-verified

215
216
217class T2IAdapter(ModelMixin, ConfigMixin):
218 r"""
219 A simple ResNet-like model that accepts images containing control signals such as keyposes and depth. The model
220 generates multiple feature maps that are used as additional conditioning in [`UNet2DConditionModel`]. The model's
221 architecture follows the original implementation of
222 [Adapter](https://github.com/TencentARC/T2I-Adapter/blob/686de4681515662c0ac2ffa07bf5dda83af1038a/ldm/modules/encoders/adapter.py#L97)
223 and
224 [AdapterLight](https://github.com/TencentARC/T2I-Adapter/blob/686de4681515662c0ac2ffa07bf5dda83af1038a/ldm/modules/encoders/adapter.py#L235).
225
226 This model inherits from [`ModelMixin`]. Check the superclass documentation for the generic methods the library
227 implements for all the model (such as downloading or saving, etc.)
228
229 Parameters:
230 in_channels (`int`, *optional*, defaults to 3):
231 Number of channels of Aapter's input(*control image*). Set this parameter to 1 if you're using gray scale
232 image as *control image*.
233 channels (`List[int]`, *optional*, defaults to `(320, 640, 1280, 1280)`):
234 The number of channel of each downsample block's output hidden state. The `len(block_out_channels)` will
235 also determine the number of downsample blocks in the Adapter.
236 num_res_blocks (`int`, *optional*, defaults to 2):
237 Number of ResNet blocks in each downsample block.
238 downscale_factor (`int`, *optional*, defaults to 8):
239 A factor that determines the total downscale factor of the Adapter.
240 adapter_type (`str`, *optional*, defaults to `full_adapter`):
241 The type of Adapter to use. Choose either `full_adapter` or `full_adapter_xl` or `light_adapter`.
242 """
243
244 @register_to_config
245 def __init__(
246 self,
247 in_channels: int = 3,
248 channels: List[int] = [320, 640, 1280, 1280],
249 num_res_blocks: int = 2,
250 downscale_factor: int = 8,
251 adapter_type: str = "full_adapter",
252 ):
253 super().__init__()
254
255 if adapter_type == "full_adapter":
256 self.adapter = FullAdapter(in_channels, channels, num_res_blocks, downscale_factor)
257 elif adapter_type == "full_adapter_xl":
258 self.adapter = FullAdapterXL(in_channels, channels, num_res_blocks, downscale_factor)
259 elif adapter_type == "light_adapter":
260 self.adapter = LightAdapter(in_channels, channels, num_res_blocks, downscale_factor)
261 else:
262 raise ValueError(
263 f"Unsupported adapter_type: '{adapter_type}'. Choose either 'full_adapter' or "
264 "'full_adapter_xl' or 'light_adapter'."
265 )
266
267 def forward(self, x: torch.Tensor) -> List[torch.Tensor]:
268 r"""
269 This function processes the input tensor `x` through the adapter model and returns a list of feature tensors,
270 each representing information extracted at a different scale from the input. The length of the list is
271 determined by the number of downsample blocks in the Adapter, as specified by the `channels` and
272 `num_res_blocks` parameters during initialization.
273 """
274 return self.adapter(x)

Calls

no outgoing calls