σ
ΎχXc           @@ sM  d  Z  d d l m Z d d l 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 d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d Z d Z e d d d d d d  Z  d S(   s   VGG19 model for Keras.

# Reference

- [Very Deep Convolutional Networks for Large-Scale Image Recognition](https://arxiv.org/abs/1409.1556)

i    (   t   print_function(   t   absolute_importNi   (   t   Model(   t   Flatten(   t   Dense(   t   Input(   t   Conv2D(   t   MaxPooling2D(   t   GlobalAveragePooling2D(   t   GlobalMaxPooling2D(   t   get_source_inputs(   t   layer_utils(   t   get_file(   t   backendi   (   t   decode_predictions(   t   preprocess_input(   t   _obtain_input_shapess   https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels.h5sy   https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5t   imagenetiθ  c         C@ s¬  | d d@ h k r! t d   n  | d k rN |  rN | d k rN t d   n  t | d d d d d	 t j   d
 |  } | d@ k r t d |  } n- t j |  s½ t d | d |  } n | } t d dA d d d d d d |  } t d dB d d d d d d |  } t dC d dD d d |  } t d dE d d d d d d |  } t d dF d d d d d d |  } t dG d dH d d |  } t d dI d d d d d d |  } t d dJ d d d d d d |  } t d dK d d d d d d  |  } t d dL d d d d d d! |  } t dM d dN d d" |  } t d# dO d d d d d d$ |  } t d# dP d d d d d d% |  } t d# dQ d d d d d d& |  } t d# dR d d d d d d' |  } t dS d dT d d( |  } t d# dU d d d d d d) |  } t d# dV d d d d d d* |  } t d# dW d d d d d d+ |  } t d# dX d d d d d d, |  } t dY d dZ d d- |  } |  rAt	 d d.  |  } t
 d/ d d d d0 |  } t
 d/ d d d d1 |  } t
 | d d2 d d3 |  } n< | d4 k r_t   |  } n | d5 k r}t   |  } n  | d@ k	 rt |  } n | } t | | d d6 }	 | d k r¨|  rέt d7 t d8 d9 }
 n t d: t d8 d9 }
 |	 j |
  t j   d; k r!t j |	  n  t j   d< k r¨|  r|	 j d d-  } | j d= } |	 j d d0  } t j | | d<  n  t j   d> k r₯t j d?  q₯q¨n  |	 S([   si  Instantiates the VGG19 architecture.

    Optionally loads weights pre-trained
    on ImageNet. Note that when using TensorFlow,
    for best performance you should set
    `image_data_format="channels_last"` in your Keras config
    at ~/.keras/keras.json.

    The model and the weights are compatible with both
    TensorFlow and Theano. The data format
    convention used by the model is the one
    specified in your Keras config file.

    # Arguments
        include_top: whether to include the 3 fully-connected
            layers at the top of the network.
        weights: one of `None` (random initialization)
            or "imagenet" (pre-training on ImageNet).
        input_tensor: optional Keras tensor (i.e. output of `layers.Input()`)
            to use as image input for the model.
        input_shape: optional shape tuple, only to be specified
            if `include_top` is False (otherwise the input shape
            has to be `(224, 224, 3)` (with `channels_last` data format)
            or `(3, 224, 244)` (with `channels_first` data format).
            It should have exactly 3 inputs channels,
            and width and height should be no smaller than 48.
            E.g. `(200, 200, 3)` would be one valid value.
        pooling: Optional pooling mode for feature extraction
            when `include_top` is `False`.
            - `None` means that the output of the model will be
                the 4D tensor output of the
                last convolutional layer.
            - `avg` means that global average pooling
                will be applied to the output of the
                last convolutional layer, and thus
                the output of the model will be a 2D tensor.
            - `max` means that global max pooling will
                be applied.
        classes: optional number of classes to classify images
            into, only to be specified if `include_top` is True, and
            if no `weights` argument is specified.

    # Returns
        A Keras model instance.

    # Raises
        ValueError: in case of invalid argument for `weights`,
            or invalid input shape.
    R   sp   The `weights` argument should be either `None` (random initialization) or `imagenet` (pre-training on ImageNet).iθ  sS   If using `weights` as imagenet with `include_top` as true, `classes` should be 1000t   default_sizeiΰ   t   min_sizei0   t   data_formatt   include_topt   shapet   tensori@   i   t
   activationt   relut   paddingt   samet   namet   block1_conv1t   block1_conv2i   t   stridest   block1_pooli   t   block2_conv1t   block2_conv2t   block2_pooli   t   block3_conv1t   block3_conv2t   block3_conv3t   block3_conv4t   block3_pooli   t   block4_conv1t   block4_conv2t   block4_conv3t   block4_conv4t   block4_poolt   block5_conv1t   block5_conv2t   block5_conv3t   block5_conv4t   block5_poolt   flatteni   t   fc1t   fc2t   softmaxt   predictionst   avgt   maxt   vgg19s+   vgg19_weights_tf_dim_ordering_tf_kernels.h5t   cache_subdirt   modelss1   vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5t   theanot   channels_firsti   t
   tensorflowsς   You are using the TensorFlow backend, yet you are using the Theano image data format convention (`image_data_format="channels_first"`). For best performance, set `image_data_format="channels_last"` in your Keras config at ~/.keras/keras.json.N(   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   t   Nonet
   ValueErrorR   t   Kt   image_data_formatR   t   is_keras_tensorR   R   R   R   R   R	   R
   R   R   t   WEIGHTS_PATHt   WEIGHTS_PATH_NO_TOPt   load_weightsR   R   t   convert_all_kernels_in_modelt	   get_layert   output_shapet!   convert_dense_weights_data_formatt   warningst   warn(   R   t   weightst   input_tensort   input_shapet   poolingt   classest	   img_inputt   xt   inputst   modelt   weights_patht   maxpoolR   t   dense(    (    s7   /tmp/pip-build-isqEY4/keras/keras/applications/vgg19.pyt   VGG19#   s    5		''''''''''''''''!	(!   t   __doc__t
   __future__R    R   RL   R<   R   t   layersR   R   R   R   R   R   R	   t   engine.topologyR
   t   utilsR   t   utils.data_utilsR   t    R   RB   t   imagenet_utilsR   R   R   RE   RF   t   TrueR@   RZ   (    (    (    s7   /tmp/pip-build-isqEY4/keras/keras/applications/vgg19.pyt   <module>   s0   