CoolFace
Apppublic

hololens/stable-diffusion-webui-depthmap-script

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
Resnext_torch.cpython-312.pyc55 linesDownload Raw Back to __pycache__
12��f#���ddlmZ	ddlmZdgZddd�Zdd�Zdd�Z	Gd	�d3ej�ZGd�dej�ZGd
�dej�Z
dd�Zedk(rQddlZed�j#�Zej&d�j#�Zee�Zeee��yy#e$r	ddlmZY��wxYw)�N)�urlretrieve�resnext101_32x8dz@https://download.pytorch.org/models/resnext50_32x4d-7cdf4587.pthzAhttps://download.pytorch.org/models/resnext101_32x8d-8ba56ff5.pth)�resnext50_32x4drc4�<�tj||d|||d|��S)z3x3 convolution with padding�F)�kernel_size�stride�padding�groups�bias�dilation��nn�Conv2d)�	in_planes�5out_planesr	rr
s     �IF:\3dpicmaker\stable-diffusion-webui-depthmap-script\lib\Resnext_torch.py�conv3x3rs&��
�9�9�Y�6��&�%�f�5�8�U�U�c�6�tj||d|d��S)z1x1 convolution�F)rr	rr)rrr	s   r�conv1x1rs��
�9�9�Y�7��&�u�U�Urc�.��eZdZdZ		d�fd�	Zd�Z�xZS)�8BasicBlockrc	�d��tt|��|�tj}|dk7s|dk7rtd��|dkDrt
d��t|||�|_||�|_	tjd��|_t||�|_||�|_
||_||_y)Nr�@z3BasicBlock only supports groups=1 and base_width=64z(Dilation > 1 not supported in BasicBlockT��inplace)�superr�__init__r�BatchNorm2d�9ValueError�NotImplementedErrorr�conv1�bn1�ReLU�relu�conv2�bn2�10downsampler	)11�self�inplanes�planesr	r*r�12base_widthr
�13norm_layer�	__class__s14         �rr zBasicBlock.__init__!s����
�j�$�(�*������J��Q�;�*��*��R�S�S��a�<�%�&P�Q�Q��X�v�v�6��15��f�%����G�G�D�)��	��V�V�,��16��f�%���$�����rc��|}|j|�}|j|�}|j|�}|j|�}|j	|�}|j17�|j|�}||z
}|j|�}|S�N)r$r%r'r(r)r*�r+�x�identity�outs    r�forwardzBasicBlock.forward3s{�����j�j��m���h�h�s�m���i�i��n���j�j��o���h�h�s�m���?�?�&����q�)�H��x����i�i��n���18r�rNrrrN��__name__�19__module__�__qualname__�	expansionr r7�
__classcell__�r0s@rrrs����I�KL�7;��$rrc�.��eZdZdZ		d�fd�	Zd�Z�xZS)�20Bottleneck�c	���tt|��|�tj}t||dzz�|z}	t
||	�|_||	�|_t|	|	|||�|_21||	�|_t
|	||jz�|_
|||jz�|_tjd��|_||_||_y)NgP@Tr)rrAr rr!�intrr$r%rr(r)r=�conv3�bn3r&r'r*r	)r+r,r-r	r*rr.r
r/�widthr0s          �rr zBottleneck.__init__Os����
�j�$�(�*������J��F�j�3�.�/�0�6�9���X�u�-��22��e�$����U�E�6�6�8�D��23��e�$����U�F�T�^�^�$;�<��24��f�t�~�~�5�6����G�G�D�)��	�$�����rc��|}|j|�}|j|�}|j|�}|j|�}|j	|�}|j|�}|j|�}|j
|�}|j�|j|�}||z
}|j|�}|Sr2)r$r%r'r(r)rErFr*r3s    rr7zBottleneck.forward`s������j�j��m���h�h�s�m���i�i��n���j�j��o���h�h�s�m���i�i��n���j�j��o���h�h�s�m���?�?�&����q�)�H��x����i�i��n���25rr8r9r?s@rrArAFs����I�KL�7;��"rrAc�:��eZdZ			d�fd�	Zdd�Zd�Zd�Z�xZS)�ResNetc	����tt|��|�tj}||_d|_d|_|�gd�}t|�dk7rtdj|���||_||_tjd|jdddd�	�|_||j�|_tj d26��|_tj$ddd��|_|j)|d|d
�|_|j)|d|dd|d
��|_|j)|d|dd|d��|_|j)|d|dd|d��|_|j3�D]�}	t5|	tj�r-tj6j9|	j:dd���Jt5|	tjtj<f�s�utj6j?|	j:d�tj6j?|	j@d
���|r�|j3�D]�}	t5|	tB�r5tj6j?|	jDj:d
��Ht5|	tF�s�Ytj6j?|	jHj:d
���yy)Nrr)FFFrzHreplace_stride_with_dilation should be None or a 3-element tuple, got {}��F)rr	r27rTr)rr	r28r�)r	�dilate�i�fan_outr')�mode�nonlinearity)%rrJr rr!�_norm_layerr,r
�lenr"�formatrr.rr$r%r&r'�	MaxPool2d�maxpool�_make_layer�layer1�layer2�layer3�layer4�modules�29isinstance�init�kaiming_normal_�weight�	GroupNorm�	constant_rrArFrr))r+�block�layers�num_classes�zero_init_residualr�width_per_group�replace_stride_with_dilationr/�mr0s          �rr zResNet.__init__ysi���	�f�d�$�&������J�%�����
���
�'�/�,A�(��+�,��1��<�<B�F�C_�<`�b�
b����)����Y�Y�q�$�-�-�Q�q�RS�$)�+��30��d�m�m�,����G�G�D�)��	��|�|��!�Q�G����&�&�u�b�&��)�<����&�&�u�c�6�!�9�Q�.J�1�.M�'�O����&�&�u�c�6�!�9�Q�.J�1�.M�'�O����&�&�u�c�6�!�9�Q�.J�1�.M�'�O���31����	-�A��!�R�Y�Y�'����'�'����y�v�'�V��A�������=�>����!�!�!�(�(�A�.����!�!�!�&�&�!�,�	-���\�\�^�
7���a��,��G�G�%�%�a�e�e�l�l�A�6���:�.��G�G�%�%�a�e�e�l�l�A�6�	
7�rc��|j}d}|j}|r|xj|zc_d}|dk7s|j||jzk7rKt	j32t
|j||jz|�|||jz��}g}	|	j||j||||j|j||��||jz|_td|�D]G}33|	j||j||j|j|j|����It	j34|	�S)Nr)rr.r
r/)rTr
r,r=r�35Sequentialr�appendrr.�range)r+rer-�blocksr	rOr/r*�previous_dilationrf�_s           rrYzResNet._make_layer�s'���%�%�36��37� �M�M����M�M�V�#�M��F��Q�;�$�-�-�6�E�O�O�+C�C������
�
�v����'?��H��6�E�O�O�3�4��J�38���
�
�e�D�M�M�6�6�:�t�{�{� �O�O�->�39�L�	M�����0��
��q�&�!�	8�A��M�M�%��
�
�v�d�k�k�+/�?�?�T�]�]�+5�7�
8�	8�40�}�}�f�%�%rc��g}|j|�}|j|�}|j|�}|j|�}|j	|�}|j|�|j
|�}|j|�|j|�}|j|�|j|�}|j|�|Sr2)	r$r%r'rXrZrnr[r\r])r+r4�featuress   r�
_forward_implzResNet._forward_impl�s������J�J�q�M���H�H�Q�K���I�I�a�L���L�L��O���K�K��N��������K�K��N��������K�K��N��������K�K��N��������rc�$�|j|�Sr2)ru)r+r4s  rr7zResNet.forward�s���!�!�!�$�$r)i�FrrNN)rF)r:r;r<r rYrur7r>r?s@rrJrJws!���KP�LP� �17�f&�0�4%rrJTc�@�d|d<d|d<ttgd�fi|��}|S)zyConstructs a ResNet-152 model.41    Args:42        pretrained (bool): If True, returns a model pre-trained on ImageNet43    � r�ri)rrB�r)rJrA)�44pretrained�kwargs�models   rrr�s/��45�F�8�� !�F����:�}�7��7�E��Lr�__main__)rMrrPrP)rrr)r)T)�torch.nnr�urllibr�ImportError�urllib.request�__all__�46model_urlsrr�ModulerrArJrr:�torch�cudar}�rand�rgbr6�printrU�rr�<module>r�s����+�"��47��Z�[��48�U�V�49%����%�P.����.�bh%�R�Y�Y�h%�X	��z����T�"�'�'�)�E�50�%�*�*�%�51&�52+�53+�54-�C�55��*�C�	�#�c�(�O�
��S�+�*�+�s�B8�8C�C