
Xc           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d d d d d  Z e j	 e d d Z
 d   Z e d d	 g d
 dm dn do dp dq dr ds g  Z e d d d d g d
 dt g  Z d   Z e d d d g d
 du dv dw g d! e  Z e d d" d# d$ g d
 dx dy dz g  Z e d d( g d
 d{ g  Z e d d) g d
 d| g  Z d+   Z e d d	 g d
 d} d~ d d d d d d d d g
 d8 i i d9 d: 6d; d< 6d= d> 6d6 6d! e  Z e d d g d
 d g  Z e d d" d# d$ g d
 d d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z e d d" d# d$ g d
 d d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z e d
 d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z e d dF g d
 d g  Z e d dF g d
 d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z e d dF g d
 d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z dH   Z e d dI dJ g d
 d d d d d d d d d d g
 d! e  Z dN   Z e d dI dJ g d
 d d d d d d d d d d g
 d8 i i dA dB 6dC dD 6d dE 6d? 6d! e  Z dP   Z  e d dI dJ g d
 d d d d d d d g d8 i i dA dB 6dC dD 6d dE 6d? 6d! e   Z! dQ   Z" e d dI dJ g d
 d d d d d d d d d d g
 d8 i i dA dB 6dC dD 6d dE 6d? 6d! e"  Z# dR   Z$ e d dI dJ g d
 d d d d d d d d d d g
 d8 i i dA dB 6dC dD 6d dE 6d? 6d! e$  Z% dS   Z& dT   Z' e d dI dJ g d
 d d d d d d d d d d d d d g d8 i i dA dB 6dC dD 6d dE 6d? 6d! e'  Z( e d g  d
 d d g d! e&  Z) dY   Z* e d d$ g d
 d g d8 i i dA dB 6dC dD 6d dE 6d? 6d! e*  Z+ e d d$ g d
 d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z, e d dZ g d
 d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z- e d dZ g d
 d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z. e d d g d
 d g  Z/ e d d g d
 d d g d8 i i dA dB 6dC dD 6d dE 6d? 6 Z0 e d d[ d\ g  Z1 d]   Z2 e
 d d^ d_ d` g d
 d d d d d g d! e2  Z3 e d d d
 d d g  Z4 d S(   s5   Interface converters for Keras 1 support in Keras 2.
iNt   classc      	      sa     d  k r t  n t    p$ g     p0 g    p< g          f d   } | S(   Nc            sF   t  j            f d    } t j    | _ | S(   Nc             so   d k r |  d j  j } n	  j }  rI  |  |  \ }  } } n g  }  r t |   t    d k r t d | d t t     d t t     d t t |  d     q n  xL  D]D } | | k r | | } |  | k r | | | | <qq q Wxk  D]c \ } } | | k r| j |  } | | k r`t | |  n  | | | <| j	 | | f  qqW| rbd | d }	 x t
 |  d  D] \ }
 } t | t j  r|	 d	 | d	 7}	 nT t | t j  rd
 } n t |  } t |  d k r&| d  d } n  |	 | 7}	 |
 t |  d  d k  sP| r|	 d 7}	 qqWx t
 | j    D] \ }
 \ } } |	 | d 7}	 t | t j  r|	 d	 | d	 7}	 nT t | t j  rd
 } n t |  } t |  d k r| d  d } n  |	 | 7}	 |
 t |  d k  rt|	 d 7}	 qtqtW|	 d 7}	 t j d | d |	 d d n   |  |   S(   NR    i    i   t   `s   ` can accept only s    positional arguments s5   , but you passed the following positional arguments: t   (t   "t   arrayi
   s   ...s   , t   =s   )`s   Update your `s   ` call to the Keras 2 API: t
   stackleveli   (   t	   __class__t   __name__t   lent	   TypeErrort   strt   tuplet   listt   popt   raise_duplicate_arg_errort   appendt	   enumeratet
   isinstancet   sixt   string_typest   npt   ndarrayt   itemst   warningst   warn(   t   argst   kwargst   object_namet	   convertedt   keyt	   old_valuet   old_namet   new_namet   valuet	   signaturet   it   str_valt   name(   t   allowed_positional_argst   check_positional_argst   conversionst   funct   object_typet   preprocessort   value_conversions(    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   wrapper   sh    	3 

	
 %	

(   R   t   wrapst   inspectt
   getargspect   _legacy_support_signature(   R*   R.   (   R'   R(   R)   R+   R,   R-   (   R*   s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   legacy_support   s    0A(   t   Nonet   Falset   True(   R'   R)   R,   R-   R+   R3   (    (   R'   R(   R)   R+   R,   R-   s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   generate_legacy_interface
   s    	DR+   t   methodc         C   s(   t  d | d |  d | d   d  S(   Ns	   For the `sA   ` argument, the layer received both the legacy keyword argument `s$   ` and the Keras 2 keyword argument `s   `. Stick to the latter!(   R
   (   t   old_argt   new_arg(    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyR   b   s    R'   t   unitsR)   t
   output_dimt   initt   kernel_initializert   W_regularizert   kernel_regularizert   b_regularizert   bias_regularizert   W_constraintt   kernel_constraintt   b_constraintt   bias_constraintt   biast   use_biast   ratet   noise_shapet   seedt   pc         C   sB   g  } d | k r5 | j  d  t j d d d n  |  | | f S(   Nt   dropouts   The `dropout` argument is no longer support in `Embedding`. You can apply a `keras.layers.SpatialDropout1D` layer right after the `Embedding` layer to get the same behavior.R   i   (   R   R   R   (   R   R   R   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   embedding_kwargs_preprocessory   s    
t	   input_dimt   embeddings_initializert   embeddings_regularizert   embeddings_constraintR,   t	   pool_sizet   stridest   paddingt   pool_lengtht   stridet   border_modet   alpha_initializert   stddevt   sigmac         C   s   g  } d | k rl | d d k rI | j  d  t | d <| j d  ql | j  d  t j d d d n  d | k r | j  d d   } | j  d  } | | f } | | d	 <| j d  t j d
 d d n  |  | | f S(   Nt   forget_bias_initt   onet   unit_forget_biassm   The `forget_bias_init` argument has been ignored. Use `unit_forget_bias=True` instead to intialize with ones.R   i   RO   t   input_lengtht   input_shapesk   The `input_dim` and `input_length` arguments in recurrent layers are deprecated. Use `input_shape` instead.(   R\   R^   (   s	   input_dims   input_shape(   R   R6   R   R   R   R4   (   R   R   R   R_   RO   R`   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   recurrent_args_preprocessor   s$    



t
   inner_initt   recurrent_initializert   inner_activationt   recurrent_activationt   U_regularizert   recurrent_regularizert	   dropout_WRM   t	   dropout_Ut   recurrent_dropoutt   consume_lesst   implementationR-   i    t   cpui   t   memi   t   gput   dim_orderingt   data_formatt   channels_lastt   tft   channels_firstt   tht   defaultt   sizet   lengthc         C   sr   g  } d | k re d | k r0 | j  d  } n d  } | | j  d  f } | | d <| j d  n  |  | | f S(   NRO   R_   R`   (   s   input_shapes	   input_dim(   R   R4   R   (   R   R   R   Rx   R`   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   conv1d_args_preprocessor   s    
t   filterst   kernel_sizet	   nb_filtert   filter_lengtht   subsample_lengthc         C   s0  g  } t  |   d k r' t d   n  t  |   d k r t |  d t  r#t |  d t  r#d d d g } x) | D]! } | | k ru t d   qu qu W|  d |  d f } |  d	 |  d
 | g }  | j d  q#nKt  |   d k rLt |  d t  rLd | k r#|  d | j d  f } |  d	 |  d
 | g }  | j d  q#n t  |   d k rd | k r#d | k r#| j d  | j d  f } |  d	 |  d
 | g }  | j d  q#ne t  |   d
 k r#d | k r#d | k r#| j d  | j d  f } | | d <| j d  q#n  |  | | f S(   Ni   s1   Layer can receive at most 3 positional arguments.i   i   RU   RT   Rq   s   It seems that you are using the Keras 2 and you are passing both `kernel_size` and `strides` as integer positional arguments. For safety reasons, this is disallowed. Pass `strides` as a keyword argument instead.i    i   R{   s   nb_row/nb_colt   nb_colt   nb_row(   s   kernel_sizes   nb_row/nb_col(   s   kernel_sizes   nb_row/nb_col(   s   kernel_sizes   nb_row/nb_col(   s   kernel_sizes   nb_row/nb_col(   R	   R
   R   t   intt
   ValueErrorR   R   (   R   R   R   t   new_keywordst   kwdR{   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   conv2d_args_preprocessor	  s:    &%
t	   subsamplec         C   sn   g  } d | k rE | j  d  } | | d <| | d <| j d  n  t |  |  \ }  } } |  | | | f S(   NR=   t   depthwise_initializert   pointwise_initializers+   depthwise_initializer/pointwise_initializer(   s   inits+   depthwise_initializer/pointwise_initializer(   R   R   R   (   R   R   R   R=   t
   _converted(    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt"   separable_conv2d_args_preprocessor>  s    

c         C   s   g  } t  |   d k rH t |  d t  rH |  d  }  | j d  qH n  d | k rq | j d  | j d  n  t |  |  \ }  } } |  | | | f S(   Ni   i   it   output_shape(   R   N(   R   N(   R	   R   R   R   R4   R   R   (   R   R   R   R   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   deconv2d_args_preprocessorW  s    
c         C   s#  g  } t  |   d k r' t d   n  t  |   d k r t |  d t  rt |  d t  rt |  d t  r|  d |  d |  d f } |  d |  d | g }  | j d  qn_t  |   d k rt |  d t  rt |  d t  r@t |  d t  r@d
 d d g } x, | D]! } | | k rt d   qqWn  d | k r|  d |  d | j d  f } |  d |  d | g }  | j d  qnt  |   d k rd | k rd | k r|  d | j d  | j d  f } |  d |  d | g }  | j d  qnt  |   d k rd | k rd | k rd | k r| j d  | j d  | j d  f } |  d |  d | g }  | j d  qn} t  |   d k rd | k rd | k rd | k r| j d  | j d  | j d  f } | | d <| j d  qn  |  | | f S(   Ni   s1   Layer can receive at most 4 positional arguments.i   i   i   i    i   R{   s   kernel_dim*RU   RT   Rq   s   It seems that you are using the Keras 2 and you are passing both `kernel_size` and `strides` as integer positional arguments. For safety reasons, this is disallowed. Pass `strides` as a keyword argument instead.t   kernel_dim3t   kernel_dim2t   kernel_dim1s   nb_row/nb_col(   s   kernel_sizes   kernel_dim*(   s   kernel_sizes   kernel_dim*(   s   kernel_sizes   kernel_dim*(   s   kernel_sizes   kernel_dim*(   s   kernel_sizes   nb_row/nb_col(   R	   R
   R   R   R   R   R   (   R   R   R   R{   R   R   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   conv3d_args_preprocessoru  sR    9%& $$
c         C   sz   g  } t  |   d k r' t d   n  d | k rm | j d  } | d k r] t d   n  | j d  n  |  | | f S(   Ni   sc   The `BatchNormalization` layer does not accept positional arguments. Use keyword arguments instead.t   modei    sl   The `mode` argument of `BatchNormalization` no longer exists. `mode=1` and `mode=2` are no longer supported.(   s   modeN(   R	   R
   R   R   R4   (   R   R   R   R"   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   batchnorm_args_preprocessor  s    c         C   s   g  } d | k r] | j  d  } | d k rG t | d <| j d  q] t j d d d n  t |  |  \ }  } } |  | | | f S(   NR\   R]   R^   sm   The `forget_bias_init` argument has been ignored. Use `unit_forget_bias=True` instead to intialize with ones.R   i   (   s   forget_bias_inits   unit_forget_bias(   R   R6   R   R   R   R   (   R   R   R   R"   R   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   convlstm2d_args_preprocessor  s    

t	   beta_initt   beta_initializert
   gamma_initt   gamma_initializerc         C   s  g  } d | k r t  | d t  r t | d j    d d d d h k r| d j d d  } | d j d d  } | d j d d  } | d j d d  } | | f | | f f | d <t j d d d	 qn t |   d
 k rt  |  d t  rt |  d j    d d d d h k r|  d j d d  } |  d j d d  } |  d j d d  } |  d j d d  } |  d | | f | | f f f }  t j d d d	 qn  |  | | f S(   NRU   t   top_padt
   bottom_padt   left_padt	   right_padi    s   The `padding` argument in the Keras 2 API no longeraccepts dict types. You can now input argument as: `padding=(top_pad, bottom_pad, left_pad, right_pad)`.R   i   i   i   s   The `padding` argument in the Keras 2 API no longeraccepts dict types. You can now input argument as: `padding=((top_pad, bottom_pad), (left_pad, right_pad))`(   R   t   dictt   sett   keyst   getR   R   R	   (   R   R   R   R   R   R   R   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   zeropadding2d_args_preprocessor  s,    %"t   croppingt   functionR   c         C   s   g  } t  |   d k  r d | k r | j d  } t  |   d k rR |  d } n
 | d } t | d  r | | j | d <n t j d d d | | d <| j d	  q n  |  | | f S(
   Ni   t   samples_per_epochi   t	   generatort
   batch_sizet   steps_per_epochs   The semantics of the Keras 2 argument  `steps_per_epoch` is not the same as the Keras 1 argument `samples_per_epoch`. `steps_per_epoch` is the number of batches to draw from the generator at each epoch. Update your method calls accordingly.R   (   s   samples_per_epochR   (   R	   R   t   hasattrR   R   R   R   (   R   R   R   R   R   (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt#   generator_methods_args_preprocessor8  s    

R   R   t   epochsR   t   val_samplest   stepst   nb_epocht   nb_val_samplest   validation_stepst	   nb_workert   workerst   inputt   inputst   outputt   outputs(   R<   R;   (   s   initR>   (   R?   R@   (   RA   RB   (   RC   RD   (   RE   RF   (   RG   RH   (   RL   RI   (   s   initRP   (   R?   RQ   (   RC   RR   (   RV   RS   (   RW   s   strides(   RX   s   padding(   s   initRY   (   s   sigmas   stddev(   R<   R;   (   s   initR>   (   Rb   Rc   (   Rd   Re   (   R?   R@   (   RA   RB   (   Rf   Rg   (   Rh   s   dropout(   Ri   Rj   (   Rk   s   implementation(   RL   RI   (   RX   s   padding(   Rp   s   data_format(   RX   s   padding(   Rp   s   data_format(   Rp   s   data_format(   s   lengths   size(   Rp   s   data_format(   Rp   s   data_format(   R|   s   filters(   R}   s   kernel_size(   R~   s   strides(   RX   s   padding(   s   initR>   (   R?   R@   (   RA   RB   (   RC   RD   (   RE   RF   (   RG   RH   (   R|   s   filters(   R   s   strides(   RX   s   padding(   Rp   s   data_format(   s   initR>   (   R?   R@   (   RA   RB   (   RC   RD   (   RE   RF   (   RG   RH   (   R|   s   filters(   R   s   strides(   RX   s   padding(   Rp   s   data_format(   RA   RB   (   RE   RF   (   RG   RH   (   R|   s   filters(   R   s   strides(   RX   s   padding(   Rp   s   data_format(   s   initR>   (   R?   R@   (   RA   RB   (   RC   RD   (   RE   RF   (   RG   RH   (   R|   s   filters(   R   s   strides(   RX   s   padding(   Rp   s   data_format(   s   initR>   (   R?   R@   (   RA   RB   (   RC   RD   (   RE   RF   (   RG   RH   (   R|   s   filters(   R   s   strides(   RX   s   padding(   Rp   s   data_format(   s   initR>   (   Rb   Rc   (   R?   R@   (   Rf   Rg   (   RA   RB   (   Rd   Re   (   Rh   s   dropout(   Ri   Rj   (   RG   RH   (   R   R   (   R   R   (   Rp   s   data_format(   Rp   s   data_format(   Rp   s   data_format(   Rp   s   data_format(   RL   RI   (   RL   RI   (   Rp   s   data_format(   s   samples_per_epochs   steps_per_epoch(   R   R   (   R   R   (   R   R   (   R   R   (   s   inputs   inputs(   s   outputs   outputs(5   t   __doc__R   R   t	   functoolsR0   t   numpyR   R4   R7   t   partialt    generate_legacy_method_interfaceR   t   legacy_dense_supportt   legacy_dropout_supportRN   t   legacy_embedding_supportt   legacy_pooling1d_supportt   legacy_prelu_supportt   legacy_gaussiannoise_supportRa   t   legacy_recurrent_supportt   legacy_gaussiandropout_supportt   legacy_pooling2d_supportt   legacy_pooling3d_supportt   legacy_global_pooling_supportt   legacy_upsampling1d_supportt   legacy_upsampling2d_supportt   legacy_upsampling3d_supportRy   t   legacy_conv1d_supportR   t   legacy_conv2d_supportR   t   legacy_separable_conv2d_supportR   t   legacy_deconv2d_supportR   t   legacy_conv3d_supportR   R   t   legacy_convlstm2d_supportt   legacy_batchnorm_supportR   t   legacy_zeropadding2d_supportt   legacy_zeropadding3d_supportt   legacy_cropping2d_supportt   legacy_cropping3d_supportt   legacy_spatialdropout1d_supportt   legacy_spatialdropoutNd_supportt   legacy_lambda_supportR   t    legacy_generator_methods_supportt    legacy_model_constructor_support(    (    (    s6   /tmp/pip-build-isqEY4/keras/keras/legacy/interfaces.pyt   <module>   s  P																										#			
						/																								