o
    )j4                     @   sp   d dl Zd dlm  mZ dddZdddZdd	d
Z				dddZ					dddZ	e
dkr6	 dS dS )    N    resblockc                 C   sr   t |* tj| |ddgd dd}t j|}tj||ddgd dd}||  W  d    S 1 s2w   Y  d S )N   Zconv1)activation_fnscopeZconv2)tfvariable_scopeslimconvolution2dnn
leaky_relu)inputsout_channelnamex r   e/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/models/cv/cartoon/network.pyr      s   $   c                 C   s  | j  }t| d|d g} tjdd|d gt dd}|}d }t|D ]}	 t|t| }tj	
|}t|| }tj	
|}q&t|}t|}tt|| t|}	t||g | |	 }
t|
|}
W d    |
S 1 s{w   Y  |
S )Nur   F)initializerZ	trainable)shapeZas_listr   Zreshapeget_variableZrandom_normal_initializerrangematmulZ	transposer   Zl2_normalizeZstop_gradientZcontrol_dependenciesZassign)w	iterationZw_shaper   Zu_hatZv_hatiZv_Zu_sigmaZw_normr   r   r   spectral_norm   s2   



r   
conv_snormc                 C   s   t |; t jd|d |d |  d |gd}t jd|gt dd}t jj| t|d||dgd	d
| } | W  d    S 1 sCw   Y  d S )NZkernelr   r   r   )r   Zbiasg        )r   ZSAME)inputfilterstridespadding)r   r   r   	get_shapeZconstant_initializerr   Zconv2dr   )r   channelZk_sizestrider   r   br   r   r   conv_spectral_norm3   s&   
$r)      	generatorFc                 C   s8  t j||d	 tj| |ddgd d}t j|}tj||ddgdd d}t j|}tj||d ddgd d}t j|}tj||d ddgdd d}t j|}tj||d ddgd d}t j|}t|D ]}t||d d|d	}qjtj||d ddgd d}t j|}t 	|d
 t 	|d }	}
t j
||	d |
d f}tj|| |d ddgd d}t j|}tj||ddgd d}t j|}t 	|d
 t 	|d }}t j
||d |d f}tj|| |ddgd d}t j|}tj|dddgd d}|W  d    S 1 sw   Y  d S )Nreuse   r   r      )r'   r   r*   zblock_{})r   r   r   )r   r   r	   r
   r   r   r   r   formatr   imageZresize_bilinear)r   r&   Z
num_blocksr   r-   Zx0x1Zx2idxZh1Zw1Zx3h2Zw2Zx4r   r   r   unet_generatorD   sH   &r6   Tdiscriminatorc              
   C   s   t j||d` tdD ]1}t| |d|  ddgdd|d} t j| } t| |d|  ddgd|d} t j| } q|du rMt| d	d	d	gd
d} nt j| d	dgd} tj	| d	d d} | W  d    S 1 sjw   Y  d S )Nr,   r   r0   zconv{}_1)r'   r   zconv{}_2)r   Tr   Zconv_out)Zaxisr/   )
r   r   r   r)   r1   r   r   Zreduce_meanr	   Zfully_connected)r   scaler&   patchr   r-   r4   r   r   r   disc_sns   s&   $r:   __main__)r   r   )r   )r   r    )r   r*   r+   F)r   r   Tr7   F)Z
tensorflowr   Ztensorflow.contrib.slimcontribr	   r   r   r)   r6   r:   __name__r   r   r   r   <module>   s&    


"
0
