Hi Pascal, I have a error: TypeError: Cannot convert Type TensorType(uint8, 
matrix) (of Variable Subtensor{int64:int64:}.0) into Type 
TensorType(float64, matrix). You can try to manually convert 
Subtensor{int64:int64:}.0 into a TensorType(float64, matrix).
 
when I created te shared variables: 

train_set_x = theano.shared(numpy.array(train_set_x))
test_set_x = theano.shared(numpy.array(test_set_x))
train_set_y = theano.shared(numpy.array(y_train))
test_set_y = theano.shared(numpy.array(y_test))
valid_set_x = theano.shared(numpy.array(valid_set_x))
valid_set_y = theano.shared(numpy.array(y_val))


If I do not force to be float64 and int32 it does not work:


train_set_x = theano.shared(numpy.array(train_set_x,dtype=float64))
test_set_x = theano.shared(numpy.array(test_set_x, dtype=float64))
train_set_y = theano.shared(numpy.array(y_train, dtype=int32))
test_set_y = theano.shared(numpy.array(y_test, dtype=int32))
valid_set_x = theano.shared(numpy.array(valid_set_x, dtype=float64))
valid_set_y = theano.shared(numpy.array(y_val,  dtype=int32))



But If I do that, it does not work in gpu. And I want to use gpu. Could you 
help me, please??



El martes, 9 de junio de 2015, 23:47:21 (UTC+2), Pascal Lamblin escribió:
>
> Hi, 
>
> You seem to be using explicitly double-precision variables, which will 
> not be computed on the GPU using the default back-end. 
> You should explicitly use dtype='float32', T.fmatrix(), T.fvector(), etc., 
> or use dtype=theano.config.floatX, T.matrix, T.vector(), and explicitly 
> set "floatX=float32" in the Theano flags. 
>
> On Tue, Jun 09, 2015, Qixianbiao Qixianbiao wrote: 
> > Hello, 
> > 
> >          I am new to theano although I have used some other DL toolbox. 
> >  Recently, I write one Lenet5 CNN code based on theano.  After long time 
> > struggle, I finally can run it, but I find the decreasing speed of the 
> cost 
> > value is very slow. Meanwhile, the running speed on both GPU and CPU is 
> > similar although it shows that "Using GPU device 0: Tesla K20".   Any 
> > comments for the code style and denotation will be greatly appreciated. 
> > 
> > 
> > 
> > import theano 
> > import theano.tensor as T 
> > from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams 
> > from theano.tensor.signal import downsample 
> > from theano.tensor.nnet import conv 
> > import numpy as np 
> > import cPickle 
> > 
> > rng = RandomStreams(1234) 
> > 
> > 
> > 
> > def loadData(path='mnist.pkl.gz'): 
> >     train_set, valid_set, test_set = cPickle.load(file('mnist.pkl', 
> 'r')) 
> >     trX, trY = train_set 
> >     valX, valY = valid_set 
> >     teX, teY = test_set 
> >     return trX, trY, valX, valY, teX, teY 
> > 
> > def dropout(X, p1): 
> >     if p1>0.0: 
> >         keep = 1 - p1 
> >         X *= rng.binomial(X.shape, p=keep, dtype='float32') 
> >         X = X/(1-p1) 
> >     return X 
> > 
> > def rectify(X): 
> >     return T.maximum(X, 0) 
> > 
> > def softmax(X, w, b): 
> >     return T.nnet.softmax( T.dot(X, w) + b ) 
> > 
> > def pooling(X, poolsize=(2, 2)): 
> >     return downsample.max_pool_2d(X, poolsize) 
> > 
> > def hiddenlayer(X, w, b): 
> >     return T.dot(X, w) + b 
> > 
> > def convlayer(X, w, b): 
> >     print X.dtype 
> >     print w.dtype 
> >     result = conv.conv2d(X, w) + b.dimshuffle('x', 0, 'x', 'x') 
> >     return result 
> > 
> > def model(input, w1, b1, w2, b2, wh, bh, wo, bo): 
> >     layer1 = convlayer(input, w1, b1) 
> >     r1 = rectify(layer1) 
> >     p1 = pooling(r1) 
> >     d1 = dropout(p1, 0.2) 
> > 
> >     layer2 = convlayer(d1, w2, b2) 
> >     r2 = rectify(layer2) 
> >     p2 = pooling(r2) 
> >     d2 = dropout(p2, 0.4) 
> > 
> >     d2flat = T.flatten(d2, outdim=2) 
> >     hidden1 = hiddenlayer(d2flat, wh, bh) 
> >     r2 = rectify(hidden1) 
> > 
> >     out = softmax(r2, wo, bo) 
> > 
> >     return out 
> > 
> > def costfunction(out, y): 
> >     return T.mean( T.nnet.categorical_crossentropy(out, y) ) 
> > 
> > 
> > X = T.dtensor4() 
> > Y = T.dmatrix() 
> > 
> > 
> > w1np = np.zeros((6, 1, 5, 5), dtype='float64') 
> > w1 = theano.shared(w1np, borrow=True) 
> > b1np = np.zeros((6, ), dtype='float64') 
> > b1 = theano.shared(b1np, borrow=True) 
> > 
> > 
> > w2np = np.zeros((12, 6, 3, 3), dtype='float64') 
> > w2 = theano.shared(w2np, borrow=True) 
> > b2np = np.zeros((12, ), dtype='float64') 
> > b2 = theano.shared(b2np, borrow=True) 
> > 
> > 
> > whnp = np.zeros((300, 64), dtype='float64') 
> > wh = theano.shared(whnp, borrow=True) 
> > bhnp = np.zeros((64, ), dtype='float64') 
> > bh = theano.shared(bhnp, borrow=True) 
> > 
> > wonp = np.zeros((64, 10), dtype='float64') 
> > wo = theano.shared(wonp, borrow=True) 
> > bonp = np.zeros((10, ), dtype='float64') 
> > bo = theano.shared(bonp, borrow=True) 
> > 
> > 
> > """ 
> > w1 = theano.shared(np.asarray(np.random.uniform(-1.0/25, 1.0/25, (6, 1, 
> 5, 5)), dtype=theano.config.floatX)) 
> > b1 = theano.shared(np.asarray(np.random.uniform(-1.0/25, 1.0/25, (6, )), 
> dtype=theano.config.floatX)) 
> > 
> > w2 = theano.shared(np.asarray(np.random.uniform(-1.0/9, 1.0/9, (12, 6, 
> 3, 3)), dtype=theano.config.floatX)) 
> > b2 = theano.shared(np.asarray(np.random.uniform(-1.0/9, 1.0/9, (12, )), 
> dtype=theano.config.floatX)) 
> > 
> > wh = theano.shared(np.asarray(np.random.uniform(-6.0/300, 6.0/300, 
> (12*5*5, 64)), dtype=theano.config.floatX)) 
> > bh = theano.shared(np.asarray(np.random.uniform(-6.0/300, 6.0/300, (64, 
> )), dtype=theano.config.floatX)) 
> > 
> > wo = theano.shared(np.asarray(np.random.uniform(-6.0/64, 6.0/64, (64, 
> 10)), dtype=theano.config.floatX)) 
> > bo = theano.shared(np.asarray(np.random.uniform(-6.0/64, 6.0/64, (10, 
> )), dtype=theano.config.floatX)) 
> > """ 
> > 
> > outlayer = model(X, w1, b1, w2, b2, wh, bh, wo, bo) 
> > cost = costfunction(outlayer, Y) 
> > predictLabel = T.argmax(outlayer, axis = 1) 
> > 
> > params = [w1, b1, w2, b2, wh, bh, wo, bo] 
> > updates = [] 
> > gradP = T.grad(cost, params) 
> > for i in range( len(params) ): 
> >     updates.append((params[i], params[i]-0.1*gradP[i])) 
> > 
> > train = theano.function([X, Y], cost, updates=updates) 
> > predict = theano.function([X], predictLabel) 
> > 
> > 
> > trX, trY, valX, valY, teX, teY = loadData() 
> > trX = trX.reshape(-1, 1, 28, 28) 
> > teX = teX.reshape(-1, 1, 28, 28) 
> > trX = (np.asarray(trX, 'float64')) 
> > newTrY = np.zeros((trY.shape[0], 10)) 
> > for i in range(trY.shape[0]): 
> >     newTrY[i, trY[i]] = 1 
> > 
> > newTrY = (np.asarray(newTrY, 'float64')) 
> > datanum = trX.shape[0] 
> > 
> > #trX = theano.shared(trX) 
> > #newTrY = theano.shared(newTrY) 
> > 
> > print trX.shape 
> > 
> > epoch = 100 
> > batchsize = 128 
> > 
> > for i in range(epoch): 
> >     for i, j in zip(range(0, datanum, 128), range(128, datanum, 128)): 
> >         cost = train(trX[i:j], newTrY[i:j]) 
> >     print cost 
> > 
> >   
> > 
> > -- 
> > 
> > --- 
> > 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 [email protected] <javascript:>. 
> > 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to