codingutf8 2022 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license swin2sr transformer model configuration from configurationutils import pretrainedconfig from utils import logging logger logging getloggername swin2srpretrainedconfigarchivemap caidasswin2srclassicalsrx264 https huggingface cocaidasswin2srclassicalsrx264resolvemainconfig json class swin2srconfigpretrainedconfig r this is the configuration class to store the configuration of a swin2srmodel it is used to instantiate a swin transformer v2 model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the swin transformer v2 caidasswin2srclassicalsrx264https huggingface cocaidasswin2srclassicalsrx264 architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args imagesize int optional defaults to 64 the size resolution of each image patchsize int optional defaults to 1 the size resolution of each patch numchannels int optional defaults to 3 the number of input channels numchannelsout int optional defaults to numchannels the number of output channels if not set it will be set to numchannels embeddim int optional defaults to 180 dimensionality of patch embedding depths listint optional defaults to 6 6 6 6 6 6 depth of each layer in the transformer encoder numheads listint optional defaults to 6 6 6 6 6 6 number of attention heads in each layer of the transformer encoder windowsize int optional defaults to 8 size of windows mlpratio float optional defaults to 2 0 ratio of mlp hidden dimensionality to embedding dimensionality qkvbias bool optional defaults to true whether or not a learnable bias should be added to the queries keys and values hiddendropoutprob float optional defaults to 0 0 the dropout probability for all fully connected layers in the embeddings and encoder attentionprobsdropoutprob float optional defaults to 0 0 the dropout ratio for the attention probabilities droppathrate float optional defaults to 0 1 stochastic depth rate hiddenact str or function optional defaults to gelu the nonlinear activation function function or string in the encoder if string gelu relu selu and gelunew are supported useabsoluteembeddings bool optional defaults to false whether or not to add absolute position embeddings to the patch embeddings initializerrange float optional defaults to 0 02 the standard deviation of the truncatednormalinitializer for initializing all weight matrices layernormeps float optional defaults to 1e05 the epsilon used by the layer normalization layers upscale int optional defaults to 2 the upscale factor for the image 2348 for image super resolution 1 for denoising and compress artifact reduction imgrange float optional defaults to 1 0 the range of the values of the input image resiconnection str optional defaults to 1conv the convolutional block to use before the residual connection in each stage upsampler str optional defaults to pixelshuffle the reconstruction reconstruction module can be pixelshuffle pixelshuffledirect nearestconv none example python from transformers import swin2srconfig swin2srmodel initializing a swin2sr caidasswin2srclassicalsrx264 style configuration configuration swin2srconfig initializing a model with random weights from the caidasswin2srclassicalsrx264 style configuration model swin2srmodelconfiguration accessing the model configuration configuration model config modeltype swin2sr attributemap hiddensize embeddim numattentionheads numheads numhiddenlayers numlayers def init self imagesize64 patchsize1 numchannels3 numchannelsoutnone embeddim180 depths6 6 6 6 6 6 numheads6 6 6 6 6 6 windowsize8 mlpratio2 0 qkvbiastrue hiddendropoutprob0 0 attentionprobsdropoutprob0 0 droppathrate0 1 hiddenactgelu useabsoluteembeddingsfalse initializerrange0 02 layernormeps1e5 upscale2 imgrange1 0 resiconnection1conv upsamplerpixelshuffle kwargs super initkwargs self imagesize imagesize self patchsize patchsize self numchannels numchannels self numchannelsout numchannels if numchannelsout is none else numchannelsout self embeddim embeddim self depths depths self numlayers lendepths self numheads numheads self windowsize windowsize self mlpratio mlpratio self qkvbias qkvbias self hiddendropoutprob hiddendropoutprob self attentionprobsdropoutprob attentionprobsdropoutprob self droppathrate droppathrate self hiddenact hiddenact self useabsoluteembeddings useabsoluteembeddings self layernormeps layernormeps self initializerrange initializerrange self upscale upscale self imgrange imgrange self resiconnection resiconnection self upsampler upsampler coding utf 8 2022 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license swin2sr transformer model configuration this is the configuration class to store the configuration of a swin2srmodel it is used to instantiate a swin transformer v2 model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the swin transformer v2 caidas swin2sr classicalsr x2 64 https huggingface co caidas swin2sr classicalsr x2 64 architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args image_size int optional defaults to 64 the size resolution of each image patch_size int optional defaults to 1 the size resolution of each patch num_channels int optional defaults to 3 the number of input channels num_channels_out int optional defaults to num_channels the number of output channels if not set it will be set to num_channels embed_dim int optional defaults to 180 dimensionality of patch embedding depths list int optional defaults to 6 6 6 6 6 6 depth of each layer in the transformer encoder num_heads list int optional defaults to 6 6 6 6 6 6 number of attention heads in each layer of the transformer encoder window_size int optional defaults to 8 size of windows mlp_ratio float optional defaults to 2 0 ratio of mlp hidden dimensionality to embedding dimensionality qkv_bias bool optional defaults to true whether or not a learnable bias should be added to the queries keys and values hidden_dropout_prob float optional defaults to 0 0 the dropout probability for all fully connected layers in the embeddings and encoder attention_probs_dropout_prob float optional defaults to 0 0 the dropout ratio for the attention probabilities drop_path_rate float optional defaults to 0 1 stochastic depth rate hidden_act str or function optional defaults to gelu the non linear activation function function or string in the encoder if string gelu relu selu and gelu_new are supported use_absolute_embeddings bool optional defaults to false whether or not to add absolute position embeddings to the patch embeddings initializer_range float optional defaults to 0 02 the standard deviation of the truncated_normal_initializer for initializing all weight matrices layer_norm_eps float optional defaults to 1e 05 the epsilon used by the layer normalization layers upscale int optional defaults to 2 the upscale factor for the image 2 3 4 8 for image super resolution 1 for denoising and compress artifact reduction img_range float optional defaults to 1 0 the range of the values of the input image resi_connection str optional defaults to 1conv the convolutional block to use before the residual connection in each stage upsampler str optional defaults to pixelshuffle the reconstruction reconstruction module can be pixelshuffle pixelshuffledirect nearest conv none example python from transformers import swin2srconfig swin2srmodel initializing a swin2sr caidas swin2sr classicalsr x2 64 style configuration configuration swin2srconfig initializing a model with random weights from the caidas swin2sr classicalsr x2 64 style configuration model swin2srmodel configuration accessing the model configuration configuration model config
from ...configuration_utils import PretrainedConfig
from ...utils import logging


logger = logging.get_logger(__name__)

SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "caidas/swin2sr-classicalsr-x2-64": (
        "https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json"
    ),
}


class Swin2SRConfig(PretrainedConfig):
    r

    model_type = "swin2sr"

    attribute_map = {
        "hidden_size": "embed_dim",
        "num_attention_heads": "num_heads",
        "num_hidden_layers": "num_layers",
    }

    def __init__(
        self,
        image_size=64,
        patch_size=1,
        num_channels=3,
        num_channels_out=None,
        embed_dim=180,
        depths=[6, 6, 6, 6, 6, 6],
        num_heads=[6, 6, 6, 6, 6, 6],
        window_size=8,
        mlp_ratio=2.0,
        qkv_bias=True,
        hidden_dropout_prob=0.0,
        attention_probs_dropout_prob=0.0,
        drop_path_rate=0.1,
        hidden_act="gelu",
        use_absolute_embeddings=False,
        initializer_range=0.02,
        layer_norm_eps=1e-5,
        upscale=2,
        img_range=1.0,
        resi_connection="1conv",
        upsampler="pixelshuffle",
        **kwargs,
    ):
        super().__init__(**kwargs)

        self.image_size = image_size
        self.patch_size = patch_size
        self.num_channels = num_channels
        self.num_channels_out = num_channels if num_channels_out is None else num_channels_out
        self.embed_dim = embed_dim
        self.depths = depths
        self.num_layers = len(depths)
        self.num_heads = num_heads
        self.window_size = window_size
        self.mlp_ratio = mlp_ratio
        self.qkv_bias = qkv_bias
        self.hidden_dropout_prob = hidden_dropout_prob
        self.attention_probs_dropout_prob = attention_probs_dropout_prob
        self.drop_path_rate = drop_path_rate
        self.hidden_act = hidden_act
        self.use_absolute_embeddings = use_absolute_embeddings
        self.layer_norm_eps = layer_norm_eps
        self.initializer_range = initializer_range
        self.upscale = upscale
        self.img_range = img_range
        self.resi_connection = resi_connection
        self.upsampler = upsampler