Fatima_Ali
Fatima_Ali

Reputation: 194

How can I save the weight and biases of trained Neural Network

I built neural network using tensorflow.

After training it and get the minimum cost, I need to save the weights and biases as matrices in order to be use in e.g., Matlab. How I can do that?

When I perform the following code after finishing the training to save the weights:

from scipy.io import savemat
savemat("end_Weight1.mat", weights )

I can save it, but I get empty matrix, it means the matrix includes only the four variables but without any values. I don't get any values in the matrices.

I think the weights need to be updated before saving them or something like that ?

Upvotes: 1

Views: 794

Answers (1)

Armin Azhdehnia
Armin Azhdehnia

Reputation: 145

you can use

all_variables=tf.global_variables()

on each batches to get your variables from created graph and then saved them.

Note: this method return all variablen, for this reason you can filter the list.Ex get filter it by biases or weights as you want.

Upvotes: 2

Related Questions