o
    oi                     @   sn   d dl mZmZmZmZmZ d dlZd dlmZ d dl	m
Z d dl	mZ d dlmZ dgZG dd deZdS )	    )AnyListOptionalTupleUnionN)Tensor)PILImage)onnx)	ModelBaseSuperResolutionc                       sP  e Zd ZU dZdZeed< ee ed< ee ed< ee ed< e	
 deeee f deeee f fd	d
Z		ddeeee f deeeee f  dedeeee ed f fddZ			ddeeee f deeeee f  dee deddf
ddZ				d dee dededeeeeef   deddf fddZ  ZS )!r   zASuperResolution is a module that wraps an super resolution model.super_resolutionnameinput_image_sizeoutput_image_sizepseudo_image_sizeimagesreturnc                    sX     |}t|ttfr|d }n|}t|tr" fdd|D }n |} |S )a  Forward pass of the super resolution model.

        Args:
            images: If list of RGB images. Each image is a Tensor with shape :math:`(3, H, W)`.
                If Tensor, a Tensor with shape :math:`(B, 3, H, W)`.

        Returns:
            output tensor.

        r   c                    s   g | ]}  |d  d qS )Nr   )model).0imageself W/home/ubuntu/.local/lib/python3.10/site-packages/kornia/models/super_resolution/base.py
<listcomp>?   s    z+SuperResolution.forward.<locals>.<listcomp>)pre_processor
isinstancelisttupler   post_processor)r   r   output
out_imagesr   r   r   forward'   s   




zSuperResolution.forwardNtorch	edge_mapsoutput_typezImage.Imagec                 C   s@   |du r	|  |}g }|D ]}|| q| j||t|tdS )zDraw the super resolution results.

        Args:
            images: input tensor.
            edge_maps: detected edges.
            output_type: type of the output.

        Returns:
            output tensor.

        N)is_batch)r"   append_tensor_to_typer   r   )r   r   r$   r%   r    edge_mapr   r   r   	visualizeD   s   
zSuperResolution.visualize	directoryc                 C   s2   |  |||}| j||dd | j||dd dS )aG  Save the super resolution results.

        Args:
            images: input tensor.
            edge_maps: detected edges.
            output_type: type of the output.
            directory: where to save outputs.
            output_type: backend used to generate outputs.

        Returns:
            output tensor.

        _src)suffix_srN)r*   _save_outputs)r   r   r$   r+   r%   outputsr   r   r   save]   s   zSuperResolution.saveT	onnx_nameinclude_pre_and_post_processorr1   additional_metadatakwargszonnx.ModelProtoc              	      s~   |du rd| j  d}t j|fdd| jpd| jpdgdd| jp!d| jp%dgdd| jp,d| jp0dg|r5| n| j||d|S )	a?  Export the current super resolution model to an ONNX model file.

        Args:
            onnx_name:
                The name of the output ONNX file. If not provided, a default name in the
                format "Kornia-<ClassName>.onnx" will be used.
            image_size:
                The size to which input images will be resized during preprocessing.
                If None, image_size will be dynamic. For DexiNed, recommended scale is 352.
            include_pre_and_post_processor:
                Whether to include the pre-processor and post-processor in the exported model.
            save:
                If to save the model or load it.
            additional_metadata:
                Additional metadata to add to the ONNX model.
            kwargs: Additional arguments for converting to onnx.

        Nkornia_z.onnx      i`  )input_shapeoutput_shapepseudo_shaper   r1   r4   )r   superto_onnxr   r   r   r   )r   r2   r3   r1   r4   r5   	__class__r   r   r>   u   s   zSuperResolution.to_onnx)Nr#   )NNr#   )NTTN)__name__
__module____qualname____doc__r   str__annotations__r   intr#   inference_moder   r   r   r"   r*   r1   boolr   r   r>   __classcell__r   r   r?   r   r      sd   
 ,

)typingr   r   r   r   r   r#   kornia.corer   kornia.core.externalr   Imager	   kornia.models.baser
   __all__r   r   r   r   r   <module>   s   