Re: [theano-users] Getting an error while being new to theano

2018-02-21 Thread Pascal Lamblin

You seem to be using Theano 0.6.0.
Only version 1.0.1 is still supported.

Does the error still occur with 1.0.1?

On 2018-02-21 11:26 AM, Loïc wrote:

Hi,

I have downloaded an open source code which uses theano 
(https://www.repository.cam.ac.uk/handle/1810/263961)


When I try running the learning step I get an error (I have set theano 
verbosity to high).



python train_bnn.py -i lytroPatches_30x30.pkl.gz

|

Traceback(most recent call last):
File"train_bnn.py",line 525,in
      evaluate_dcnn(dataset=dataset_file,nkerns=kernels)
File"train_bnn.py",line 440,inevaluate_dcnn
print("res = {}".format(validate_model(0)))
File"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/function_module.py",line 
579,in__call__

      outputs =self.fn()
File"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/debugmode.py",line 
2030,indeco

returnf()
File"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/debugmode.py",line 
1790,inf

      thunk_py()
File"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/debugmode.py",line 
1623,in

      n=node:p(n,[x[0]forx ini],o))
File"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/tensor/basic.py",line 
1418,inperform

      max[0]=theano._asarray(numpy.max(x,axis),
File"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/numpy/core/fromnumeric.py",line 
2320,inamax

out=out,**kwargs)
File"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/numpy/core/_methods.py",line 
26,in_amax

returnumr_maximum(a,axis,None,out,keepdims)

TypeError:only integer scalar arrays can be converted to a scalar index
Applynode that caused the 
error:MaxAndArgmax(Softmax.0,TensorConstant{(1,)of 1})

Inputsshapes:[(100,2),(1,)]
Inputsstrides:[(16,8),(8,)]
Inputstypes:[TensorType(float64,matrix),TensorType(int64,(True,))]
Debugprintof the apply node:
MaxAndArgmax.0[@A]'max'
MaxAndArgmax.1[@A]'argmax'
|



Now I am really new to Theano and do not even have dnn experience which 
makes it hard to understand the messages I get from Theano and to debug 
this code...
As far as I know this could even be not related to Theano (though I hope 
I am not wasting your time).


What I think I have understood is that the train_model theano.function 
goes well. But the validate_model and test_model theano.function do not.
I think this is due to the errors() method of the LogisticRegression 
layer (the negative_log_likelihood is used what I guess is called the 
cost function for the train_model, while the errors one is the function 
that is supposed to test how well the dnn has learnt so far).



|
classLogisticRegression(object):
''' Logistic regression layer
      '''

# initialization
def__init__(self,input,n_in,n_out):

# initialize the weight matrix to zeros
self.W =theano.shared(value=np.zeros((n_in,n_out),
                                                dtype=theano.config.floatX),
                                 name='W',borrow=True)

# initialize the bias term
self.b =theano.shared(value=np.zeros((n_out,),
                                                dtype=theano.config.floatX),
                                 name='b',borrow=True)

# define symbolic expressions for probability and prediction
self.p_y_given_x =T.nnet.softmax(T.dot(input,self.W)+self.b)

self.y_pred =T.argmax(self.p_y_given_x,axis=1)

self.params=[self.W,self.b]

defnegative_log_likelihood(self,y):
# the loss function
return-T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]),y])

deferrors(self,y):

# check if y has same dimension of y_pred
ify.ndim !=self.y_pred.ndim:
raiseTypeError(
'y should have the same shape as self.y_pred',
('y',y.type,'y_pred',self.y_pred.type)
)
# check if y is of the current data type
ify.dtype.startswith('int'):
# compute error
returnT.mean(T.neq(self.y_pred,y))
else:
print("NotImplementedError for LogisticRegression::errors()")
raiseNotImplementedError()
|



So here I come to you hopping that maybe you will have hints or clues to 
help me find out where this error comes from.


Could it be related to the shapes of the tensors ? How can I access them 
? I have truble playing with tensors so far...


I really thank you for the time you will spend reading this and 
answering it.



--

---
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 Lamblin

--

--- 
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 

[theano-users] Getting an error while being new to theano

2018-02-21 Thread Loïc
Hi,

I have downloaded an open source code which uses theano 
(https://www.repository.cam.ac.uk/handle/1810/263961)

When I try running the learning step I get an error (I have set theano 
verbosity to high). 


python train_bnn.py -i lytroPatches_30x30.pkl.gz


Traceback (most recent call last):
   File "train_bnn.py", line 525, in 
 evaluate_dcnn(dataset=dataset_file, nkerns=kernels)
   File "train_bnn.py", line 440, in evaluate_dcnn
 print("res = {}".format(validate_model(0)))
   File 
"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/function_module.py"
, line 579, in __call__
 outputs = self.fn()
   File 
"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/debugmode.py"
, line 2030, in deco
 return f()
   File 
"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/debugmode.py"
, line 1790, in f
 thunk_py()
   File 
"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/compile/debugmode.py"
, line 1623, in 
 n=node: p(n, [x[0] for x in i], o))
   File 
"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/Theano-0.6.0-py2.7.egg/theano/tensor/basic.py"
, line 1418, in perform
 max[0] = theano._asarray(numpy.max(x, axis),
   File 
"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/numpy/core/fromnumeric.py"
, line 2320, in amax
 out=out, **kwargs)
   File 
"/home/PRODUITS/COTS/python2.7.9/lib/python2.7/site-packages/numpy/core/_methods.py"
, line 26, in _amax
 return umr_maximum(a, axis, None, out, keepdims)
 
TypeError: only integer scalar arrays can be converted to a scalar index
 Apply node that caused the error: MaxAndArgmax(Softmax.0, TensorConstant{(1
,) of 1})
 Inputs shapes: [(100, 2), (1,)]
 Inputs strides: [(16, 8), (8,)]
 Inputs types: [TensorType(float64, matrix), TensorType(int64, (True,))]
 Debugprint of the apply node:
 MaxAndArgmax.0 [@A]  'max'
 MaxAndArgmax.1 [@A]  'argmax'



Now I am really new to Theano and do not even have dnn experience which 
makes it hard to understand the messages I get from Theano and to debug 
this code...
As far as I know this could even be not related to Theano (though I hope I 
am not wasting your time).

What I think I have understood is that the train_model theano.function goes 
well. But the validate_model and test_model theano.function do not. 
I think this is due to the errors() method of the LogisticRegression layer 
(the negative_log_likelihood is used what I guess is called the cost 
function for the train_model, while the errors one is the function that is 
supposed to test how well the dnn has learnt so far).


class LogisticRegression(object):
 ''' Logistic regression layer
 '''
 
 # initialization
 def __init__(self, input, n_in, n_out):
 
 # initialize the weight matrix to zeros
 self.W = theano.shared(value=np.zeros((n_in, n_out),
   dtype=theano.config.floatX),
name='W', borrow=True)
 
 # initialize the bias term
 self.b = theano.shared(value=np.zeros((n_out,),
   dtype=theano.config.floatX),
name='b', borrow=True)
 
 # define symbolic expressions for probability and prediction
 self.p_y_given_x = T.nnet.softmax(T.dot(input, self.W) + self.b)
 
 self.y_pred = T.argmax(self.p_y_given_x, axis=1)
 
 self.params = [self.W, self.b]
 
 def negative_log_likelihood(self, y):
 # the loss function
 return -T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]), y])
 
 def errors(self, y):
 
 # check if y has same dimension of y_pred
 if y.ndim != self.y_pred.ndim:
 raise TypeError(
 'y should have the same shape as self.y_pred',
 ('y', y.type, 'y_pred', self.y_pred.type)
 )
 # check if y is of the current data type
 if y.dtype.startswith('int'):
 # compute error
 return T.mean(T.neq(self.y_pred, y))
 else:
 print("NotImplementedError for LogisticRegression::errors()")
 raise NotImplementedError()



So here I come to you hopping that maybe you will have hints or clues to 
help me find out where this error comes from.

Could it be related to the shapes of the tensors ? How can I access them ? 
I have truble playing with tensors so far...

I really thank you for the time you will spend reading this and answering 
it.


-- 

--- 
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