σ
ΙΘχXc           @` sA  d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l	 Z
 d d l	 m Z d d l Z d d l m Z d d l
 Z d d	 l m Z e j j j Z e j j j d
 d d  e j j j d d d  e j j j d e d  d   Z d d  Z e d k r=e j j   n  d S(   st  A binary to train CIFAR-10 using a single GPU.

Accuracy:
cifar10_train.py achieves ~86% accuracy after 100K steps (256 epochs of
data) as judged by cifar10_eval.py.

Speed: With batch_size 128.

System        | Step Time (sec/batch)  |     Accuracy
------------------------------------------------------------------
1 Tesla K20m  | 0.35-0.60              | ~86% at 60K steps  (5 hours)
1 Tesla K40m  | 0.25-0.35              | ~86% at 100K steps (4 hours)

Usage:
Please see the tutorial and website for how to download the CIFAR-10
data set, compile the program and train the model.

http://tensorflow.org/tutorials/deep_cnn/
i    (   t   absolute_import(   t   division(   t   print_function(   t   datetimeN(   t   gfile(   t   xrange(   t   cifar10t	   train_dirs   /tmp/cifar10_trains3   Directory where to write event logs and checkpoint.t	   max_stepsi@B s   Number of batches to run.t   log_device_placements    Whether to log device placement.c          C` sT  t  j   j   <t  j d d t }  t j   \ } } t j |  } t j | |  } t j	 | |   } t  j	 j
 t  j    } t  j   } t  j   } t  j d t  j d t j   }	 |	 j |  t  j	 j d |	  t  j	 j t j d |	 j }
 xKt t j  D]:} t j   } |	 j | | g  \ } } t j   | } t j |  set d   | d d k rΐt j } | | } t |  } d	 } t | t  j!   | | | | f  n  | d
 d k rς|	 j |  } |
 j" | |  n  | d d k s| d t j k rt# j$ j% t j d  } | j& |	 | d | qqWWd QXd S(   s%   Train CIFAR-10 for a number of steps.i    t	   trainablet   configR	   t   sesst	   graph_defs   Model diverged with loss = NaNi
   s<   %s: step %d, loss = %.2f (%.1f examples/sec; %.3f sec/batch)id   iθ  i   s
   model.ckptt   global_stepN('   t   tft   Grapht
   as_defaultt   Variablet   FalseR   t   distorted_inputst	   inferencet   losst   traint   Savert   all_variablest   merge_all_summariest   initialize_all_variablest   Sessiont   ConfigProtot   FLAGSR	   t   runt   start_queue_runnerst   SummaryWriterR   R   R   R   t   timet   npt   isnant   AssertionErrort
   batch_sizet   floatt   printR   t   nowt   add_summaryt   ost   patht   joint   save(   R   t   imagest   labelst   logitsR   t   train_opt   savert
   summary_opt   initR   t   summary_writert   stept
   start_timet   _t
   loss_valuet   durationt   num_examples_per_stept   examples_per_sect   sec_per_batcht
   format_strt   summary_strt   checkpoint_path(    (    so   /tmp/pip-build-UG86a1/tensorflow/tensorflow-0.6.0.data/purelib/tensorflow/models/image/cifar10/cifar10_train.pyR   ?   sB    	
#c         C` sJ   t  j   t j t j  r/ t j t j  n  t j t j  t   d  S(   N(	   R   t   maybe_download_and_extractR   t   ExistsR   R   t   DeleteRecursivelyt   MakeDirsR   (   t   argv(    (    so   /tmp/pip-build-UG86a1/tensorflow/tensorflow-0.6.0.data/purelib/tensorflow/models/image/cifar10/cifar10_train.pyt   main   s
    
t   __main__(   t   __doc__t
   __future__R    R   R   R   t   os.pathR+   R"   t   tensorflow.python.platformt
   tensorflowR   t   numpyR#   t	   six.movesR   R   t   tensorflow.models.image.cifar10R   t   appt   flagsR   t   DEFINE_stringt   DEFINE_integert   DEFINE_booleanR   R   t   NoneRG   t   __name__R   (    (    (    so   /tmp/pip-build-UG86a1/tensorflow/tensorflow-0.6.0.data/purelib/tensorflow/models/image/cifar10/cifar10_train.pyt   <module>"   s.   	B