
    g	                     Z    d dl mZ d dlZd dlmZ d dlmZ  G d dej                        Zy)    )OptionalN)nn)
functionalc                        e Zd ZdZ	 d	dedeej                     f fdZde	j                  de	j                  de	j                  fdZ xZS )

FOVNetworkz!Field of View estimation network.num_featuresfov_encoderc                 r   t         |           t        j                  ||dz  ddd      t        j                  d      g}t        j                  |dz  |dz  ddd      t        j                  d      t        j                  |dz  |dz  ddd      t        j                  d      t        j                  |dz  dddd	      g}|Tt        j
                  |t        j                  |j                  |dz              | _        t        j
                  | | _	        n||z   }t        j
                  | | _
        y
)zInitialize the Field of View estimation block.

        Args:
        ----
            num_features: Number of features used.
            fov_encoder: Optional encoder to bring additional network capacity.

                 )kernel_sizestridepaddingT         r   N)super__init__r   Conv2dReLU
SequentialLinear	embed_dimencoder
downsamplehead)selfr   r	   	fov_head0fov_head	__class__s        B/home/cameronsmith/repos/ml-depth-pro/src/depth_pro/network/fov.pyr   zFOVNetwork.__init__   s"    	 IIla/QqRS GGDM	
	 II!<1#4!AWX GGDMII!<1#4!AWX GGDMIIla'!QO

 "==RYY{'<'<la>OPDL !mmY7DO 8+HMM8,	    xlowres_featurereturnc                    t        | d      rkt        j                  |dddd      }| j                  |      ddddf   j	                  dd	d      }| j                  |      }|j                  |      |z   }n|}| j                  |      S )
zForward the fov network.

        Args:
        ----
            x (torch.Tensor): Input image.
            lowres_feature (torch.Tensor): Low resolution feature.

        Returns:
        -------
            The field of view tensor.

        r   Ng      ?bilinearF)sizescale_factormodealign_cornersr   r   r   )hasattrFinterpolater   permuter   
reshape_asr   )r   r$   r%   s      r"   forwardzFOVNetwork.forward8   s     4#!#A Q12&..q!Q7A!__^<N^,~=AAyy|r#   )N)__name__
__module____qualname____doc__intr   r   Moduler   torchTensorr2   __classcell__)r!   s   @r"   r   r      sR    +
 ,0(-(- bii((-T u||  r#   r   )	typingr   r9   r   torch.nnr   r.   r8   r    r#   r"   <module>r?      s%       $G Gr#   