I've built a simple 4 layer Neural Network (2 hidden layers) in TensorFlow. I am not using the built in NN provided by TensorFlow but implementing a basic version of my own. Now, to keep W (weights) and B(biases) Tensor's at one place I built a dictionary of these variables like this:
weights = {
'h1': tf.Variable(tf.random_normal([n_input, n_hidden_1])),
'h2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2])),
'out': tf.Variable(tf.random_normal([n_hidden_2, n_classes]))
}
biases = {
'b1': tf.Variable(tf.random_normal([n_hidden_1])),
'b2': tf.Variable(tf.random_normal([n_hidden_2])),
'out': tf.Variable(tf.random_normal([n_classes]))
}
After I learn these parameters, I want to save them using the Saver object. I tried this:
saver = tf.train.Saver([weights,biases])
save_path = saver.save(sess,"./data/model.ckpt")
But I'm unsuccessful in doing so. The error seen is:
TypeError: unhashable type: 'dict'
Now, one solution is to separate all the variables : h1,h2,out,b1,b2,bias_out (out of biases dictionary) into individual variables and save them but this seems a naive approach. If I later have more variables that need to be clubbed together I'd like to keep it that way, it's more clean and manageable. How can I save the grouped variables together ?