Discussion:
[theano-users] How can I index a list using a theano scalar?
Rob
2015-03-10 12:46:05 UTC
Permalink
I want a theano function that, given a scalar input, will return a tensor
stored in a list at the index of that scalar. i.e

theano.function([index],list[index],givens= {x: <some function of index>})

where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.

This generates error:

TypeError: list indices must be integers, not TensorVariable


I'm very new to Theano so I'm probably thinking about this problem in the
wrong way. I would really appreciate any advice.

Rob
--
---
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.
Rob
2015-03-10 13:03:50 UTC
Permalink
I have circumvented the problem. Rather than creating a list of tensor on
which I apply a single theano function, I just created a list of theano
functions (one for each tensor).

If there are better solutions I would still love to here them.
Post by Rob
I want a theano function that, given a scalar input, will return a tensor
stored in a list at the index of that scalar. i.e
theano.function([index],list[index],givens= {x: <some function of index>})
where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.
TypeError: list indices must be integers, not TensorVariable
I'm very new to Theano so I'm probably thinking about this problem in the
wrong way. I would really appreciate any advice.
Rob
--
---
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.
Frédéric Bastien
2015-03-10 13:10:36 UTC
Permalink
Do all element of the list have the same size? If so, I would recommand to
make an ndarray with 1 extra dimensions instead of putting this in a list.
Then you can put this ndarray as a shared variable

example:

nd_list = numpy.ndarray(list)
shared_var = theano.shared(nd_list)

then you can do:

shared_var[index]

And use that in a Theano function.

Otherwise, you can use typed list:

http://deeplearning.net/software/theano/library/typed_list.html

Fred
Post by Rob
I have circumvented the problem. Rather than creating a list of tensor on
which I apply a single theano function, I just created a list of theano
functions (one for each tensor).
If there are better solutions I would still love to here them.
Post by Rob
I want a theano function that, given a scalar input, will return a tensor
stored in a list at the index of that scalar. i.e
theano.function([index],list[index],givens= {x: <some function of index
})
where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.
TypeError: list indices must be integers, not TensorVariable
I'm very new to Theano so I'm probably thinking about this problem in the
wrong way. I would really appreciate any advice.
Rob
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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.
Florin
2016-07-28 15:42:55 UTC
Permalink
I have a similar problem:

out = lasagne.layers.get_output(nets[index], x)
theano.function([index], out, givens= {x: inputs})

I basically have a list of neural networks nets and want to dynamically
select which to evaluate, depending on index. How could I do this?

Cris
Post by Frédéric Bastien
Do all element of the list have the same size? If so, I would recommand to
make an ndarray with 1 extra dimensions instead of putting this in a list.
Then you can put this ndarray as a shared variable
nd_list = numpy.ndarray(list)
shared_var = theano.shared(nd_list)
shared_var[index]
And use that in a Theano function.
http://deeplearning.net/software/theano/library/typed_list.html
Fred
Post by Rob
I have circumvented the problem. Rather than creating a list of tensor on
which I apply a single theano function, I just created a list of theano
functions (one for each tensor).
If there are better solutions I would still love to here them.
Post by Rob
I want a theano function that, given a scalar input, will return a
tensor stored in a list at the index of that scalar. i.e
theano.function([index],list[index],givens= {x: <some function of index
})
where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.
TypeError: list indices must be integers, not TensorVariable
I'm very new to Theano so I'm probably thinking about this problem in
the wrong way. I would really appreciate any advice.
Rob
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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.
Frédéric Bastien
2016-07-28 16:19:09 UTC
Permalink
You should compile 1 theano function per network. You can put them in a
list and index that list to find the good funtion to call.

Fred
Post by Florin
out = lasagne.layers.get_output(nets[index], x)
theano.function([index], out, givens= {x: inputs})
I basically have a list of neural networks nets and want to dynamically
select which to evaluate, depending on index. How could I do this?
Cris
Post by Frédéric Bastien
Do all element of the list have the same size? If so, I would recommand
to make an ndarray with 1 extra dimensions instead of putting this in a
list. Then you can put this ndarray as a shared variable
nd_list = numpy.ndarray(list)
shared_var = theano.shared(nd_list)
shared_var[index]
And use that in a Theano function.
http://deeplearning.net/software/theano/library/typed_list.html
Fred
I have circumvented the problem. Rather than creating a list of tensor on
Post by Frédéric Bastien
Post by Rob
which I apply a single theano function, I just created a list of theano
functions (one for each tensor).
If there are better solutions I would still love to here them.
Post by Rob
I want a theano function that, given a scalar input, will return a
tensor stored in a list at the index of that scalar. i.e
theano.function([index],list[index],givens= {x: <some function of index
})
where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.
TypeError: list indices must be integers, not TensorVariable
I'm very new to Theano so I'm probably thinking about this problem in
the wrong way. I would really appreciate any advice.
Rob
--
---
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
Post by Rob
For more options, visit https://groups.google.com/d/optout.
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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.
Bavani Sankar
2017-05-27 21:50:46 UTC
Permalink
I have a python list I want to splice... I also have the theano tensor
i = T.lscalar()
How do I use this scalar to splice the list?
training_x[i * self.mini_batch_size: (i + 1) * self.mini_batch_size]
I get the error: "TypeError: slice indices must be integers or None or
have an __index__ method"
Can you please help me out?
You should compile 1 theano function per network. You can put them in a
list and index that list to find the good funtion to call.
Fred
Post by Florin
out = lasagne.layers.get_output(nets[index], x)
theano.function([index], out, givens= {x: inputs})
I basically have a list of neural networks nets and want to dynamically
select which to evaluate, depending on index. How could I do this?
Cris
Post by Frédéric Bastien
Do all element of the list have the same size? If so, I would recommand
to make an ndarray with 1 extra dimensions instead of putting this in a
list. Then you can put this ndarray as a shared variable
nd_list = numpy.ndarray(list)
shared_var = theano.shared(nd_list)
shared_var[index]
And use that in a Theano function.
http://deeplearning.net/software/theano/library/typed_list.html
Fred
I have circumvented the problem. Rather than creating a list of tensor on
Post by Frédéric Bastien
Post by Rob
which I apply a single theano function, I just created a list of theano
functions (one for each tensor).
If there are better solutions I would still love to here them.
Post by Rob
I want a theano function that, given a scalar input, will return a
tensor stored in a list at the index of that scalar. i.e
theano.function([index],list[index],givens= {x: <some function of index>})
where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.
TypeError: list indices must be integers, not TensorVariable
I'm very new to Theano so I'm probably thinking about this problem in
the wrong way. I would really appreciate any advice.
Rob
--
---
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
Post by Rob
For more options, visit https://groups.google.com/d/optout.
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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.
Frédéric Bastien
2017-05-29 12:28:56 UTC
Permalink
Python list don't know how to handle Theano variable. You can't miss them.
Convert your list to a Theano tensor. Maybe theano.shared(your list) will
work for your case.
Post by Bavani Sankar
I have a python list I want to splice... I also have the theano tensor
i = T.lscalar()
How do I use this scalar to splice the list?
training_x[i * self.mini_batch_size: (i + 1) * self.mini_batch_size]
I get the error: "TypeError: slice indices must be integers or None or
have an __index__ method"
Can you please help me out?
You should compile 1 theano function per network. You can put them in a
list and index that list to find the good funtion to call.
Fred
Post by Florin
out = lasagne.layers.get_output(nets[index], x)
theano.function([index], out, givens= {x: inputs})
I basically have a list of neural networks nets and want to dynamically
select which to evaluate, depending on index. How could I do this?
Cris
Post by Frédéric Bastien
Do all element of the list have the same size? If so, I would recommand
to make an ndarray with 1 extra dimensions instead of putting this in a
list. Then you can put this ndarray as a shared variable
nd_list = numpy.ndarray(list)
shared_var = theano.shared(nd_list)
shared_var[index]
And use that in a Theano function.
http://deeplearning.net/software/theano/library/typed_list.html
Fred
I have circumvented the problem. Rather than creating a list of tensor
Post by Frédéric Bastien
on which I apply a single theano function, I just created a list of theano
functions (one for each tensor).
If there are better solutions I would still love to here them.
Post by Rob
I want a theano function that, given a scalar input, will return a
tensor stored in a list at the index of that scalar. i.e
theano.function([index],list[index],givens= {x: <some function of index>})
where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.
TypeError: list indices must be integers, not TensorVariable
I'm very new to Theano so I'm probably thinking about this problem in
the wrong way. I would really appreciate any advice.
Rob
--
---
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.
--
---
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.
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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.
Bavani Sankar
2017-05-30 07:02:54 UTC
Permalink
Ok, I did that... Now it throws the error: TypeError: Cannot convert Type
TensorType(int32, matrix) (of Variable Subtensor{int64:int64:}.0) into Type
TensorType(int32, vector)

Error on the line

y: training_y[index * batch_size: (index + 1) * batch_size]

How to fix this? My training labels are nparrays casted into Tensor shared variables.
Here is the link to my code:
*https://github.com/Layman806/ocr-cnn/blob/master/CNN.py*
Post by Frédéric Bastien
Python list don't know how to handle Theano variable. You can't miss them.
Convert your list to a Theano tensor. Maybe theano.shared(your list) will
work for your case.
Post by Bavani Sankar
I have a python list I want to splice... I also have the theano tensor
i = T.lscalar()
How do I use this scalar to splice the list?
training_x[i * self.mini_batch_size: (i + 1) * self.mini_batch_size]
I get the error: "TypeError: slice indices must be integers or None or
have an __index__ method"
Can you please help me out?
You should compile 1 theano function per network. You can put them in a
list and index that list to find the good funtion to call.
Fred
Post by Florin
out = lasagne.layers.get_output(nets[index], x)
theano.function([index], out, givens= {x: inputs})
I basically have a list of neural networks nets and want to dynamically
select which to evaluate, depending on index. How could I do this?
Cris
Post by Frédéric Bastien
Do all element of the list have the same size? If so, I would
recommand to make an ndarray with 1 extra dimensions instead of putting
this in a list. Then you can put this ndarray as a shared variable
nd_list = numpy.ndarray(list)
shared_var = theano.shared(nd_list)
shared_var[index]
And use that in a Theano function.
http://deeplearning.net/software/theano/library/typed_list.html
Fred
I have circumvented the problem. Rather than creating a list of tensor
Post by Frédéric Bastien
on which I apply a single theano function, I just created a list of theano
functions (one for each tensor).
If there are better solutions I would still love to here them.
Post by Rob
I want a theano function that, given a scalar input, will return a
tensor stored in a list at the index of that scalar. i.e
theano.function([index],list[index],givens= {x: <some function of index>})
where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.
TypeError: list indices must be integers, not TensorVariable
I'm very new to Theano so I'm probably thinking about this problem
in the wrong way. I would really appreciate any advice.
Rob
--
---
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.
--
---
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.
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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.
Bavani Sankar
2017-05-30 07:10:00 UTC
Permalink
Did that, but now it shows me the error:
TypeError: Cannot convert Type TensorType(float64, 3D) (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).

on the line:

training_y[index * self.mini_batch_size: (index + 1) * self.mini_batch_size]

I changed the input. It is the 74K dataset. And the labels are np arrays. I casted themn into Theano shared variables, like in the tutorial, but I don't know what else is wrong.
Here is the code:
https://github.com/Layman806/ocr-cnn/blob/master/CNN.py
Post by Frédéric Bastien
Python list don't know how to handle Theano variable. You can't miss them.
Convert your list to a Theano tensor. Maybe theano.shared(your list) will
work for your case.
Post by Bavani Sankar
I have a python list I want to splice... I also have the theano tensor
i = T.lscalar()
How do I use this scalar to splice the list?
training_x[i * self.mini_batch_size: (i + 1) * self.mini_batch_size]
I get the error: "TypeError: slice indices must be integers or None or
have an __index__ method"
Can you please help me out?
You should compile 1 theano function per network. You can put them in a
list and index that list to find the good funtion to call.
Fred
Post by Florin
out = lasagne.layers.get_output(nets[index], x)
theano.function([index], out, givens= {x: inputs})
I basically have a list of neural networks nets and want to dynamically
select which to evaluate, depending on index. How could I do this?
Cris
Post by Frédéric Bastien
Do all element of the list have the same size? If so, I would
recommand to make an ndarray with 1 extra dimensions instead of putting
this in a list. Then you can put this ndarray as a shared variable
nd_list = numpy.ndarray(list)
shared_var = theano.shared(nd_list)
shared_var[index]
And use that in a Theano function.
http://deeplearning.net/software/theano/library/typed_list.html
Fred
I have circumvented the problem. Rather than creating a list of tensor
Post by Frédéric Bastien
on which I apply a single theano function, I just created a list of theano
functions (one for each tensor).
If there are better solutions I would still love to here them.
Post by Rob
I want a theano function that, given a scalar input, will return a
tensor stored in a list at the index of that scalar. i.e
theano.function([index],list[index],givens= {x: <some function of index>})
where the list contains different x-dependent tensors that I want to
evaluate depending on the index given.
TypeError: list indices must be integers, not TensorVariable
I'm very new to Theano so I'm probably thinking about this problem
in the wrong way. I would really appreciate any advice.
Rob
--
---
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.
--
---
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.
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
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...