On Sun, Sep 15, 2013, Ya Li wrote:
> Hi Fred,
> theano.printing.debugprint(train_set_y) gives out like this:
>
> Elemwise{Cast{int32}} [@117570320] ''
> |HostFromGpu [@118639312] ''
> | |<CudaNdarrayType(float32, vector)> [@118638544]
>
> Could you figure out what is wrong? I think I did not change the
> train_set_y.
So, as Fred said, only shared variables actually contain a value, and
have a get_value() method. That's the case for train_set_x, but not
for train_set_y, which is a symbolic expression transforming a shared
variable stored as a float32 vector on the GPU (the one printed as
"<CudaNdarrayType(float32, vector)> [@118638544]" into an int32 vector.
If you want to compute a value from that symbolic expression, starting
from the current value of the shared variable, you can do the following:
train_set_y.eval()
However, this is not an efficient way of getting that value, and you
should only do that for debugging purposes, not during training or
testing.
During training or testing, you should build a symbolic expression, then
call theano.function(...), as explained in the tutorials.
Hope this helps,
> >>> *********************
> >>> start sample code file "debugging-shared.py"
> >>> ****************************************************************
> >>> *********************
> >>> #!/usr/bin/env python
> >>>
> >>> import theano
> >>> import theano.tensor as T
> >>> import numpy as np
> >>>
> >>> intArray = np.array([1,2,3], dtype='int64')
> >>> fltArray = np.array([1,2,3], dtype='float64')
> >>>
> >>> print "***as expected***"
> >>> print intArray
> >>> print fltArray
> >>>
> >>> sharedInt = theano.shared(intArray)
> >>> sharedFlt = theano.shared(fltArray)
> >>>
> >>> print "***as expected***"
> >>> print sharedInt, sharedInt.get_value()
> >>> print sharedFlt, sharedFlt.get_value()
> >>>
> >>> fltArray2 = np.array([1,2,3], dtype='float64')
> >>> castedFlt = T.cast(theano.shared(**fltArray2), 'int32')
> >>>
> >>> print "!!!trouble ahead!!!"
> >>> print castedFlt, castedFlt.get_constant_value()
> >>>
> >>> ****************************************************************
> >>> *********************
> >>> start output:
> >>> ****************************************************************
> >>> *********************
> >>> % python debugging-shared.py
> >>> Using gpu device 0: GeForce 8300
> >>> ***as expected***
> >>> [1 2 3]
> >>> [ 1. 2. 3.]
> >>> ***as expected***
> >>> <TensorType(int64, vector)> [1 2 3]
> >>> <TensorType(float64, vector)> [ 1. 2. 3.]
> >>> !!!trouble ahead!!!
> >>> Elemwise{Cast{int32}}.0
> >>> Traceback (most recent call last):
> >>> File "debugging-shared.py", line 25, in <module>
> >>> print castedFlt, castedFlt.get_constant_value()
> >>> File "/home/mfenner/created/bytype/**code/python/theano/Theano/**theano/tensor/basic.py",
> >>> line 1654, in get_constant_value
> >>> return get_constant_value(self)
> >>> File "/home/mfenner/created/bytype/**code/python/theano/Theano/**theano/tensor/basic.py",
> >>> line 501, in get_constant_value
> >>> const = get_constant_value(v.owner.**inputs[0])
> >>> File "/home/mfenner/created/bytype/**code/python/theano/Theano/**theano/tensor/basic.py",
> >>> line 556, in get_constant_value
> >>> raise TypeError(v)
> >>> TypeError: <TensorType(float64, vector)>
> >>>
> >>> --
> >>
> >> ---
> >> You received this message because you are subscribed to the Google Groups
> >> "theano-users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to
theano-users...@googlegroups.com <javascript:>.
--
Pascal