o
    ߥi~                     @   s\   d dl mZ d dlZd dlmZmZ ddlmZm	Z	m
Z
mZ ddlmZ G dd deZdS )	    )DictN)ModelTensor   )content_lossguided_filter
style_losstotal_variation_loss)unet_generatorc                       s~   e Zd Z fddZ		ddeeef deeef deeef deeef fdd	Zd
eeef deeef fddZ  Z	S )CartoonModelc                    s$   t  j|g|R i | || _d S )N)super__init__	model_dir)selfr   argskwargs	__class__ Y/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/cv/cartoon/model_tf.pyr      s   
zCartoonModel.__init__Ninput_photoinput_cartooninput_superpixelreturnc                 C   s   |du rt |}t||dd}d|iS t |}t||dd}t| j|||}t||\}}t|}	d| d|  d|	  }
|}||
|dS )	a9  return the result by the model

        Args:
            input_photo: the preprocessed input photo image
            input_cartoon: the preprocessed input cartoon image
            input_superpixel: the computed input superpixel image

        Returns:
            output_dict: output dict of target ids
        Nr   )routput_cartoong?g      i@g     @)r   g_lossd_loss)r
   r   r   r   r   r	   )r   r   r   r   outputr   con_loss
sty_g_loss
sty_d_losstv_lossr   r   r   r   r   __call__   s"   zCartoonModel.__call__inputc                 C   s   dS )z
        Run the forward pass for a model.

        Args:
            input (Dict[str, Tensor]): the dict of the model inputs for the forward method

        Returns:
            Dict[str, Tensor]: output from the model forward pass
        Nr   )r   r$   r   r   r   forward7   s    zCartoonModel.forward)NN)
__name__
__module____qualname__r   r   strr   r#   r%   __classcell__r   r   r   r   r      s    




*%r   )typingr   
tensorflowtfmodelscope.models.baser   r   lossr   r   r   r	   networkr
   r   r   r   r   r   <module>   s   