I would like to know how to retrieve the dimension of a SharedVariable from theano.
This here e.g. does not work:
from theano import *
from numpy import *
import numpy as np
w = shared( np.asarray(zeros((1000,1000)), np.float32) )
print np.asarray(w).shape
print np.asmatrix(w).shape
and only returns
()
(1, 1)
I am also interested in printing/retriving the values of a matrix or vector ..
You can get the value of a shared variable like this:
w.get_value()
Then this would work:
w.get_value().shape
But this will copy the shared variable content. To remove the copy you can use the borrow parameter like this:
w.get_value(borrow=True).shape
But if the shared variable is on the GPU, this will still copy the data from the GPU to the CPU. To don't do this:
w.get_value(borrow=True, return_internal_type=True).shape
Their is a simpler way to do this, compile a Theano function that return the shape:
w.shape.eval()
w.shape
return a symbolic variable. .eval() will compile a Theano function and return the value of shape.
If you want to know more about how Theano handle the memory, check this web page: http://www.deeplearning.net/software/theano/tutorial/aliasing.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With