[visionegg] Re: smooth object motion
- From: Bertrand Guay-Paquet <bernie@xxxxxxxxxxxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Tue, 23 Aug 2005 20:50:15 -0400
Hello,
I have a few ideas you could try out:
1- First of all, do *not* use "for i in xrange(num_range)" if you can
avoid it. Use "for object in object_list". This is much faster since you
go over the list sequentially instead of looking up the index "i" each
time around.
2- Instead of using "object_list[i].position =
object_list[i].trajectory_list[j]", create a method in your object class
which would look something like this:
def next_position(self):
self.current_pos += 1 # move to next position, should check for
# overflow here
self.position = self.trajectory_list[self.current_pos]
Your loop would then look like this:
## in main experiment loop ##
for j in xrange (g_num_cycles):
for object in object_list:
object.next_position()
drawScreen()
This way, you would cut the number of list lookups from 3
(object_list[i], object_list[i] and trajectory_list[j]) to 1 in the
next_position() method. Remember, this is not a compiled language so
each time you index a list, the whole operation is started over. You
could even eliminate the only lookup remaining by storing a list
iterator in your object class. Essentially, you get the iterator by
calling "self.trajectory_list.__iter__()" and from there, you get the
next value with "iterator.next()"
That should speed up your code if this part is really the bottleneck.
Try using the python profiler (neat example in the python docs, easy to
use) to find out where your code is taking longer.
As for Numeric, you might be able to use it. It all depends on the kind
of trajectory your are using for your objects. It might even be faster
to generate your trajectories in real-time. If you give more details
about the trajectories, I can perhaps help you further.
Good luck,
Bertrand
Gabriel Nevarez wrote:
Hello, all,
I was hoping to recode some multiple-object-tracking studies in VisionEgg. So,
thinking that it'd be nice that I finally get to do an object-oriented version
of an object-tracking program, I go about it, only to realize that the
interpreter overhead makes the final program too slow to be useful.
Essentially, I create anywhere from 1 to 10 objects, giving them individual
properties (i.e, size, shape, position, orientation, etc) and append them in a
list, then I iterate through their trajectories, themselves part of the object,
(generated offline and loaded before each trial) for each object, as such:
g_num_objects = 8
g_num_cycles = 1000
## in main experiment loop ##
for j in xrange (g_num_cycles):
for i in xrange(g_num_objects):
object_list[i].position = object_list[i].trajectory_list[j]
drawScreen()
It works exactly as intended.... but *horribly* slow!
Any suggestions on optimizing overall script speed? Have looked into the
generally-recommended performance-enhancing python tips (such as
http://www.szgti.bmf.hu/harp/python/fastpython.html), but seems the main speed
bottleneck is the interpreter moving up and down the call stack within the
embedded loops, so I would need to restructure the object position updates in a
different way from the embedded loops I currently have. I noticed the Dots.py
demo uses the Numeric package to optimize object movement, which I'm currently
looking into.
Any tips?
cheers,
-=Gabriel Nevarez
Research Programmer
Psychology Department
Cardiff University
http://www.cf.ac.uk/psych
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
- References:
- [visionegg] smooth object motion
- From: Gabriel Nevarez
Other related posts:
- » [visionegg] smooth object motion
- » [visionegg] Re: smooth object motion
- » [visionegg] Re: smooth object motion
- » [visionegg] Re: smooth object motion
I was hoping to recode some multiple-object-tracking studies in VisionEgg. So, thinking that it'd be nice that I finally get to do an object-oriented version of an object-tracking program, I go about it, only to realize that the interpreter overhead makes the final program too slow to be useful.
Essentially, I create anywhere from 1 to 10 objects, giving them individual properties (i.e, size, shape, position, orientation, etc) and append them in a list, then I iterate through their trajectories, themselves part of the object, (generated offline and loaded before each trial) for each object, as such:
g_num_objects = 8
g_num_cycles = 1000 ## in main experiment loop ##
for j in xrange (g_num_cycles):
for i in xrange(g_num_objects):
object_list[i].position = object_list[i].trajectory_list[j]
drawScreen()It works exactly as intended.... but *horribly* slow!
Any suggestions on optimizing overall script speed? Have looked into the
generally-recommended performance-enhancing python tips (such as
http://www.szgti.bmf.hu/harp/python/fastpython.html), but seems the main speed
bottleneck is the interpreter moving up and down the call stack within the
embedded loops, so I would need to restructure the object position updates in a
different way from the embedded loops I currently have. I noticed the Dots.py
demo uses the Numeric package to optimize object movement, which I'm currently
looking into.
Any tips?
cheers,
-=Gabriel Nevarez Research Programmer Psychology Department Cardiff University http://www.cf.ac.uk/psych
====================================== The Vision Egg mailing list Archives: http://www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html
- [visionegg] smooth object motion
- From: Gabriel Nevarez