First, we initialize the class variables and weights:
self.num_input = num_input self.num_hidden = num_hidden self.transfer = transfer_function network_weights = self._initialize_weights() self.weights = network_weights
Here, the _initialize_weigths() function is a local function that initializes values for the weights dictionary:
- w1 is a 2D tensor with shape num_input X num_hidden
- b1 is a 1D tensor with shape num_hidden
- w2 is a 2D tensor with shape num_hidden X num_input
- b2 is a 2D tensor with shape num_input
The following code shows how weights are initialized as a dictionary of TensorFlow variables for two hidden layers:
def _initialize_weights(self): weights = dict() weights['w1'] = tf.get_variable("w1"