
     hB                     R    d dl Z d dlZd dlmZ d Z G d de      Z G d de      Zy)    N)
PatchEmbedc                 :    | dv sJ  t        |       ||d|      }|S )N)PatchEmbedDust3RManyAR_PatchEmbed   )eval)patch_embed_clsimg_size
patch_sizeenc_embed_dimpatch_embeds        @/home/cameronsmith/repos/controll3r/dust3r/dust3r/patch_embed.pyget_patch_embedr      s+    GGG'$'*aOK    c                       e Zd Zd Zy)r   c                    |j                   \  }}}}|| j                  d   z  dk(  sJ d| d| j                  d    d       || j                  d   z  dk(  sJ d| d| j                  d    d       | j                  |      }| j                  ||j	                  d      |j	                  d      |j
                        }| j                  r!|j                  d      j                  dd      }| j                  |      }||fS )	Nr   Input image height (#) is not a multiple of patch size ().   Input image width (   r   )	shaper   projposition_gettersizedeviceflatten	transposenorm)selfxkwBCHWposs           r   forwardzPatchEmbedDust3R.forward   s    WW
1a4??1%%*.B1#Ehimixixyzi{h||~,4??1%%*~.A!Dghlhwhwxyhzg{{},~~IIaL""1affQiAHHE<<		!&&q!,AIIaL#vr   N)__name__
__module____qualname__r)    r   r   r   r      s    	r   r   c                   *     e Zd ZdZd fd	Zd Z xZS )r   z Handle images with non-square aspect ratio.
        All images in the same batch have the same aspect ratio.
        true_shape = [(height, width) ...] indicates the actual shape of each image.
    c                 <    || _         t        | 	  ||||||       y )N)	embed_dimsuper__init__)r!   r
   r   in_chansr0   
norm_layerr   	__class__s          r   r2   zManyAR_PatchEmbed.__init__&   s"    ":xJPWXr   c                 @   |j                   \  }}}}||k\  sJ d|d|       || j                  d   z  dk(  sJ d| d| j                  d    d       || j                  d   z  dk(  sJ d| d| j                  d    d       |j                   |d	fk(  sJ d
|j                           || j                  d   z  }|| j                  d   z  }||z  }|j                  \  }}	|	|k\  }
|
 }|j                  ||| j                  f      }|j                  ||d	ft
        j                        }| j                  ||
         j                  dd	dd      j                  dd	      j                         ||
<   | j                  ||   j                  dd            j                  dd	dd      j                  dd	      j                         ||<   | j                  d|||j                        ||
<   | j                  d|||j                        ||<   | j                  |      }||fS )Nz+img should be in landscape mode, but got W=z H=r   r   r   r   r   r   r   ztrue_shape has the wrong shape=)dtyper   )r   r   T	new_zerosr0   torchint64r   permuter   floatswapaxesr   r   r    )r!   img
true_shaper$   r%   r&   r'   n_tokensheightwidthis_landscapeis_portraitr"   r(   s                 r   r)   zManyAR_PatchEmbed.forward*   sA   YY
1aAvLE1$dtLL4??1%%*.B1#Ehimixixyzi{h||~,4??1%%*~.A!Dghlhwhwxyhzg{{},~~Aq6)_-LZM]M]L^+__ 	
dooa  	dooa  q5"#m MM1h78mmQ!,EKKm@ ))C$56>>q!QJRRSTVWX^^`,3{#3#<#<R#DEMMaQRTUWXYaabcefgmmo+ 00Aq#**EL//1aDKIIaL#vr   )      r   i   NT)r*   r+   r,   __doc__r2   r)   __classcell__)r5   s   @r   r   r       s    
Yr   r   )r<   dust3r.utils.path_to_crocodust3rmodels.blocksr   r   r   r   r-   r   r   <module>rO      s-     ! $
z 
& &r   