提交 5ed22311 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Some flake8 fixes.

上级 c508befc
...@@ -6,32 +6,31 @@ import sys ...@@ -6,32 +6,31 @@ import sys
import time import time
import unittest import unittest
import numpy import numpy
from six.moves import xrange from six.moves import xrange
from nose.plugins.skip import SkipTest
imported_scipy_convolve2d = False
try:
from scipy.signal import convolve2d
imported_scipy_convolve2d = True
except ImportError:
pass
import theano import theano
from theano import tensor from theano import tensor
from theano.tests.unittest_tools import seed_rng from theano.tests.unittest_tools import seed_rng
# We let that import do the init of the back-end if needed. # We let that import do the init of the back-end if needed.
from .test_basic_ops import (mode_with_gpu, from .test_basic_ops import mode_with_gpu
mode_without_gpu)
from ..type import GpuArrayType from ..type import GpuArrayType
from ..conv import GpuConv from ..conv import GpuConv
from theano.sandbox.gpuarray import dnn from theano.sandbox.gpuarray import dnn
import pygpu import pygpu
imported_scipy_convolve2d = False
try:
from scipy.signal import convolve2d
imported_scipy_convolve2d = True
except ImportError:
pass
gftensor4 = GpuArrayType('float32', [False] * 4) gftensor4 = GpuArrayType('float32', [False] * 4)
def py_conv_valid_numpy(img, kern): def py_conv_valid_numpy(img, kern):
assert img.shape[1] == kern.shape[1] assert img.shape[1] == kern.shape[1]
outshp = (img.shape[0], kern.shape[0], outshp = (img.shape[0], kern.shape[0],
...@@ -191,15 +190,17 @@ def _params_allgood(ishape, kshape, mode, subsample=(1, 1), img_stride=(1, 1), ...@@ -191,15 +190,17 @@ def _params_allgood(ishape, kshape, mode, subsample=(1, 1), img_stride=(1, 1),
cpu_mflops = approx_fp / (t1 - t0) cpu_mflops = approx_fp / (t1 - t0)
gpu_mflops = approx_fp / (t2 - t1) gpu_mflops = approx_fp / (t2 - t1)
if verbose > 0: if verbose > 0:
print('%15s' % str(ishape), '%15s' % str(kshape), end=' ', file=sys.stdout) print('%15s' % str(ishape), '%15s' % str(kshape), end=' ',
print('%12.5f %7.2f %7.2f %7.1f' % (approx_fp, file=sys.stdout)
cpu_mflops, gpu_mflops, (t1 - t0) / (t2 - t1)), file=sys.stdout) print('%12.5f %7.2f %7.2f %7.1f' %
(approx_fp, cpu_mflops, gpu_mflops, (t1 - t0) / (t2 - t1)),
file=sys.stdout)
if not rval: if not rval:
print(('test_' + mode + ' id=' + str(id) + print('test_' + mode + ' id=' + str(id) +
' FAILED for ishape, kshape, mode, subsample,' + ' FAILED for ishape, kshape, mode, subsample,' +
' img_stride, kern_stride, version', ishape, ' img_stride, kern_stride, version', ishape,
kshape, mode, subsample, img_stride, kern_stride, kshape, mode, subsample, img_stride, kern_stride,
version), file=sys.stdout) version, file=sys.stdout)
diff = cpuval - gpuval diff = cpuval - gpuval
diffabs = numpy.absolute(diff) diffabs = numpy.absolute(diff)
pr_diff = diffabs / numpy.absolute(cpuval) pr_diff = diffabs / numpy.absolute(cpuval)
...@@ -210,7 +211,7 @@ def _params_allgood(ishape, kshape, mode, subsample=(1, 1), img_stride=(1, 1), ...@@ -210,7 +211,7 @@ def _params_allgood(ishape, kshape, mode, subsample=(1, 1), img_stride=(1, 1),
nb_close, "/", diff.size)) nb_close, "/", diff.size))
print("max relatif diff:", (pr_diff.max(), "avg rel diff:", print("max relatif diff:", (pr_diff.max(), "avg rel diff:",
numpy.average(pr_diff))) numpy.average(pr_diff)))
if not rval and print_ != False: if not rval and print_ is not False:
if npy_img.shape[0] > 5: if npy_img.shape[0] > 5:
print("img", npy_img[0]) print("img", npy_img[0])
print("kern", npy_kern[0]) print("kern", npy_kern[0])
...@@ -242,7 +243,8 @@ def exec_conv(version, shapes, verbose, random, mode, ...@@ -242,7 +243,8 @@ def exec_conv(version, shapes, verbose, random, mode,
istride, kstride) in enumerate(shapes): istride, kstride) in enumerate(shapes):
ret = False ret = False
try: try:
ret = _params_allgood(ishape, ret = _params_allgood(
ishape,
kshape, kshape,
mode, mode,
subsample=subshape, subsample=subshape,
...@@ -297,15 +299,15 @@ def get_shapes(imshp=(1, 1), kshp=(1, 1), subsample=(1, 1), ...@@ -297,15 +299,15 @@ def get_shapes(imshp=(1, 1), kshp=(1, 1), subsample=(1, 1),
((3, 1) + imshp, (1, 1) + kshp, subsample, img_stride, kern_stride), ((3, 1) + imshp, (1, 1) + kshp, subsample, img_stride, kern_stride),
# nkern only # nkern only
((1, 1) + imshp, (2, 1) + kshp, subsample, img_stride, kern_stride), ((1, 1) + imshp, (2, 1) + kshp, subsample, img_stride, kern_stride),
#batch and nkern # batch and nkern
((3, 1) + imshp, (2, 1) + kshp, subsample, img_stride, kern_stride), ((3, 1) + imshp, (2, 1) + kshp, subsample, img_stride, kern_stride),
#batch and stack # batch and stack
((3, 2) + imshp, (1, 2) + kshp, subsample, img_stride, kern_stride), ((3, 2) + imshp, (1, 2) + kshp, subsample, img_stride, kern_stride),
#stack and nkern # stack and nkern
((1, 2) + imshp, (2, 2) + kshp, subsample, img_stride, kern_stride), ((1, 2) + imshp, (2, 2) + kshp, subsample, img_stride, kern_stride),
#batch, nkern and stack # batch, nkern and stack
((2, 2) + imshp, (2, 2) + kshp, subsample, img_stride, kern_stride), ((2, 2) + imshp, (2, 2) + kshp, subsample, img_stride, kern_stride),
#batch, nkern and stack # batch, nkern and stack
((3, 2) + imshp, (4, 2) + kshp, subsample, img_stride, kern_stride) ((3, 2) + imshp, (4, 2) + kshp, subsample, img_stride, kern_stride)
] ]
...@@ -344,7 +346,6 @@ def get_shapes2(scales_img=(1, 1), scales_kern=(1, 1), subsample=(1, 1), ...@@ -344,7 +346,6 @@ def get_shapes2(scales_img=(1, 1), scales_kern=(1, 1), subsample=(1, 1),
def get_valid_shapes(): def get_valid_shapes():
# img shape, kern shape, subsample shape # img shape, kern shape, subsample shape
shapes = get_basic_shapes() shapes = get_basic_shapes()
...@@ -361,37 +362,34 @@ def get_valid_shapes(): ...@@ -361,37 +362,34 @@ def get_valid_shapes():
shapes += [ shapes += [
# other test # other test
((2, 1, 2, 2), (1, 1, 2, 2), (1, 1), (1, 1), (1, 1)) ((2, 1, 2, 2), (1, 1, 2, 2), (1, 1), (1, 1), (1, 1)),
, ((3, 2, 4, 4), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)) ((3, 2, 4, 4), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)),
, ((4, 1, 10, 10), (1, 1, 2, 2), (1, 1), (1, 1), (1, 1)) ((4, 1, 10, 10), (1, 1, 2, 2), (1, 1), (1, 1), (1, 1)),
, ((1, 1, 4, 4), (1, 1, 2, 3), (1, 1), (1, 1), (1, 1)) ((1, 1, 4, 4), (1, 1, 2, 3), (1, 1), (1, 1), (1, 1)),
, ((4, 1, 10, 10), (1, 1, 2, 3), (1, 1), (1, 1), (1, 1)) ((4, 1, 10, 10), (1, 1, 2, 3), (1, 1), (1, 1), (1, 1)),
, ((4, 1, 10, 10), (1, 1, 2, 10), (1, 1), (1, 1), (1, 1)) ((4, 1, 10, 10), (1, 1, 2, 10), (1, 1), (1, 1), (1, 1)),
, ((4, 1, 20, 10), (1, 1, 2, 10), (1, 1), (1, 1), (1, 1)) ((4, 1, 20, 10), (1, 1, 2, 10), (1, 1), (1, 1), (1, 1)),
, ((3, 2, 8, 8), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)) # stack, nkern, bsize ((3, 2, 8, 8), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)), # stack, nkern, bsize
, ((3, 2, 8, 6), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)) # stack, nkern, bsize, non-square image ((3, 2, 8, 6), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)), # stack, nkern, bsize, non-square image
, ((3, 2, 8, 6), (4, 2, 4, 3), (1, 1), (1, 1), (1, 1)) # stack, nkern, bsize, non-square image, non-square kern ((3, 2, 8, 6), (4, 2, 4, 3), (1, 1), (1, 1), (1, 1)), # stack, nkern, bsize, non-square image, non-square kern
, ((3, 2, 8, 6), (4, 2, 4, 6), (1, 1), (1, 1), (1, 1)) # stack, nkern, bsize ,non-square image, non-square kern, kernsize==imgsize on one dim ((3, 2, 8, 6), (4, 2, 4, 6), (1, 1), (1, 1), (1, 1)), # stack, nkern, bsize ,non-square image, non-square kern, kernsize==imgsize on one dim
, ((16, 5, 64, 64), (8, 5, 8, 8), (1, 1), (1, 1), (1, 1)) # a big one ((16, 5, 64, 64), (8, 5, 8, 8), (1, 1), (1, 1), (1, 1)), # a big one
, ((16, 1, 28, 28), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)) # MNIST LeNET layer 1 ((16, 1, 28, 28), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)), # MNIST LeNET layer 1
, ((20, 16, 32, 32), (1, 16, 28, 28), (1, 1), (1, 1), (1, 1)) # layer 1 backprop to weights ((20, 16, 32, 32), (1, 16, 28, 28), (1, 1), (1, 1), (1, 1)), # layer 1 backprop to weights
, ((60, 20, 28, 28), (10, 20, 5, 5), (1, 1), (2, 2), (1, 1)) # added a test case that fail from test_nnet.py.test_conv_nnet2 ((60, 20, 28, 28), (10, 20, 5, 5), (1, 1), (2, 2), (1, 1)), # added a test case that fail from test_nnet.py.test_conv_nnet2
, ((10, 5, 28, 28), (10, 5, 5, 5), (1, 1), (2, 2), (1, 1)) # test precedent but reduced that triger the error ((10, 5, 28, 28), (10, 5, 5, 5), (1, 1), (2, 2), (1, 1)), # test precedent but reduced that triger the error
# Test more than maxThreadsDim0 # Test more than maxThreadsDim0
, ((2, 4, 13, 1050), (3, 4, 10, 11), (1, 1), (1, 1), (1, 1)) ((2, 4, 13, 1050), (3, 4, 10, 11), (1, 1), (1, 1), (1, 1)),
, ((2, 4, 1050, 13), (3, 4, 10, 11), (1, 1), (1, 1), (1, 1)) ((2, 4, 1050, 13), (3, 4, 10, 11), (1, 1), (1, 1), (1, 1)),
] ]
shapes += [ ((60, 1, 28, 28), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)) # test_lenet_28 1 layers shapes += [((60, 1, 28, 28), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)), # test_lenet_28 1 layers
, ((60, 20, 12, 12), (30, 20, 5, 5), (1, 1), (1, 1), (1, 1)) # test_lenet_28 2 layers ((60, 20, 12, 12), (30, 20, 5, 5), (1, 1), (1, 1), (1, 1)), # test_lenet_28 2 layers
, ((60, 30, 8, 8), (20, 30, 5, 5), (1, 1), (1, 1), (1, 1)) # test_lenet_28 bprop 1 full ((60, 30, 8, 8), (20, 30, 5, 5), (1, 1), (1, 1), (1, 1)), # test_lenet_28 bprop 1 full
, ((20, 60, 12, 12), (30, 60, 8, 8), (1, 1), (1, 1), (1, 1)) # test_lenet_28 bprop 2 valid ((20, 60, 12, 12), (30, 60, 8, 8), (1, 1), (1, 1), (1, 1)), # test_lenet_28 bprop 2 valid
# , ((1,60,28,28),(20,60,24,24), (1, 1), (1, 1), (1, 1))#test_lenet_28 bprop 2 valid ((10, 1, 64, 64), (20, 1, 7, 7), (1, 1), (1, 1), (1, 1)), # test_lenet_64 1 layers
, ((10, 1, 64, 64), (20, 1, 7, 7), (1, 1), (1, 1), (1, 1)) # test_lenet_64 1 layers ((10, 20, 29, 29), (30, 20, 7, 7), (1, 1), (1, 1), (1, 1)), # test_lenet_64 2 layers
, ((10, 20, 29, 29), (30, 20, 7, 7), (1, 1), (1, 1), (1, 1)) # test_lenet_64 2 layers ((10, 30, 23, 23), (20, 30, 7, 7), (1, 1), (1, 1), (1, 1)), # test_lenet_64 full
, ((10, 30, 23, 23), (20, 30, 7, 7), (1, 1), (1, 1), (1, 1)) # test_lenet_64 full
# , ((20,10,29,29),(30,10,23,23), (1, 1), (1, 1), (1, 1))#test_lenet_64 bprop 1
# , ((1,10,64,64),(20,10,58,58), (1, 1), (1, 1), (1, 1))#test_lenet_64 bprop 2
] ]
return shapes return shapes
...@@ -428,42 +426,34 @@ def test_full(): ...@@ -428,42 +426,34 @@ def test_full():
shapes += [ shapes += [
# other test # other test
((2, 1, 2, 2), (1, 1, 2, 2), (1, 1), (1, 1), (1, 1)) ((2, 1, 2, 2), (1, 1, 2, 2), (1, 1), (1, 1), (1, 1)),
, ((3, 2, 4, 4), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)) ((3, 2, 4, 4), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)),
, ((4, 1, 10, 10), (1, 1, 2, 2), (1, 1), (1, 1), (1, 1)) ((4, 1, 10, 10), (1, 1, 2, 2), (1, 1), (1, 1), (1, 1)),
, ((1, 1, 4, 4), (1, 1, 2, 3), (1, 1), (1, 1), (1, 1)) ((1, 1, 4, 4), (1, 1, 2, 3), (1, 1), (1, 1), (1, 1)),
, ((4, 1, 10, 10), (1, 1, 2, 3), (1, 1), (1, 1), (1, 1)) ((4, 1, 10, 10), (1, 1, 2, 3), (1, 1), (1, 1), (1, 1)),
, ((4, 1, 10, 10), (1, 1, 2, 10), (1, 1), (1, 1), (1, 1)) ((4, 1, 10, 10), (1, 1, 2, 10), (1, 1), (1, 1), (1, 1)),
, ((4, 1, 20, 10), (1, 1, 2, 10), (1, 1), (1, 1), (1, 1)) ((4, 1, 20, 10), (1, 1, 2, 10), (1, 1), (1, 1), (1, 1)),
, ((3, 2, 8, 8), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)) # stack, nkern, bsize ((3, 2, 8, 8), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)), # stack, nkern, bsize
, ((3, 2, 8, 6), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)) # stack, nkern, bsize, non-square image ((3, 2, 8, 6), (4, 2, 4, 4), (1, 1), (1, 1), (1, 1)), # stack, nkern, bsize, non-square image
, ((3, 2, 8, 6), (4, 2, 4, 3), (1, 1), (1, 1), (1, 1)) # stack, nkern, bsize, non-square image, non-square kern ((3, 2, 8, 6), (4, 2, 4, 3), (1, 1), (1, 1), (1, 1)), # stack, nkern, bsize, non-square image, non-square kern
, ((3, 2, 8, 6), (4, 2, 4, 6), (1, 1), (1, 1), (1, 1)) # stack, nkern, bsize ,non-square image, non-square kern, kernsize==imgsize on one dim ((3, 2, 8, 6), (4, 2, 4, 6), (1, 1), (1, 1), (1, 1)), # stack, nkern, bsize ,non-square image, non-square kern, kernsize==imgsize on one dim
, ((16, 5, 64, 64), (8, 5, 8, 8), (1, 1), (1, 1), (1, 1)) # a big one ((16, 5, 64, 64), (8, 5, 8, 8), (1, 1), (1, 1), (1, 1)), # a big one
, ((16, 1, 28, 28), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)) # MNIST LeNET layer 1 ((16, 1, 28, 28), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)), # MNIST LeNET layer 1
, ((20, 16, 32, 32), (1, 16, 28, 28), (1, 1), (1, 1), (1, 1)) # layer 1 backprop to weights ((20, 16, 32, 32), (1, 16, 28, 28), (1, 1), (1, 1), (1, 1)), # layer 1 backprop to weights
# other test # other test
, ((3, 1, 1, 1), (2, 1, 5, 3), (1, 1), (1, 1), (1, 1)) # kernel bigger then image ((3, 1, 1, 1), (2, 1, 5, 3), (1, 1), (1, 1), (1, 1)), # kernel bigger then image
, ((3, 2, 1, 1), (4, 2, 1, 1), (1, 1), (1, 1), (1, 1)) ((3, 2, 1, 1), (4, 2, 1, 1), (1, 1), (1, 1), (1, 1)),
, ((3, 2, 4, 4), (4, 2, 2, 6), (1, 1), (1, 1), (1, 1)) ((3, 2, 4, 4), (4, 2, 2, 6), (1, 1), (1, 1), (1, 1)),
, ((3, 2, 4, 4), (4, 2, 8, 6), (1, 1), (1, 1), (1, 1)) # kernel bigger then image ((3, 2, 4, 4), (4, 2, 8, 6), (1, 1), (1, 1), (1, 1)), # kernel bigger then image
, ((4, 2, 10, 10), (3, 2, 2, 12), (1, 1), (1, 1), (1, 1)) ((4, 2, 10, 10), (3, 2, 2, 12), (1, 1), (1, 1), (1, 1)),
] ]
shapes += [ shapes += [
# ((60,1,28,28),(20,1,5,5), (1, 1), (1, 1), (1, 1))#test_lenet_28 1 layers ((60, 30, 8, 8), (20, 30, 5, 5), (1, 1), (1, 1), (1, 1)), # test_lenet_28 bprop 1 full
# , ((60,20,12,12),(30,20,5,5), (1, 1), (1, 1), (1, 1))#test_lenet_28 2 layers ((10, 30, 23, 23), (20, 30, 7, 7), (1, 1), (1, 1), (1, 1)), # test_lenet_64 full
((60, 30, 8, 8), (20, 30, 5, 5), (1, 1), (1, 1), (1, 1)) # test_lenet_28 bprop 1 full
# , ((20,60,12,12),(30,60,8,8), (1, 1), (1, 1), (1, 1))#test_lenet_28 bprop 2 valid
# , ((1,60,28,28),(20,60,24,24), (1, 1), (1, 1), (1, 1))#test_lenet_28 bprop 2 valid
# , ((10,1,64,64),(20,1,7,7), (1, 1), (1, 1), (1, 1))#test_lenet_64 1 layers
# , ((10,20,29,29),(30,20,7,7), (1, 1), (1, 1), (1, 1))#test_lenet_64 2 layers
, ((10, 30, 23, 23), (20, 30, 7, 7), (1, 1), (1, 1), (1, 1)) # test_lenet_64 full
# , ((20,10,29,29),(30,10,23,23), (1, 1), (1, 1), (1, 1))#test_lenet_64 bprop 1
# , ((1,10,64,64),(20,10,58,58), (1, 1), (1, 1), (1, 1))#test_lenet_64 bprop 2
# Test more than maxThreadsDim0 # Test more than maxThreadsDim0
, ((2, 4, 13, 1050), (3, 4, 10, 11), (1, 1), (1, 1), (1, 1)) ((2, 4, 13, 1050), (3, 4, 10, 11), (1, 1), (1, 1), (1, 1)),
, ((2, 4, 1050, 13), (3, 4, 10, 11), (1, 1), (1, 1), (1, 1)) ((2, 4, 1050, 13), (3, 4, 10, 11), (1, 1), (1, 1), (1, 1)),
] ]
version = [-1] version = [-1]
...@@ -562,7 +552,6 @@ class TestConv2DGPU(unittest.TestCase): ...@@ -562,7 +552,6 @@ class TestConv2DGPU(unittest.TestCase):
for mode in ['valid', 'full']: for mode in ['valid', 'full']:
for shapes in [((3, 2, 8, 8), (4, 2, 5, 5), (8, 8)), for shapes in [((3, 2, 8, 8), (4, 2, 5, 5), (8, 8)),
((3, 2, 8, 8), (4, 2, 5, 5), (5, 8)), ((3, 2, 8, 8), (4, 2, 5, 5), (5, 8)),
#((3, 2, 8, 8), (4, 2, 5, 5), (8, 5)),
# We use only the number of columns. # We use only the number of columns.
]: ]:
...@@ -580,47 +569,45 @@ def benchmark(): ...@@ -580,47 +569,45 @@ def benchmark():
shapes_valid = [ shapes_valid = [
# test_lenet_28 shape # test_lenet_28 shape
((20, 60, 12, 12), (30, 60, 8, 8), (1, 1), (1, 1), (1, 1)) # valid ((20, 60, 12, 12), (30, 60, 8, 8), (1, 1), (1, 1), (1, 1)), # valid
, ((60, 20, 12, 12), (30, 20, 5, 5), (1, 1), (1, 1), (1, 1)) # valid ((60, 20, 12, 12), (30, 20, 5, 5), (1, 1), (1, 1), (1, 1)), # valid
, ((60, 1, 28, 28), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)) # valid ((60, 1, 28, 28), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)), # valid
, ((1, 60, 28, 28), (20, 60, 24, 24), (1, 1), (1, 1), (1, 1)) # valid ((1, 60, 28, 28), (20, 60, 24, 24), (1, 1), (1, 1), (1, 1)), # valid
# test_lenet_32 shape # test_lenet_32 shape
, ((20, 60, 14, 14), (30, 60, 10, 10), (1, 1), (1, 1), (1, 1)) # valid ((20, 60, 14, 14), (30, 60, 10, 10), (1, 1), (1, 1), (1, 1)), # valid
, ((60, 20, 14, 14), (30, 20, 5, 5), (1, 1), (1, 1), (1, 1)) # valid ((60, 20, 14, 14), (30, 20, 5, 5), (1, 1), (1, 1), (1, 1)), # valid
, ((60, 1, 32, 32), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)) # valid ((60, 1, 32, 32), (20, 1, 5, 5), (1, 1), (1, 1), (1, 1)), # valid
, ((1, 60, 32, 32), (20, 60, 28, 28), (1, 1), (1, 1), (1, 1)) # valid ((1, 60, 32, 32), (20, 60, 28, 28), (1, 1), (1, 1), (1, 1)), # valid
# test_lenet_64 shape # test_lenet_64 shape
, ((10, 20, 29, 29), (30, 20, 7, 7), (1, 1), (1, 1), (1, 1)) # valid ((10, 20, 29, 29), (30, 20, 7, 7), (1, 1), (1, 1), (1, 1)), # valid
, ((20, 10, 29, 29), (30, 10, 23, 23), (1, 1), (1, 1), (1, 1)) # valid ((20, 10, 29, 29), (30, 10, 23, 23), (1, 1), (1, 1), (1, 1)), # valid
, ((10, 1, 64, 64), (20, 1, 7, 7), (1, 1), (1, 1), (1, 1)) # valid ((10, 1, 64, 64), (20, 1, 7, 7), (1, 1), (1, 1), (1, 1)), # valid
, ((1, 10, 64, 64), (20, 10, 58, 58), (1, 1), (1, 1), (1, 1)) # valid ((1, 10, 64, 64), (20, 10, 58, 58), (1, 1), (1, 1), (1, 1)), # valid
# test_lenet_108 shape # test_lenet_108 shape
, ((10, 20, 51, 51), (30, 20, 7, 7), (1, 1), (1, 1), (1, 1)) # valid ((10, 20, 51, 51), (30, 20, 7, 7), (1, 1), (1, 1), (1, 1)), # valid
, ((20, 10, 51, 51), (30, 10, 45, 45), (1, 1), (1, 1), (1, 1)) # valid ((20, 10, 51, 51), (30, 10, 45, 45), (1, 1), (1, 1), (1, 1)), # valid
, ((10, 1, 108, 108), (20, 1, 7, 7), (1, 1), (1, 1), (1, 1)) # valid ((10, 1, 108, 108), (20, 1, 7, 7), (1, 1), (1, 1), (1, 1)), # valid
, ((1, 10, 108, 108), (20, 10, 102, 102), (1, 1), (1, 1), (1, 1)) # valid ((1, 10, 108, 108), (20, 10, 102, 102), (1, 1), (1, 1), (1, 1)), # valid
# test_lenet_256 shape # test_lenet_256 shape
, ((2, 20, 124, 124), (30, 20, 9, 9), (1, 1), (1, 1), (1, 1)) # valid ((2, 20, 124, 124), (30, 20, 9, 9), (1, 1), (1, 1), (1, 1)), # valid
, ((20, 2, 124, 124), (30, 2, 116, 116), (1, 1), (1, 1), (1, 1)) # valid ((20, 2, 124, 124), (30, 2, 116, 116), (1, 1), (1, 1), (1, 1)), # valid
, ((2, 1, 256, 256), (20, 1, 9, 9), (1, 1), (1, 1), (1, 1)) # valid ((2, 1, 256, 256), (20, 1, 9, 9), (1, 1), (1, 1), (1, 1)), # valid
, ((1, 2, 256, 256), (20, 2, 248, 248), (1, 1), (1, 1), (1, 1)) # valid ((1, 2, 256, 256), (20, 2, 248, 248), (1, 1), (1, 1), (1, 1)), # valid
] ]
shapes_full = [ shapes_full = [
# test_lenet_28 shape # test_lenet_28 shape
((60, 30, 8, 8), (20, 30, 5, 5), (1, 1), (1, 1), (1, 1)) # full ((60, 30, 8, 8), (20, 30, 5, 5), (1, 1), (1, 1), (1, 1)), # full
# test_lenet_32 shape # test_lenet_32 shape
, ((60, 30, 10, 10), (20, 30, 5, 5), (1, 1), (1, 1), (1, 1)) # full conv_full_patch_stack_padded' N=1 ((60, 30, 10, 10), (20, 30, 5, 5), (1, 1), (1, 1), (1, 1)), # full conv_full_patch_stack_padded' N=1
# test_lenet_64 shape # test_lenet_64 shape
, ((10, 30, 23, 23), (20, 30, 7, 7), (1, 1), (1, 1), (1, 1)) # full conv_full_patch_stack_padded' N=3 ((10, 30, 23, 23), (20, 30, 7, 7), (1, 1), (1, 1), (1, 1)), # full conv_full_patch_stack_padded' N=3
# test_lenet_108 shape # test_lenet_108 shape
, ((10, 30, 45, 45), (20, 30, 7, 7), (1, 1), (1, 1), (1, 1)) # full 'conv_full_patch_stack_padded' N=9 ((10, 30, 45, 45), (20, 30, 7, 7), (1, 1), (1, 1), (1, 1)), # full 'conv_full_patch_stack_padded' N=9
# test_lenet_256 shape # test_lenet_256 shape
, ((2, 30, 116, 116), (20, 30, 9, 9), (1, 1), (1, 1), (1, 1)) # full conv_reference_full ((2, 30, 116, 116), (20, 30, 9, 9), (1, 1), (1, 1), (1, 1)), # full conv_reference_full
] ]
# shapes_valid=shapes_valid[-1:]
# shapes_full=shapes_full[-1:]
version = [-1] version = [-1]
verbose = 1 verbose = 1
random = True random = True
......
import unittest
from theano.tensor.nnet.tests import test_neighbours from theano.tensor.nnet.tests import test_neighbours
# We let that import do the init of the back-end if needed. # We let that import do the init of the back-end if needed.
from .test_basic_ops import (mode_with_gpu, from .test_basic_ops import mode_with_gpu
mode_without_gpu)
from ..neighbours import GpuImages2Neibs from ..neighbours import GpuImages2Neibs
......
from __future__ import print_function from __future__ import print_function
from nose.plugins.skip import SkipTest
import numpy import numpy
import unittest import unittest
...@@ -7,8 +7,6 @@ import theano ...@@ -7,8 +7,6 @@ import theano
import theano.tensor as T import theano.tensor as T
import theano.tests.unittest_tools as utt import theano.tests.unittest_tools as utt
from theano.sandbox import gpuarray
# We let that import do the init of the back-end if needed. # We let that import do the init of the back-end if needed.
from .test_basic_ops import (mode_with_gpu, from .test_basic_ops import (mode_with_gpu,
mode_without_gpu) mode_without_gpu)
...@@ -36,15 +34,13 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias(): ...@@ -36,15 +34,13 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
n_in = 4098 n_in = 4098
n_out = 4099 n_out = 4099
x = T.fmatrix('x')
y = T.lvector('y') y = T.lvector('y')
b = T.fvector('b') b = T.fvector('b')
#W = T.fmatrix('W')
# we precompute the dot with big shape before to allow the test of # we precompute the dot with big shape before to allow the test of
# GpuCrossentropySoftmax1HotWithBiasDx to don't fail with the error # GpuCrossentropySoftmax1HotWithBiasDx to don't fail with the error
#(the launch timed out and was terminated) on GPU card not # (the launch timed out and was terminated) on GPU card not
# powerful enough. We need the big shape to check for corner # powerful enough. We need the big shape to check for corner
# case. # case.
dot_result = T.fmatrix('dot_result') dot_result = T.fmatrix('dot_result')
...@@ -54,7 +50,6 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias(): ...@@ -54,7 +50,6 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
xx = numpy.asarray(numpy.random.rand(batch_size, n_in), xx = numpy.asarray(numpy.random.rand(batch_size, n_in),
dtype=numpy.float32) dtype=numpy.float32)
#?????yy = numpy.ones((batch_size,),dtype='float32')
yy = numpy.ones((batch_size,), dtype='int32') yy = numpy.ones((batch_size,), dtype='int32')
b_values = numpy.zeros((n_out,), dtype='float32') b_values = numpy.zeros((n_out,), dtype='float32')
W_values = numpy.asarray(numpy.random.rand(n_in, n_out), dtype='float32') W_values = numpy.asarray(numpy.random.rand(n_in, n_out), dtype='float32')
...@@ -71,8 +66,6 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias(): ...@@ -71,8 +66,6 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
classify_gpu = theano.function(inputs=[y, b, dot_result], classify_gpu = theano.function(inputs=[y, b, dot_result],
outputs=[loss, y_pred, dW], outputs=[loss, y_pred, dW],
mode=mode_with_gpu) mode=mode_with_gpu)
# theano.printing.debugprint(classify)
# theano.printing.debugprint(classify_gpu)
assert any([isinstance(node.op, assert any([isinstance(node.op,
T.nnet.CrossentropySoftmaxArgmax1HotWithBias) T.nnet.CrossentropySoftmaxArgmax1HotWithBias)
...@@ -97,12 +90,10 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx(): ...@@ -97,12 +90,10 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
We check that we loop when their is too much threads We check that we loop when their is too much threads
""" """
n_in = 1000
batch_size = 4097 batch_size = 4097
n_out = 1250 n_out = 1250
if not isinstance(mode_with_gpu, theano.compile.DebugMode): if not isinstance(mode_with_gpu, theano.compile.DebugMode):
n_in = 4098
n_out = 4099 n_out = 4099
# Seed numpy.random with config.unittests.rseed # Seed numpy.random with config.unittests.rseed
...@@ -137,25 +128,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx(): ...@@ -137,25 +128,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
rtol = 1e-5 rtol = 1e-5
atol = 1e-6 atol = 1e-6
if not numpy.allclose(cpu_out, gpu_out, rtol=rtol, atol=atol): utt.assert_allclose(cpu_out, gpu_out, rtol=rtol, atol=atol)
abs_err, rel_err = T.numeric_grad.abs_rel_err(cpu_out, gpu_out)
scaled_err = numpy.minimum(abs_err / atol, rel_err / rtol)
max_i = scaled_err.argmax()
print('max err index:', max_i, max_i / batch_size, end=' ')
print(max_i % batch_size, max_i / n_out, max_i & n_out)
print('At that index:')
print('err:', scaled_err.flatten()[max_i])
print('absolute error:', abs_err.flatten()[max_i])
print('relative error:', rel_err.flatten()[max_i])
print('cpu_out:', cpu_out.flatten()[max_i])
print('gpu_out:', gpu_out.flatten()[max_i])
print('softmax_output_value:', softmax_output_value.flatten()[max_i])
print('dnll_value:', dnll_value[max_i / n_out])
print('y_idx_value:', y_idx_value[max_i / n_out])
assert False, "numpy.allclose(cpu_out, gpu_out, rtol=%s, atol=%s)" % (
rtol, atol)
def test_softmax_with_bias_float16(): def test_softmax_with_bias_float16():
...@@ -166,6 +139,7 @@ def test_softmax_with_bias_float16(): ...@@ -166,6 +139,7 @@ def test_softmax_with_bias_float16():
softmax_with_bias_unittest_template(dtypeInput='float32', softmax_with_bias_unittest_template(dtypeInput='float32',
dtypeBias='float16') dtypeBias='float16')
def test_softmax_with_bias_float32(): def test_softmax_with_bias_float32():
softmax_with_bias_unittest_template(dtypeInput='float32', softmax_with_bias_unittest_template(dtypeInput='float32',
dtypeBias='float32') dtypeBias='float32')
...@@ -188,6 +162,7 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias): ...@@ -188,6 +162,7 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias):
TODO: check that we loop when there are too many threads. (THIS IS TODO: check that we loop when there are too many threads. (THIS IS
NOT IMPLEMENTED) NOT IMPLEMENTED)
""" """
x = T.matrix('x', dtype=dtypeInput) x = T.matrix('x', dtype=dtypeInput)
b = T.vector('b', dtype=dtypeBias) b = T.vector('b', dtype=dtypeBias)
...@@ -228,9 +203,11 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias): ...@@ -228,9 +203,11 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias):
def test_softmax_float16(): def test_softmax_float16():
softmax_unittest_template('float16') softmax_unittest_template('float16')
def test_softmax_float32(): def test_softmax_float32():
softmax_unittest_template('float32') softmax_unittest_template('float32')
def test_softmax_float64(): def test_softmax_float64():
softmax_unittest_template('float64') softmax_unittest_template('float64')
......
import operator
import numpy import numpy
import theano import theano
...@@ -25,7 +23,6 @@ def test_deep_copy(): ...@@ -25,7 +23,6 @@ def test_deep_copy():
def test_values_eq_approx(): def test_values_eq_approx():
a = rand_gpuarray(20, dtype='float32') a = rand_gpuarray(20, dtype='float32')
g = GpuArrayType(dtype='float32', broadcastable=(False,))('g')
assert GpuArrayType.values_eq_approx(a, a) assert GpuArrayType.values_eq_approx(a, a)
b = a.copy() b = a.copy()
b[0] = numpy.asarray(b[0]) + 1. b[0] = numpy.asarray(b[0]) + 1.
......
...@@ -160,12 +160,8 @@ whitelist_flake8 = [ ...@@ -160,12 +160,8 @@ whitelist_flake8 = [
"sandbox/gpuarray/__init__.py", "sandbox/gpuarray/__init__.py",
"sandbox/gpuarray/tests/test_subtensor.py", "sandbox/gpuarray/tests/test_subtensor.py",
"sandbox/gpuarray/tests/test_scan.py", "sandbox/gpuarray/tests/test_scan.py",
"sandbox/gpuarray/tests/test_neighbours.py",
"sandbox/gpuarray/tests/test_conv_cuda_ndarray.py",
"sandbox/gpuarray/tests/test_type.py",
"sandbox/gpuarray/tests/test_opt.py", "sandbox/gpuarray/tests/test_opt.py",
"sandbox/gpuarray/tests/test_elemwise.py", "sandbox/gpuarray/tests/test_elemwise.py",
"sandbox/gpuarray/tests/test_nnet.py",
"scan_module/scan_utils.py", "scan_module/scan_utils.py",
"scan_module/scan_views.py", "scan_module/scan_views.py",
"scan_module/scan.py", "scan_module/scan.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论