Discussion:
[theano-users] Getting an error while being new to theano
Loïc
2018-02-21 16:26:04 UTC
Permalink
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 <module>
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 <lambda>
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] <TensorType(float64, vector)> 'max'
MaxAndArgmax.1 [@A] <TensorType(int64, vector)> '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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Pascal Lamblin
2018-02-21 18:23:13 UTC
Permalink
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?
Post by 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
|
File"train_bnn.py",line 525,in<module>
     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<lambda>
     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,))]
|
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).
|
''' Logistic regression layer
     '''
# initialization
# 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]
# the loss function
return-T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]),y])
# check if y has same dimension of y_pred
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
# compute error
returnT.mean(T.neq(self.y_pred,y))
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
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 an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loïc
2018-02-26 13:58:05 UTC
Permalink
Hello,

Sorry for the delay but I got sick and stuck at home for a few days.

Indeed I am using v0.6.0 of Theano merely because it is the version that
the author used. Plus they added that if someone wanted to update Theano he
will have to find a new way to downsample.

In fact, I have tested with Theano 1.0.1 and I do get an error earlier in
the program as it seem that in version 1.0.1 the downsample method from
theano.tensor.signal module does not exist anymore. Are you aware of a
workaround ? Maybe a new way to downsample has replaced this obsolete one ?

Anyway thank you for your previous answer, I will let you know if I can get
theano version 1.0.1 to downsample as the 0.6.0 used to and if it also
resolves the initial issue.
--
---
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.
For more options, visit https://groups.google.com/d/optout.
Pascal Lamblin
2018-02-26 17:24:16 UTC
Permalink
Post by Loïc
Hello,
Sorry for the delay but I got sick and stuck at home for a few days.
Indeed I am using v0.6.0 of Theano merely because it is the version that
the author used. Plus they added that if someone wanted to update Theano
he will have to find a new way to downsample.
In that case, you will probably need to use an old version of numpy as
well, since the error seems to be raised from numpy.
Post by Loïc
In fact, I have tested with Theano 1.0.1 and I do get an error earlier
in the program as it seem that in version 1.0.1 the downsample method
from theano.tensor.signal module does not exist anymore. Are you aware
of a workaround ? Maybe a new way to downsample has replaced this
obsolete one ?
Yes, the module has been renamed to "pool":
http://deeplearning.net/software/theano/library/tensor/signal/pool.html
Post by Loïc
Anyway thank you for your previous answer, I will let you know if I can
get theano version 1.0.1 to downsample as the 0.6.0 used to and if it
also resolves the initial issue.
--
---
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
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 an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loïc
2018-02-27 15:02:19 UTC
Permalink
Thank you for the link.

I have now a 1.0.1 theano version of the code and it works. I had a few
things that needed to be changed using 1.0.1 instead of 0.6.0 but now it
works and my issue is resolved.

Thank you for your help.
--
---
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.
For more options, visit https://groups.google.com/d/optout.
Loading...