Tensor to numpy array
In Tensorflow, kernel (tf.Variable
) can be easily accessed by slim.get_model_variables()
(return a list of tf.Variable
)if using slim package. Also, if we want to access corresponding
- name: simply by
.name
- value:
sess.run
1 | weights = slim.get_model_variables() |
Numpy array to file
BAD TRY: numpy.savetxt
Extracted numpy array is usually multi-dimentional, therefore numpy.savetxt
is not applicable, because it requires a 1-d or 2-d array.
BAD TRY: numpy.save
pretty easy to use, but only applicable when we only need to load the file using Python, but we need to implement a C code in our project
SUCCESSFUL: scipy.io.loadmat
numpy
to .mat
file, need a dic
to generate the file, therefore we need the name of tf.variable
above.
1 | import numpy as np |