Creating a DBN with the Keras Model API
Learn how to implement deep belief networks (DBN) using TensorFlow 2.0.
We'll cover the following...
The creation of a single-layer RBM to generate images is the building block required to create a full-fledged DBN. Usually, for a model in TensorFlow 2, we only need to extend tf.keras.Model and define an initialization (where the layers are defined) and a call function (for the forward pass). For our DBN model, we also need a few more custom functions to define its behavior.
Implementing the RBM
Let’s continue by combining multiple RBMs in layers to create a more powerful model—the deep belief network (DBN).
RBM initialization
First, in the initialization, we need to pass a list of dictionaries that contain the parameters for our RBM layers (number_hidden_units, number_visible_units, and learning_rate, cd_steps):
At the same time, we also initialize a set of sigmoidal dense layers with a softmax at the end, which we can use for fine-tuning through backpropagation once we’ve trained the model using the generative procedures outlined earlier.
To train the DBN, we begin a new code block to start the generative learning process for the stack of RBMs:
It initializes an empty list inputs_layers ...