a
    d
                     @   sB   d dl mZ d dlmZ d dlmZ e G dd dejZ	dS )    )ARCH_REGISTRY)nn)
functionalc                       s*   e Zd ZdZd fdd	Zd	d
 Z  ZS )SRVGGNetCompacta  A compact VGG-style network structure for super-resolution.

    It is a compact network structure, which performs upsampling in the last layer and no convolution is
    conducted on the HR feature space.

    Args:
        num_in_ch (int): Channel number of inputs. Default: 3.
        num_out_ch (int): Channel number of outputs. Default: 3.
        num_feat (int): Channel number of intermediate features. Default: 64.
        num_conv (int): Number of convolution layers in the body network. Default: 16.
        upscale (int): Upsampling factor. Default: 4.
        act_type (str): Activation type, options: 'relu', 'prelu', 'leakyrelu'. Default: prelu.
       @         preluc           	   
      sN  t t|   || _|| _|| _|| _|| _|| _t	
 | _| jt	||ddd |dkrlt	jdd}n,|dkrt	j|d}n|dkrt	jd	dd
}| j| t|D ]n}| jt	||ddd |dkrt	jdd}n.|dkrt	j|d}n|dkrt	jd	dd
}| j| q| jt	||| | ddd t	|| _d S )Nr      ZreluT)inplacer
   )Znum_parametersZ	leakyrelug?)Znegative_sloper   )superr   __init__	num_in_ch
num_out_chnum_featnum_convupscaleact_typer   Z
ModuleListbodyappendZConv2dZReLUZPReLUZ	LeakyReLUrangeZPixelShuffle	upsampler)	selfr   r   r   r   r   r   Z
activation_	__class__ d/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/realesrgan/archs/srvgg_arch.pyr      s6    

"zSRVGGNetCompact.__init__c                 C   sP   |}t dt| jD ]}| j| |}q| |}tj|| jdd}||7 }|S )Nr   Znearest)Zscale_factormode)r   lenr   r   FZinterpolater   )r   xoutibaser   r   r   forward<   s    
zSRVGGNetCompact.forward)r   r   r   r   r	   r
   )__name__
__module____qualname____doc__r   r&   __classcell__r   r   r   r   r      s   &r   N)
Zbasicsr.utils.registryr   Ztorchr   Ztorch.nnr   r!   registerModuler   r   r   r   r   <module>   s   