B
    «»ˆd  ã               @   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                s^   t ƒ jf |Ž t|ƒ| _t|ƒttdt|ƒd ƒƒkrDt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   Z
input_spec)Úselfr   Úkwargs)Ú	__class__© úP/var/www/html/venv/lib/python3.7/site-packages/keras/layers/reshaping/permute.pyr	   <   s    
zPermute.__init__c             C   sN   t  |¡ ¡ }t |¡}x*t| jƒD ]\}}|| }|||d < q$W t  |¡S )Nr   )ÚtfZTensorShapeÚas_listÚcopyÚ	enumerater   )r   Zinput_shapeZoutput_shapeÚiÚdimZ
target_dimr   r   r   Úcompute_output_shapeG   s    
zPermute.compute_output_shapec             C   s   t j|d| j dS )N)r   )Zperm)r   Z	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   ÚconfigZbase_config)r   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   Ztensorflow.compat.v2ÚcompatZv2r   Zkeras.engine.base_layerr   Zkeras.engine.input_specr   Z tensorflow.python.util.tf_exportr   r   r   r   r   r   Ú<module>   s   