提交 1496f6f3 authored 作者: Frederic Bastien's avatar Frederic Bastien

make benchmark convolution script compatible with python 2.4

上级 dfdc95f2
......@@ -7,18 +7,35 @@ try:
ker_shape = int(sys.argv[3]), int(sys.argv[4])
dtype = sys.argv[5]
except:
print >> sys.stderr, "Usage: %s <img rows> <img cols> <ker rows> <ker cols> <dtype>" % sys.argv[0]
print >> sys.stderr, "Usage: %s <img rows> <img cols> <ker rows> <ker cols> <dtype> [nb_call]" % sys.argv[0]
sys.exit(-1)
nb_call = 1
if len(sys.argv)>6:
nb_call=int(sys.argv[6])
setup="""
import sys, timeit, time
import numpy
import theano, theano.tensor.signal.conv
img_shape = int(sys.argv[1]), int(sys.argv[2])
ker_shape = int(sys.argv[3]), int(sys.argv[4])
dtype = sys.argv[5]
img = theano.shared(numpy.ones(img_shape, dtype=dtype))
ker = theano.shared(numpy.ones(ker_shape, dtype=dtype))
out = theano.shared(numpy.ones((2,2,2), dtype=dtype))
"""
T = timeit.Timer("f()",
setup+"f = theano.function([], theano.tensor.signal.conv.conv2d(img, ker))")
time_without_shape = T.repeat(repeat=3, number=nb_call)
print min(time_without_shape), 'without shape'
f = theano.function([], theano.tensor.signal.conv.conv2d(img, ker))
T = timeit.Timer(f)
print min(T.repeat(repeat=3, number=1)), 'without shape'
T = timeit.Timer("f()", setup+"""f = theano.function([], [],
updates={out:theano.tensor.signal.conv.conv2d(img,
ker,image_shape=img_shape,filter_shape=ker_shape)})""")
time_with_shape = T.repeat(repeat=3, number=nb_call)
f = theano.function([], [], updates={out:theano.tensor.signal.conv.conv2d(img,
ker,image_shape=img_shape,filter_shape=ker_shape)})
T = timeit.Timer(f)
print min(T.repeat(repeat=3, number=1)), 'with shape'
print min(time_with_shape), 'with shape'
import sys, timeit, time
import sys, timeit
import numpy
import scikits.image.opencv
......@@ -7,15 +7,25 @@ try:
ker_shape = int(sys.argv[3]), int(sys.argv[4])
dtype = sys.argv[5]
except:
print >> sys.stderr, "Usage: %s <img rows> <img cols> <ker rows> <ker cols> <dtype>" % sys.argv[0]
print >> sys.stderr, "Usage: %s <img rows> <img cols> <ker rows> <ker cols> <dtype> [nb_call]" % sys.argv[0]
sys.exit(-1)
nb_call = 1
if len(sys.argv)>6:
nb_call=int(sys.argv[6])
T = timeit.Timer("f()","""
import scikits.image.opencv, sys, numpy
img_shape = int(sys.argv[1]), int(sys.argv[2])
ker_shape = int(sys.argv[3]), int(sys.argv[4])
dtype = sys.argv[5]
img = numpy.ones(img_shape, dtype=dtype)
ker = numpy.ones(ker_shape, dtype=dtype)
def f():
scikits.image.opencv.cvFilter2D(img, ker)
T = timeit.Timer(f)
print min(T.repeat(repeat=3, number=1))
""")
time = T.repeat(repeat=3, number=nb_call)
print min(time)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论