If you enabled the GPU back-end, then shared variables will live on the GPU, and the gradients will have the same type.
You have two options at this time: - either call `.transfer('cpu')` on the symbolic gradients before using them as outputs - call numpy.asarray() on the GpuArrays returned by the Theano function On Mon, Mar 27, 2017, duy kien nguyen wrote: > > Hi all, > > I tried to get the gradients from Theano in numpy type. But, when I defined > the function, it returned pygpu.gpuarray.GpuArray. How can I solve this > problem? > > Here is my function: > ---------------------------------------------------------------------------------------------------------------------------- > cost = classifier.negative_log_likelihood(answer, answer_mask) > grads = T.grad(cost, list(classifier.tparams.values())) > > optim = optimizer() > # updates = optim(itemlist(classifier.tparams), grads) > > train_model = theano.function( > inputs=[], > outputs=[cost] + grads, > # updates=updates, > givens={ > img: shared_img, ques: shared_ques_casted, ans: shared_ans_casted[:-1], > m_ques: shared_m_ques, m_ans: shared_m_ans[:-1], > answer: shared_ans_casted[1:], answer_mask: shared_m_ans[1:] > } > ) > > test_model = theano.function( > inputs=[], > outputs=classifier.samples(length_answer-1), > givens={ > img: shared_img, ques: shared_ques_casted, > m_ques: shared_m_ques > } > ) > ------------------------------------------------------------------------------------------------------------------------------ > > Here is the type of the returned gradients (the first one is in numpy type > but the other are not): > > <type 'numpy.ndarray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > <type 'pygpu.gpuarray.GpuArray'> > > Thank you in advance > > -- > > --- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Pascal -- --- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.