Hands-On Convolutional Neural Networks with TensorFlow
by Iffat Zafar, Giounona Tzanidou, Richard Burton, Nimesh Patel, Leonardo Araujo
Singleton Pattern
It is also common practice to use design patterns in order to solve some software design problems. One of the simplest and most useful design patterns in python is the singleton one. It is used when you want to force the instantiation of a class to only one object, so even if you instantiate this class multiple times in several different places in your project, you will be referencing the same object. In our case if we ask TensorFlow to create multiple nodes or graphs with the same name, it will throw an error. Therefore, we use the singleton pattern while creating the graph to avoid building it twice.
In the following example we summarize a simple classification model while also ensuring that the graph will not be built ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access