CoolFace
Apppublic

hololens/stable-diffusion-webui-depthmap-script

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
Resnet.cpython-310.pyc78 linesDownload Raw Back to __pycache__
1o

2��f(�@s�ddlmZddlmZgd�Zdddddd�Zdd3d�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�Z	ddd�Z4ddd�Zddd�Zddd�Z
ddd�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)�	in_planes�5out_planesr�r�BF:\3dpicmaker\stable-diffusion-webui-depthmap-script\lib\Resnet.py�conv3x3s�rcs*eZdZdZd�fdd�	Zdd�Z�ZS)�6BasicBlockrNcs^tt|���t|||�|_t�|�|_tj	dd�|_7t||�|_t�|�|_||_
||_dS)NT��inplace)�superr�__init__r�conv1�NN�BatchNorm2d�bn1r�ReLU�relu�conv2�bn2�8downsampler��self�inplanes�planesrr#��	__class__rrrs9zBasicBlock.__init__cCs`|}|�|�}|�|�}|�|�}|�|�}|�|�}|jdur%|�|�}||7}|�|�}|S�N)rrr r!r"r#�r%�x�residual�outrrr�forward$s1011121314151617zBasicBlock.forward�rN��__name__�18__module__�__qualname__�	expansionrr/�
__classcell__rrr(rrs19rcs*eZdZdZd�fdd�	Zdd�Z�ZS)	�20Bottleneck�rNcs�tt|���tj||ddd�|_t�|�|_tj||d|ddd�|_	t�|�|_21tj|||jddd�|_t�||j�|_
tjdd�|_||_||_dS)NrF)rrr	r22Tr)rr7rrrrrrrr!r"r5�conv3�bn3rr r#rr$r(rrr:s�23zBottleneck.__init__cCs~|}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�}|jdur4|�|�}||7}|�|�}|Sr*)rrr r!r"r9r:r#r+rrrr/Gs2425262728293031323334zBottleneck.forwardr0r1rrr(rr77s
r7cs0eZdZd	�fdd�	Zd35dd�Zdd�Z�ZS)r��csd|_tt|���tjddddddd�|_t�d�|_	tj36dd�|_tjddd	d37�|_
|�|d|d�|_|j|d|d	dd
�|_|j|d|ddd
�|_|j|d|ddd
�|_|��D])}t|tj�rqtjj|jddd�q^t|tj�r�tj�|jd	�tj�|jd�q^dS)N�@r	��Fr38Trr)rrr
r�)r�i�fan_outr )�mode�nonlinearity)r&rrrrrrrrrrr �	MaxPool2d�maxpool�_make_layer�layer1�layer2�layer3�layer4�modules�39isinstance�init�kaiming_normal_�weight�	constant_r)r%�block�layers�num_classes�mr(rrr`s(���zResNet.__init__rc	Cs�d}|dks|j||jkr&t�tj|j||jd|dd�t�||j��}g}|�||j|||��||j|_td|�D]}|�||j|��q>tj|�S)NrF)rrr)	r&r5r�40Sequentialrrr�append�range)r%rQr'�blocksrr#rR�irrrrFvs��41zResNet._make_layercCs�g}|�|�}|�|�}|�|�}|�|�}|�|�}|�|�|�|�}|�|�|�|�}|�|�|�|�}|�|�|Sr*)	rrr rErGrVrHrIrJ)r%r,�featuresrrrr/�s424344454647484950515253zResNet.forward)r;�r)r2r3r4rrFr/r6rrr(rr^s54rTcK�ttgd�fi|��}|S)zxConstructs a ResNet-18 model.55    Args:56        pretrained (bool): If True, returns a model pre-trained on ImageNet57    )r>r>r>r>�rr��58pretrained�kwargs�modelrrrr��rcKr\)zxConstructs a ResNet-34 model.59    Args:60        pretrained (bool): If True, returns a model pre-trained on ImageNet61    �r	r8�r	r]r^rrrr�rbrcKr\)zxConstructs a ResNet-50 model.62    Args:63        pretrained (bool): If True, returns a model pre-trained on ImageNet64    rc�rr7r^rrrr��rcKr\)zyConstructs a ResNet-101 model.65    Args:66        pretrained (bool): If True, returns a model pre-trained on ImageNet67    )r	r8�r	rer^rrrr�rfrcKr\)zyConstructs a ResNet-152 model.68    Args:69        pretrained (bool): If True, returns a model pre-trained on ImageNet70    )r	��$r	rer^rrrr�rbrr[)T)�torch.nnrr�__all__�71model_urlsr�Modulerr7rrrrrrrrrr�<module>s$�72	 '73=74	75	76 7778