σ šΔοYc@@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(s.build/bdist.linux-armv7l/egg/mxnet/callback.pyt _callback0sN(tinttmaxtNone(RRRR R ((RRRR s.build/bdist.linux-armv7l/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(s.build/bdist.linux-armv7l/egg/mxnet/callback.pyR Vs(R R (RRR ((RRs.build/bdist.linux-armv7l/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(s.build/bdist.linux-armv7l/egg/mxnet/callback.pyR ls" ((RRR ((RRs.build/bdist.linux-armv7l/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((s.build/bdist.linux-armv7l/egg/mxnet/callback.pyt__init__Žs      cC@s-|j}|j|kr$t|_n||_|jr||jdkr)|j|jtjƒ|j}|jdk rγ|jj ƒ}|j r‘|jj ƒnd}|dt |ƒ7}tj||j||t|dƒŒntjd|j||ƒtjƒ|_q)nt|_tjƒ|_dS(sCallback to Show speed.is,Epoch[%d] Batch [%d] Speed: %.2f samples/secs %s=%fs+Iter[%d] Batch [%d] Speed: %.2f samples/secN((RR#R R!RRttimeR"RR RRRtlenRRRtsumtTrue(R$RtcounttspeedRtmsg((s.build/bdist.linux-armv7l/egg/mxnet/callback.pyt__call__–s&    ! (  (t__name__t __module__t__doc__R)R%R-(((s.build/bdist.linux-armv7l/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$R3tlength((s.build/bdist.linux-armv7l/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 troundR2tfloatR3tmathtceilRR(R$RR*t filled_lentpercentstprog_bar((s.build/bdist.linux-armv7l/egg/mxnet/callback.pyR-Εs  & (R.R/R0R%R-(((s.build/bdist.linux-armv7l/egg/mxnet/callback.pyR1°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((s.build/bdist.linux-armv7l/egg/mxnet/callback.pyR-Ρs  (R.R/R0R-(((s.build/bdist.linux-armv7l/egg/mxnet/callback.pyR?Ξs(R0t __future__RRR:R&tmodelRR RRRtobjectRR1R?(((s.build/bdist.linux-armv7l/egg/mxnet/callback.pyts    & 8