a
    Sic  ã                   @   s^   d Z ddlZddlm  mZ ddlmZ ddlm	Z	 ddl
mZ edƒG dd„ deƒƒZdS )	zContains the Permute layer.é    N)ÚLayer)Ú	InputSpec)Úkeras_exportzkeras.layers.Permutec                       s<   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡ fdd	„Z‡  ZS )
ÚPermuteaf  Permutes the dimensions of the input according to a given pattern.

    Useful e.g. connecting RNNs and convnets.

    Example:

    ```python
    model = Sequential()
    model.add(Permute((2, 1), input_shape=(10, 64)))
    # now: model.output_shape == (None, 64, 10)
    # note: `None` is the batch dimension
    ```

    Args:
      dims: Tuple of integers. Permutation pattern does not include the
        samples dimension. Indexing starts at 1.
        For instance, `(2, 1)` permutes the first and second dimensions
        of the input.

    Input shape:
      Arbitrary. Use the keyword argument `input_shape`
      (tuple of integers, does not include the samples axis)
      when using this layer as the first layer in a model.

    Output shape:
      Same as the input shape, but with the dimensions re-ordered according
      to the specified pattern.
    c                    sb   t ƒ jf i |¤Ž t|ƒ| _t|ƒttdt|ƒd ƒƒkrHtd|› ƒ‚t	t| jƒd d| _
d S )Né   zˆInvalid permutation argument `dims` for Permute Layer. The set of indices in `dims` must be consecutive and start from 1. Received dims=)Úndim)ÚsuperÚ__init__ÚtupleÚdimsÚsortedÚlistÚrangeÚlenÚ
ValueErrorr   Ú
input_spec)Úselfr   Úkwargs©Ú	__class__© úZ/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/layers/reshaping/permute.pyr	   <   s    
þÿzPermute.__init__c                 C   sJ   t  |¡ ¡ }t |¡}t| jƒD ]\}}|| }|||d < q"t  |¡S )Nr   )ÚtfÚTensorShapeÚas_listÚcopyÚ	enumerater   )r   Úinput_shapeÚoutput_shapeÚiÚdimÚ
target_dimr   r   r   Úcompute_output_shapeG   s    
zPermute.compute_output_shapec                 C   s   t j|d| j dS )N)r   )Úperm)r   Ú	transposer   )r   Úinputsr   r   r   ÚcallO   s    zPermute.callc                    s0   d| j i}tƒ  ¡ }tt| ¡ ƒt| ¡ ƒ ƒS )Nr   )r   r   Ú
get_configÚdictr   Úitems)r   ÚconfigÚbase_configr   r   r   r'   R   s    

zPermute.get_config)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r"   r&   r'   Ú__classcell__r   r   r   r   r      s
   r   )r/   r   Útensorflow.compat.v2ÚcompatÚv2r   Úkeras.engine.base_layerr   Úkeras.engine.input_specr   Ú tensorflow.python.util.tf_exportr   r   r   r   r   r   Ú<module>   s   