CoolFace
Apppublic

huggan/FastGan

sourceHugging Faceupdated 4y agoView on Hugging Face
33likes
models.cpython-39.pyc56 linesDownload Raw Back to __pycache__
1a

2�{]b^%�@s�ddlZddlmZddlmZmZmZddlmZm	Z	ddl3mZmZm
Z
mZmZmZmZmZddlmZGdd�deje�ZGdd	�d	eje�ZdS)4�N)�Any�Tuple�Union)�	ImageType�crop_image_part)�SpectralConv2d�	InitLayer�SLEBlock�UpsampleBlockT1�UpsampleBlockT2�DownsampleBlockT1�DownsampleBlockT2�Decoder)�HugGANModelHubMixincsBeZdZeed��fdd�Zejeejejfd�dd�Z�Z	S)�	Generator��in_channels�out_channelsc5s�t���dddddddddd	�	|_t||jd6d�|_t|jd7|jdd�|_t|jd|jdd�|_t|jd|jdd�|_	t|jd|jdd�|_8t|jd|jdd�|_t|jd|jdd�|_t|jd|jdd�|_
t|jd|jdd�|_t|jd9|jdd�|_t|jd|jdd�|_t|jd|jdd�|_t|jd|jdd�|_t�t|jd|ddd
dd�t���|_t�t|jd|ddd
dd�t���|_dS)N�����@� ���	�rrrrrrrrrr��sameF�rrZkernel_size�stride�padding�bias�)�super�__init__�	_channelsr�_initr�_upsample_8r10�_upsample_16�_upsample_32�_upsample_64�
_upsample_128�
_upsample_256�
_upsample_512�_upsample_1024r	�_sle_64�_sle_128�_sle_256�_sle_512�nn�11SequentialrZTanh�_out_128�	_out_1024)�selfrr��	__class__��9H:\My Drive\Personal\HuggingFace\HugGAN\FastGan\models.pyr&sb12������zGenerator.__init__)�input�returnc
Cs�|�|�}|�|�}|�|�}|�|�}|�||�|��}|�||�|��}|�||�	|��}|�13||�|��}	|�|	�}14|�
|�}|�|15�}||fS)N)r(r)r*r+r1r,r2r-r3r.r4r/r0r7r8)
r9r>Zsize_4Zsize_8Zsize_16Zsize_32Zsize_64Zsize_128Zsize_256Zsize_512Z	size_1024Zout_128Zout_1024r<r<r=�forwardVs16171819202122zGenerator.forward)23�__name__�24__module__�__qualname__�intr&�torch�Tensorrr@�
__classcell__r<r<r:r=rs�;�rcsXeZdZed��fdd�Zejejeeeje	eje	e25e26e27fffd�dd�Z�ZS)�Discriminrator)rc
s�t���dddddddddd	�	|_t�t||jdd28ddd
d�tjdd�t|jd|jdd29ddd
d�tj|jdd�tjdd��|_t	|jd|jdd�|_30t	|jd|jdd�|_t	|jd|jdd�|_t	|jd|jdd�|_
t	|jd|jdd�|_t|jd|jdd�|_t|jd|jdd�|_t|jd|jdd�|_t�t||jdd31ddd
d�tjdd�t|jd|jdd�t|jd|jdd�t|jd|jdd��|_t�t|jd|jddddd
d�tj|jdd�tjdd�t|jddd32ddd
d��|_t�t|jddd33ddd
d��|_t|jddd�|_t|jddd�|_t|jddd�|_dS)Nrrrrrrrrrr�rFr g�������?)Znegative_slope)Znum_featuresrrr$)r%r&r'r5r6rZ	LeakyReLUZBatchNorm2dr(r
�_downsample_256�_downsample_128�_downsample_64�_downsample_32�_downsample_16r	r1�_sle_32�_sle_16r�_small_track�_features_large�_features_smallr�_decoder_large�_decoder_small�_decoder_piece)r9rr:r<r=r&ks�34��35�36��37��38����zDiscriminrator.__init__)�images_1024�39images_128�40image_typer?cCs�|�|�}|�|�}|�|�}|�|�}|�||�}|�|�}|�||�}|�|�}	|�||	�}	|�	|�}41|�42|	��d�}|�|43��d�}t
j||gdd�}
|tjkr�|�|	�}|�|44�}|�t||��}|
|||ffS|
S)N�����r)�dim)r(rJrKrLr1rMrOrNrPrQrR�viewrSrE�catrZFAKErTrUrVr)r9rWrXrYZdown_512Zdown_256Zdown_128Zdown_64Zdown_32Zdown_16Z45down_smallZfeatures_largeZfeatures_small�featuresZ	dec_largeZ	dec_smallZ	dec_piecer<r<r=r@�s&	46474849505152535455zDiscriminrator.forward)
rArBrCrDr&rErFrrrrr@rGr<r<r:r=rHisb���rH)rEZtorch.nnr5�typingrrr�utilsrr�layersrrr	r56rrr
rZhuggan.pytorch.huggan_mixinr�ModulerrHr<r<r<r=�<module>s(P