o
    i0                     @   s`   d dl mZ d dl mZmZ d dlZd dlmZ d dlm	Z	 d dl
mZmZ G dd de	ZdS )    )Dict)ListSequenceN)DPT)activate_head_gscustom_interpolatec                       s   e Zd Z													
	d#dededededededee dededededededdf fddZdee	j
 dededed e	j
deee	j
f fd!d"Z  ZS )$GSDPT      linearsigmoid   r   i      r   TF   idtdim_in
patch_size
output_dim
activationconf_activationfeaturesout_channels	pos_embedfeature_only
down_ratioconf_dim	norm_typefusion_block_inplacereturnNc                    s   t  j|||||||||
dd||d || _|r$|dkr$|dks$J d|	r(|n|d }ttd|d	 dddt t|d	 |d dddt t|d |dddt | _d S )
Nraw_gsF)r   r   r   r   r   r   r   r   r   	head_nameuse_sky_headr   r   r   r   z7use linear prediction when using view-dependent opacity      r
   )super__init__r   nn
SequentialConv2dGELUimages_merger)selfr   r   r   r   r   r   r   r   r   r   r   r   r   Zmerger_out_dim	__class__ :/data/cameron/da3_repo/src/depth_anything_3/model/gsdpt.pyr&      s:   

zGSDPT.__init__featsHWpatch_start_idximagesc                 C   s  |d j \}}}|| j || j }	}
g }t| jD ]?\}}|| d d |d f }| |}|ddd|||	|
}| j| |}| jrM| 	|||}| j
| |}|| q| |}| j|}t|	| j | j }t|
| j | j }t|||fddd}|| | }| jr| 	|||}|}| j|}i }| jrt|| j| j| jd\}}|d|| j< |d|| j d< |S | |d|| j< |S )	Nr   r#   r   bilinearT)modealign_corners)r   r   r   _conf)shaper   	enumerateintermediate_layer_idxnormpermutereshapeprojectsr   _add_pos_embedresize_layersappend_fusescratchoutput_conv1intr   r   r+   output_conv2has_confr   r   r   r   squeeze	head_main_apply_activation_single)r,   r1   r2   r3   r4   r5   B_Cphpwresized_feats	stage_idxtake_idxxfusedh_outw_outfeatmain_logitsoutspredconfr/   r/   r0   _forward_implL   sF   


zGSDPT._forward_impl)r	   r
   r   r   r   r   TFr   r   r   F)__name__
__module____qualname__rG   strr   boolr&   r   torchTensorTyDictr^   __classcell__r/   r/   r-   r0   r      sn    	
2r   )typingr   rf   r   r   rd   torch.nnr'   depth_anything_3.model.dptr   'depth_anything_3.model.utils.head_utilsr   r   r   r/   r/   r/   r0   <module>   s   