CoolFace
Apppublic

Sorobot/Document-modify-Toolkit

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
extractor.cpython-38.pyc46 linesDownload Raw Back to __pycache__
1U

2h�Hf�@s@ddlmZddlmZGdd�dej�ZGdd�dej�ZdS)�N�)�weight_init_cs*eZdZdZd�fdd�	Zdd�Z�ZS)	�
ResidualBlockz)Residual Block with custom normalization.�grouprcsXtt|���tj||dd|d�|_tj||ddd�|_t��|_|dkr�|d}t�	||�|_3t�	||�|_|dks�t�	||�|_n�|dkr�t�
|�|_4t�
|�|_|dks�t�
|�|_nh|dkr�t�|�|_5t�|�|_|dks�t�|�|_n2|d	k�r$t��|_6t��|_|dk�s$t��|_|dk�r6d|_nt�tj||d|d7�|j�|_dS)N�r)�padding�stride)rr��batch�instance�none�r)�superr�__init__�nn�Conv2D�conv1�conv2�ReLU�relu�	GroupNorm�norm1�norm2�norm3�BatchNorm2D�InstanceNorm2D�8Sequential�9downsample)�self�	in_planes�planes�norm_fnr�10num_groups��	__class__��*D:\CodeProjects\as1\Transform\extractor.pyr	s>11121314151617�zResidualBlock.__init__cCsR|}|�|�|�|���}|�|�|�|���}|jdk	rD|�|�}|�||�S�N)rrrrrr)r�x�yr%r%r&�forward-s1819zResidualBlock.forward)rr)�__name__�20__module__�__qualname__�__doc__rr*�
__classcell__r%r%r#r&rs$rcs4eZdZdZd�fdd�	Zddd�Zd	d21�Z�ZS)
�BasicEncoderz(Basic Encoder with custom normalization.�r22cs2tt|���||_|jdkr.t�dd�|_nD|jdkrFt�d�|_n,|jdkr^t�d�|_n|jdkrrt�	�|_tj23dddd	dd24�|_t��|_
d|_|jddd�|_|jd
d	d�|_|jdd	d�|_t�25d|d�|_|��D]L}t|tj26��rt|jdddd�q�t|tjtjtjf�r�t|dddd�q�dS)Nrr	�@r27rrr��)rrrr
r1���kaiming_normal_�fan_outr)�mode�nonlinearity�Constantg)�valueZ28bias_value)rr0rr!rrrrrrrrr�relu1r�_make_layer�layer1�layer2�layer3r�	sublayers�29isinstancer�weight)r�30output_dimr!�mr#r%r&r;s6313233343536�zBasicEncoder.__init__rcCs>t|j||j|d�}t|||jdd�}||f}||_tj|�S)Nr
r)rrr!rr)r�dimrr>r?�layersr%r%r&r=[s37zBasicEncoder._make_layercCsJ|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|Sr')rrr<r>r?r@r)rr(r%r%r&r*cs38394041424344zBasicEncoder.forward)r1r45)r)r+r,r-r.rr=r*r/r%r%r#r&r08s 46r0)�	paddle.nnr�weight_initr�Layerrr0r%r%r%r&�<module>s2