This post is based on the example provided by tensorflow.