Running tensorflow on Docker

Why?

  • Keep my code working on my local device. (Easier to come back to later).
  • Potential to run the docker image on a cloud server (later)
  • Structure code between multiple files
  • Refactoring code can help you learn it
  • Can use git for source control
  • BUT : Jupiter notebooks is a lot faster to start with

Install Docker

Tensorflow Image

Open terminal
  • Run Image:
    docker run -it tensorflow/tensorflow
  • Run bash shell :
    docker run -it tensorflow/tensorflow bash
  • Bash w. mapped directory:
    docker run -v '//local/dir://mapped/dir' -it tensorflow/tensorflow bash

Install python-tk

Lots of the examples in the crash course depend on python-tk which is not on the docker image

apt-get update &&\
apt-get install tk-dev python-tk &&\
rm -r /var/lib/apt/lists/*

Plotting to PDF

Matplotlib has facility to print to PDF


import matplotlib
matplotlib.use('Agg') # dont use windows
from matplotlib.backends.backend_pdf import PdfPages
def multi_page(filename, figs=None, dpi=200):
	pp = PdfPages(filename)
	if figs is None:
		figs = [plt.figure(n) for n in plt.get_fignums()]
	for fig in figs:
		fig.savefig(pp, format='pdf', bbox_inches='tight', fig_size=(10, 8))
	pp.close()
					
then to use it

from plotting_pdf import multi_page
...
multi_page("/tf/report.pdf") # save to mapped folder
				

Thanks