ó ůľČ[c@@sˇdZddlmZddlZddlZddlZddlmZded„Z dd„Z ed„Z d e fd „ƒYZ d e fd „ƒYZd e fd„ƒYZdS(sICallback functions that can be used to track various status during epoch.i(tabsolute_importNi(tsave_checkpointc@s:ttdˆƒƒ‰ddd‡‡‡‡fd†}|S(s!Callback to checkpoint Module to prefix every epoch. Parameters ---------- mod : subclass of BaseModule The module to checkpoint. prefix : str The file prefix for this checkpoint. period : int How many epochs to wait before checkpointing. Defaults to 1. save_optimizer_states : bool Indicates whether or not to save optimizer states for continued training. Returns ------- callback : function The callback function that can be passed as iter_end_callback to fit. ic@s2|dˆdkr.ˆjˆ|dˆƒndS(sThe checkpoint function.iiN(R(titer_notsymtargtaux(tmodtperiodtprefixtsave_optimizer_states(sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyt _callback0sN(tinttmaxtNone(RRRR R ((RRRR sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pytmodule_checkpoints!c@s+ttdˆƒƒ‰‡‡fd†}|S(sA callback that saves a model checkpoint every few epochs. Each checkpoint is made up of a couple of binary files: a model description file and a parameters (weights and biases) file. The model description file is named `prefix`--symbol.json and the parameters file is named `prefix`-`epoch_number`.params Parameters ---------- prefix : str Prefix for the checkpoint filenames. period : int, optional Interval (number of epochs) between checkpoints. Default `period` is 1. Returns ------- callback : function A callback function that can be passed as `epoch_end_callback` to fit. Example ------- >>> module.fit(iterator, num_epoch=n_epoch, ... epoch_end_callback = mx.callback.do_checkpoint("mymodel", 1)) Start training with [cpu(0)] Epoch[0] Resetting Data Iterator Epoch[0] Time cost=0.100 Saved checkpoint to "mymodel-0001.params" Epoch[1] Resetting Data Iterator Epoch[1] Time cost=0.060 Saved checkpoint to "mymodel-0002.params" ic@s5|dˆdkr1tˆ|d|||ƒndS(sThe checkpoint function.iiN(R(RRRR(RR(sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyR Vs(R R (RRR ((RRsN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyt do_checkpoint7sc@s‡‡fd†}|S(stCallback to log the training evaluation result every period. Parameters ---------- period : int The number of batch to log the training evaluation metric. auto_reset : bool Reset the metric after each log. Returns ------- callback : function The callback function that can be passed as iter_epoch_callback to fit. c@s„|jˆdkr€|jdk r€|jjƒ}x3|D]+\}}tjd|j|j||ƒq8Wˆr€|jjƒq€ndS(sThe checkpoint function.isIter[%d] Batch[%d] Train-%s=%fN(tnbatcht eval_metricR tget_name_valuetloggingtinfotepochtreset(tparamt name_valuetnametvalue(t auto_resetR(sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyR ls" ((RRR ((RRsN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pytlog_train_metric]s t SpeedometercB@s&eZdZded„Zd„ZRS(s>Logs training speed and evaluation metrics periodically. Parameters ---------- batch_size: int Batch size of data. frequent: int Specifies how frequently training speed and evaluation metrics must be logged. Default behavior is to log once every 50 batches. auto_reset : bool Reset the evaluation metrics after each log. Example ------- >>> # Print training speed and evaluation metrics every ten batches. Batch size is one. >>> module.fit(iterator, num_epoch=n_epoch, ... batch_end_callback=mx.callback.Speedometer(1, 10)) Epoch[0] Batch [10] Speed: 1910.41 samples/sec Train-accuracy=0.200000 Epoch[0] Batch [20] Speed: 1764.83 samples/sec Train-accuracy=0.400000 Epoch[0] Batch [30] Speed: 1740.59 samples/sec Train-accuracy=0.500000 i2cC@s:||_||_t|_d|_d|_||_dS(Ni(t batch_sizetfrequenttFalsetinitttict last_countR(tselfRRR((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyt__init__Žs      c C@sš|j}|j|kr$t|_n||_|jr~||jdkr–y%|j|jtjƒ|j}Wntk rt dƒ}nX|j dk rP|j j ƒ}|j r|j jƒd}|dt|ƒ7}tj||j||j||t|dƒŒqid}|dt|ƒ7}tj||j||t|d ƒŒntjd|j||ƒtjƒ|_q–nt|_tjƒ|_dS( sCallback to Show speed.itinfs/Epoch[%d] Batch [%d-%d] Speed: %.2f samples/secs %s=%fs.Epoch[%d] Batch [0-%d] Speed: %.2f samples/secs+Iter[%d] Batch [%d] Speed: %.2f samples/secN(((RR#R R!RRttimeR"tZeroDivisionErrortfloatRR RRRtlenRRRtsumtTrue(R$RtcounttspeedRtmsg((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyt__call__–s2    %   2(  (t__name__t __module__t__doc__R,R%R0(((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyRxst ProgressBarcB@s#eZdZdd„Zd„ZRS(sÚDisplays a progress bar, indicating the percentage of batches processed within each epoch. Parameters ---------- total: int total number of batches per epoch length: int number of chars to define maximum length of progress bar Examples -------- >>> progress_bar = mx.callback.ProgressBar(total=2) >>> mod.fit(data, num_epoch=5, batch_end_callback=progress_bar) [========--------] 50.0% [================] 100.0% iPcC@s||_||_dS(N(tbar_lenttotal(R$R6tlength((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyR%És cC@s‚|j}tt|j|t|jƒƒƒ}tjd|t|jƒƒ}d|d|j|}tj d||dƒdS(sCallback to Show progress bar.gY@t=t-s [%s] %s%s t%N( RR troundR5R)R6tmathtceilRR(R$RR-t filled_lentpercentstprog_bar((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyR0Ís  & (R1R2R3R%R0(((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyR4¸s tLogValidationMetricsCallbackcB@seZdZd„ZRS(s2Just logs the eval metrics at the end of an epoch.cC@sP|js dS|jjƒ}x-|D]%\}}tjd|j||ƒq#WdS(NsEpoch[%d] Validation-%s=%f(RRRRR(R$RRRR((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyR0Ůs  (R1R2R3R0(((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyRAÖs(R3t __future__RRR<R'tmodelRR RRRtobjectRR4RA(((sN/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/callback.pyts    & @