Skip to content

Instantly share code, notes, and snippets.

@tejaskhot
Created June 13, 2015 06:40
Show Gist options
  • Save tejaskhot/e521c9a81213c55dfa89 to your computer and use it in GitHub Desktop.
Save tejaskhot/e521c9a81213c55dfa89 to your computer and use it in GitHub Desktop.
Getting shape and size information for a Theano SharedVariable

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment