提交 0c302155 authored 作者: Frederic Bastien's avatar Frederic Bastien

added the benchmark of scipy convolution code.

上级 1496f6f3
#!/bin/bash
python opencv.py $@
python conv2d.py $@
python scipy_conv.py $@
\ No newline at end of file
...@@ -31,11 +31,11 @@ out = theano.shared(numpy.ones((2,2,2), dtype=dtype)) ...@@ -31,11 +31,11 @@ out = theano.shared(numpy.ones((2,2,2), dtype=dtype))
T = timeit.Timer("f()", T = timeit.Timer("f()",
setup+"f = theano.function([], theano.tensor.signal.conv.conv2d(img, ker))") setup+"f = theano.function([], theano.tensor.signal.conv.conv2d(img, ker))")
time_without_shape = T.repeat(repeat=3, number=nb_call) time_without_shape = T.repeat(repeat=3, number=nb_call)
print min(time_without_shape), 'without shape' print min(time_without_shape), 'theano without shape'
T = timeit.Timer("f()", setup+"""f = theano.function([], [], T = timeit.Timer("f()", setup+"""f = theano.function([], [],
updates={out:theano.tensor.signal.conv.conv2d(img, updates={out:theano.tensor.signal.conv.conv2d(img,
ker,image_shape=img_shape,filter_shape=ker_shape)})""") ker,image_shape=img_shape,filter_shape=ker_shape)})""")
time_with_shape = T.repeat(repeat=3, number=nb_call) time_with_shape = T.repeat(repeat=3, number=nb_call)
print min(time_with_shape), 'with shape' print min(time_with_shape), 'theano with shape'
...@@ -27,5 +27,5 @@ def f(): ...@@ -27,5 +27,5 @@ def f():
scikits.image.opencv.cvFilter2D(img, ker) scikits.image.opencv.cvFilter2D(img, ker)
""") """)
time = T.repeat(repeat=3, number=nb_call) time = T.repeat(repeat=3, number=nb_call)
print min(time) print min(time), "opencv"
import sys, timeit
try:
img_shape = int(sys.argv[1]), int(sys.argv[2])
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> [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()","""
from scipy.signal import convolve2d
import 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():
convolve2d(img, ker)
""")
time = T.repeat(repeat=3, number=nb_call)
print min(time), "scipy"
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论