@@ -587,5 +587,68 @@ and return the best parameters found, for evaluation on the test set.
587587
588588
589589
590+ Theano/Python Tips
591+ ===================
592+
593+ Loading and Saving Models
594+ -------------------------
595+
596+ When you're doing experiments, it can take hours (sometimes days!) for
597+ gradient-descent to find the best parameters. You will want to save those
598+ weights once you find them. You may also want to save your current-best
599+ estimates as the search progresses.
600+
601+ **Pickle the numpy ndarrays from your shared variables**
602+
603+ The best way to save/archive your model's parameters is to use pickle or
604+ deepcopy the ndarray objects. So for example, if your parameters are in
605+ shared variables ``w, v, u``, then your save command should look something
606+ like:
607+ >>> import cPickle
608+ >>> save_file = open('path', 'w') # this will overwrite current contents
609+ >>> cPickle.dump(w.value, save_file, -1) # the -1 is for HIGHEST_PROTOCOL
610+ >>> cPickle.dump(v.value, save_file, -1) # .. and it triggers much more efficient
611+ >>> cPickle.dump(u.value, save_file, -1) # .. storage than numpy's default
612+ >>> save_file.close()
613+
614+ Then later, you can load your data back like this:
615+
616+ >>> save_file = open('path')
617+ >>> w.value = cPickle.load(save_file)
618+ >>> v.value = cPickle.load(save_file)
619+ >>> u.value = cPickle.load(save_file)
620+
621+ This technique is a bit verbose, but it is tried and true. You will be able
622+ to load your data and render it in matplotlib without trouble, years after
623+ saving it.
624+
625+ **Do not pickle your training or test functions for long-term storage**
626+
627+ Theano functions are compatible with Python's deepcopy and pickle mechanisms,
628+ but you should not necessarily pickle a Theano function. If you update your
629+ Theano folder and one of the internal changes, then you may not be able to
630+ un-pickle your model. Theano is still in active development, and the internal
631+ APIs are subject to change. So to be on the safe side -- do not pickle your
632+ entire training or testing functions for long-term storage. The pickle
633+ mechanism is aimed at for short-term storage, such as a temp file, or a copy to
634+ another machine in a distributed job.
635+
636+
637+
638+ Plotting Intermediate Results
639+ -----------------------------
640+
641+ Visualizations can be very powerful tools for understanding what your model or
642+ training algorithm is doing. You might be tempted to insert ``matplotlib``
643+ plotting commands, or ``PIL`` image-rendering commands into your model-training
644+ script. However, later you will observe something interesting in one of those
645+ pre-rendered images and want to investigate something that isn't clear from
646+ the pictures. You'll wished you had saved the original model.
647+
648+ **If you have enough disk space, your training script should save intermediate models and a visualization
649+ script should process those saved models.**
650+
651+ You already have a model-saving function right? Just use it again to save
652+ these intermediate models.
590653
591654
0 commit comments