CoolFace
Apppublic

Linhz/ViMNer

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
resnet.cpython-39.pyc77 linesDownload Raw Back to __pycache__
1a

2�df��@s�ddlmZddlZddlmmZgd�Zdddddd�Zdd3d�ZGdd
�d
ej	�Z4Gdd�dej	�ZGdd�dej	�Zddd�Z
ddd�Zd dd�Zd!dd�Zd"dd�ZdS)#�N)�ResNet�resnet18�resnet34�resnet50�	resnet101�	resnet152z9https://download.pytorch.org/models/resnet18-5c106cde.pthz9https://download.pytorch.org/models/resnet34-333f7ec4.pthz9https://download.pytorch.org/models/resnet50-19c8e357.pthz:https://download.pytorch.org/models/resnet101-5d3b4d8f.pthz:https://download.pytorch.org/models/resnet152-b121ed2d.pth)rrrrr�cCstj||d|ddd�S)z3x3 convolution with padding�rF��kernel_size�stride�padding�bias)�nn�Conv2d)Z	in_planesZ5out_planesr�r�9E:\demo_datn\pythonProject1\Model\MultimodelNER\resnet.py�conv3x3s�rcs*eZdZdZd�fdd�	Zdd�Z�ZS)�6BasicBlockrNcs^tt|���t|||�|_t�|�|_tjdd�|_	t||�|_7t�|�|_||_||_
dS)NT��inplace)�superr�__init__r�conv1r�BatchNorm2d�bn1�ReLU�relu�conv2�bn2�8downsampler��self�inplanes�planesrr ��	__class__rrrszBasicBlock.__init__cCs`|}|�|�}|�|�}|�|�}|�|�}|�|�}|jdurJ|�|�}||7}|�|�}|S�N)rrrrrr �r"�x�residual�outrrr�forward&s910111213141516zBasicBlock.forward)rN��__name__�17__module__�__qualname__�	expansionrr,�
__classcell__rrr%rrs18rcs*eZdZdZd�fdd�	Zdd�Z�ZS)	�19Bottleneck�rNcs�tt|���tj||ddd�|_t�|�|_tj||d|ddd�|_t�|�|_	tj||dddd�|_20t�|d�|_tjdd�|_
||_||_dS)	NrF)rrr	r21r4Tr)rr3rrrrrrrr�conv3�bn3rrr rr!r%rrr<s�zBottleneck.__init__cCs~|}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|jdurh|�|�}||7}|�|�}|Sr')rrrrrr5r6r r(rrrr,Is2223242526272829303132zBottleneck.forward)rNr-rrr%rr39s
r3cs0eZdZd	�fdd�	Zd33dd�Zdd�Z�ZS)r��csTd|_tt|���tjddddddd�|_t�d�|_tj	dd�|_34tjddd	d35�|_|�
|d|d�|_|j
|d|d	dd
�|_|j
|d|ddd
�|_|j
|d|ddd
�|_tjdd	d
�|_t�d|j|�|_|��D]n}t|tj��r(|jd|jd	|j}|jj�dt�d|��q�t|tj�r�|jj� d	�|j!j�"�q�dS)N�@r	��Fr36Trr)rrr
r�)r�ig@)#r#rrrrrrrrrr�	MaxPool2d�maxpool�_make_layer�layer1�layer2�layer3�layer4�	AvgPool2d�avgpool�Linearr1�fc�modules�37isinstancer�out_channels�weight�data�normal_�math�sqrt�fill_r�zero_)r"�block�layers�num_classes�m�nr%rrrbs*�zResNet.__init__rc	Cs�d}|dks|j||jkrLt�tj|j||jd|dd�t�||j��}g}|�||j|||��||j|_td|�D]}|�||j|��q|tj|�S)NrF)rrr)r#r1r�38Sequentialrr�append�range)r"rRr$�blocksrr rS�irrrr?ys��zResNet._make_layercCsz|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�	|�39d�d�}|�|�}|S)Nr�����)rrrr>r@rArBrCrE�view�sizerG)r"r)rrrr,�s40414243444546474849zResNet.forward)r7)r)r.r/r0rr?r,r2rrr%rr`s50rFcKs2ttgd�fi|��}|r.|�t�td��|S)zyConstructs a ResNet-18 model.51 52    Args:53        pretrained (bool): If True, returns a model pre-trained on ImageNet54    )r:r:r:r:r�rr�load_state_dict�	model_zoo�load_url�55model_urls�Z56pretrained�kwargs�modelrrrr�srcKs2ttgd�fi|��}|r.|�t�td��|S)zyConstructs a ResNet-34 model.57 58    Args:59        pretrained (bool): If True, returns a model pre-trained on ImageNet60    �r	r4�r	rr_rdrrrr�srcKs2ttgd�fi|��}|r.|�t�td��|S)zyConstructs a ResNet-50 model.61 62    Args:63        pretrained (bool): If True, returns a model pre-trained on ImageNet64    rgr�rr3r`rarbrcrdrrrr�srcKs2ttgd�fi|��}|r.|�t�td��|S)zzConstructs a ResNet-101 model.65 66    Args:67        pretrained (bool): If True, returns a model pre-trained on ImageNet68    )r	r4�r	rrirdrrrr�srcKs2ttgd�fi|��}|r.|�t�td��|S)zzConstructs a ResNet-152 model.69 70    Args:71        pretrained (bool): If True, returns a model pre-trained on ImageNet72    )r	��$r	rrirdrrrr�sr)r)F)F)F)F)F)�torch.nnrrNZtorch.utils.model_zoo�utilsra�__all__rcr�Modulerr3rrrrrrrrrr�<module>s$�	73 '<74757677