configuration_swin2sr.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright 2022 The HuggingFace Inc. team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Swin2SR Transformer model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="caidas/swin2sr-classicalsr-x2-64")
  19. @strict
  20. class Swin2SRConfig(PreTrainedConfig):
  21. r"""
  22. num_channels_out (`int`, *optional*, defaults to `num_channels`):
  23. The number of output channels. If not set, it will be set to `num_channels`.
  24. depths (`list(int)`, *optional*, defaults to `[6, 6, 6, 6, 6, 6]`):
  25. Depth of each layer in the Transformer encoder.
  26. num_heads (`list(int)`, *optional*, defaults to `[6, 6, 6, 6, 6, 6]`):
  27. Number of attention heads in each layer of the Transformer encoder.
  28. window_size (`int`, *optional*, defaults to 8):
  29. Size of windows.
  30. upscale (`int`, *optional*, defaults to 2):
  31. The upscale factor for the image. 2/3/4/8 for image super resolution, 1 for denoising and compress artifact
  32. reduction
  33. img_range (`float`, *optional*, defaults to 1.0):
  34. The range of the values of the input image.
  35. resi_connection (`str`, *optional*, defaults to `"1conv"`):
  36. The convolutional block to use before the residual connection in each stage.
  37. upsampler (`str`, *optional*, defaults to `"pixelshuffle"`):
  38. The reconstruction reconstruction module. Can be 'pixelshuffle'/'pixelshuffledirect'/'nearest+conv'/None.
  39. Example:
  40. ```python
  41. >>> from transformers import Swin2SRConfig, Swin2SRModel
  42. >>> # Initializing a Swin2SR caidas/swin2sr-classicalsr-x2-64 style configuration
  43. >>> configuration = Swin2SRConfig()
  44. >>> # Initializing a model (with random weights) from the caidas/swin2sr-classicalsr-x2-64 style configuration
  45. >>> model = Swin2SRModel(configuration)
  46. >>> # Accessing the model configuration
  47. >>> configuration = model.config
  48. ```"""
  49. model_type = "swin2sr"
  50. attribute_map = {
  51. "hidden_size": "embed_dim",
  52. "num_attention_heads": "num_heads",
  53. "num_hidden_layers": "num_layers",
  54. }
  55. image_size: int | list[int] | tuple[int, int] = 64
  56. patch_size: int | list[int] | tuple[int, int] = 1
  57. num_channels: int = 3
  58. num_channels_out: int | None = None
  59. embed_dim: int = 180
  60. depths: list[int] | tuple[int, ...] = (6, 6, 6, 6, 6, 6)
  61. num_heads: list[int] | tuple[int, ...] = (6, 6, 6, 6, 6, 6)
  62. window_size: int = 8
  63. mlp_ratio: float = 2.0
  64. qkv_bias: bool = True
  65. hidden_dropout_prob: float | int = 0.0
  66. attention_probs_dropout_prob: float | int = 0.0
  67. drop_path_rate: float | int = 0.1
  68. hidden_act: str = "gelu"
  69. use_absolute_embeddings: bool = False
  70. initializer_range: float = 0.02
  71. layer_norm_eps: float = 1e-5
  72. upscale: int = 2
  73. img_range: float = 1.0
  74. resi_connection: str = "1conv"
  75. upsampler: str = "pixelshuffle"
  76. def __post_init__(self, **kwargs):
  77. self.num_channels_out = self.num_channels if self.num_channels_out is None else self.num_channels_out
  78. self.num_layers = len(self.depths)
  79. super().__post_init__(**kwargs)
  80. __all__ = ["Swin2SRConfig"]