提交 7039dda4 authored 作者: amrithasuresh's avatar amrithasuresh

Updated numpy as np

上级 87057fa6
...@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, division ...@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, division
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from nose.tools import assert_equals from nose.tools import assert_equals
import numpy import numpy as np
from six import integer_types from six import integer_types
import theano import theano
...@@ -67,17 +67,17 @@ class TestCorr3D(utt.InferShapeTester): ...@@ -67,17 +67,17 @@ class TestCorr3D(utt.InferShapeTester):
theano_corr = theano.function([input, filters], output, mode=self.mode) theano_corr = theano.function([input, filters], output, mode=self.mode)
# initialize input and compute result # initialize input and compute result
image_data = numpy.random.random(N_image_shape).astype(self.dtype) image_data = np.random.random(N_image_shape).astype(self.dtype)
filter_data = numpy.random.random(N_filter_shape).astype(self.dtype) filter_data = np.random.random(N_filter_shape).astype(self.dtype)
image_data /= 10 image_data /= 10
filter_data /= 10 filter_data /= 10
if non_contiguous: if non_contiguous:
image_data = numpy.transpose(image_data, axes=(0, 1, 4, 3, 2)) image_data = np.transpose(image_data, axes=(0, 1, 4, 3, 2))
image_data = image_data.copy() image_data = image_data.copy()
image_data = numpy.transpose(image_data, axes=(0, 1, 4, 3, 2)) image_data = np.transpose(image_data, axes=(0, 1, 4, 3, 2))
filter_data = numpy.transpose(filter_data, axes=(0, 1, 4, 3, 2)) filter_data = np.transpose(filter_data, axes=(0, 1, 4, 3, 2))
filter_data = filter_data.copy() filter_data = filter_data.copy()
filter_data = numpy.transpose(filter_data, axes=(0, 1, 4, 3, 2)) filter_data = np.transpose(filter_data, axes=(0, 1, 4, 3, 2))
assert not image_data.flags['CONTIGUOUS'] assert not image_data.flags['CONTIGUOUS']
assert not filter_data.flags['CONTIGUOUS'] assert not filter_data.flags['CONTIGUOUS']
...@@ -85,36 +85,36 @@ class TestCorr3D(utt.InferShapeTester): ...@@ -85,36 +85,36 @@ class TestCorr3D(utt.InferShapeTester):
# REFERENCE IMPLEMENTATION # REFERENCE IMPLEMENTATION
# Testing correlation, not convolution. Reverse filters. # Testing correlation, not convolution. Reverse filters.
filter_data_corr = numpy.array(filter_data[:, :, ::-1, ::-1, ::-1], filter_data_corr = np.array(filter_data[:, :, ::-1, ::-1, ::-1],
copy=True, copy=True,
order='C') order='C')
orig_image_data = image_data orig_image_data = image_data
img_shape3d = numpy.array(N_image_shape[-3:]) img_shape3d = np.array(N_image_shape[-3:])
fil_shape3d = numpy.array(N_filter_shape[-3:]) fil_shape3d = np.array(N_filter_shape[-3:])
dil_shape3d = numpy.array(filter_dilation) dil_shape3d = np.array(filter_dilation)
dil_fil_shape3d = (fil_shape3d - 1) * dil_shape3d + 1 dil_fil_shape3d = (fil_shape3d - 1) * dil_shape3d + 1
subsample3d = numpy.array(subsample) subsample3d = np.array(subsample)
if border_mode == 'full': if border_mode == 'full':
padHWD = (dil_fil_shape3d - 1) padHWD = (dil_fil_shape3d - 1)
elif border_mode == 'valid': elif border_mode == 'valid':
padHWD = numpy.array([0, 0, 0]) padHWD = np.array([0, 0, 0])
elif border_mode == 'half': elif border_mode == 'half':
padHWD = numpy.floor(dil_fil_shape3d / 2).astype('int32') padHWD = np.floor(dil_fil_shape3d / 2).astype('int32')
elif isinstance(border_mode, tuple): elif isinstance(border_mode, tuple):
padHWD = numpy.array(border_mode) padHWD = np.array(border_mode)
elif isinstance(border_mode, integer_types): elif isinstance(border_mode, integer_types):
padHWD = numpy.array([border_mode, border_mode, border_mode]) padHWD = np.array([border_mode, border_mode, border_mode])
else: else:
raise NotImplementedError('Unsupported border_mode {}'.format(border_mode)) raise NotImplementedError('Unsupported border_mode {}'.format(border_mode))
out_shape3d = numpy.floor((img_shape3d + 2 * (padHWD) - dil_fil_shape3d) / subsample3d) + 1 out_shape3d = np.floor((img_shape3d + 2 * (padHWD) - dil_fil_shape3d) / subsample3d) + 1
# avoid numpy deprecation # avoid numpy deprecation
out_shape3d = out_shape3d.astype('int32') out_shape3d = out_shape3d.astype('int32')
out_shape = (N_image_shape[0], N_filter_shape[0]) + tuple(out_shape3d) out_shape = (N_image_shape[0], N_filter_shape[0]) + tuple(out_shape3d)
ref_output = numpy.zeros(out_shape) ref_output = np.zeros(out_shape)
# loop over output feature maps # loop over output feature maps
ref_output.fill(0) ref_output.fill(0)
image_data2 = numpy.zeros((N_image_shape[0], N_image_shape[1], image_data2 = np.zeros((N_image_shape[0], N_image_shape[1],
N_image_shape[2] + 2 * padHWD[0], N_image_shape[2] + 2 * padHWD[0],
N_image_shape[3] + 2 * padHWD[1], N_image_shape[3] + 2 * padHWD[1],
N_image_shape[4] + 2 * padHWD[2])) N_image_shape[4] + 2 * padHWD[2]))
...@@ -283,7 +283,7 @@ class TestCorr3D(utt.InferShapeTester): ...@@ -283,7 +283,7 @@ class TestCorr3D(utt.InferShapeTester):
raise SkipTest("Need cxx for this test") raise SkipTest("Need cxx for this test")
def rand(shape, dtype='float64'): def rand(shape, dtype='float64'):
r = numpy.asarray(numpy.random.rand(*shape), dtype=dtype) r = np.asarray(np.random.rand(*shape), dtype=dtype)
return r * 2 - 1 return r * 2 - 1
ops = [corr3d.Corr3dMM, corr3d.Corr3dMM_gradWeights, corr3d.Corr3dMM_gradInputs] ops = [corr3d.Corr3dMM, corr3d.Corr3dMM_gradWeights, corr3d.Corr3dMM_gradInputs]
...@@ -312,7 +312,7 @@ class TestCorr3D(utt.InferShapeTester): ...@@ -312,7 +312,7 @@ class TestCorr3D(utt.InferShapeTester):
raise SkipTest("Need cxx for this test") raise SkipTest("Need cxx for this test")
def rand(*shape): def rand(*shape):
r = numpy.asarray(numpy.random.rand(*shape), dtype='float64') r = np.asarray(np.random.rand(*shape), dtype='float64')
return r * 2 - 1 return r * 2 - 1
corr3dMM = corr3d.Corr3dMM corr3dMM = corr3d.Corr3dMM
...@@ -345,7 +345,7 @@ class TestCorr3D(utt.InferShapeTester): ...@@ -345,7 +345,7 @@ class TestCorr3D(utt.InferShapeTester):
raise SkipTest("Need cxx for this test") raise SkipTest("Need cxx for this test")
def rand(*shape): def rand(*shape):
r = numpy.asarray(numpy.random.rand(*shape), dtype='float64') r = np.asarray(np.random.rand(*shape), dtype='float64')
return r * 2 - 1 return r * 2 - 1
corr3dMM = corr3d.Corr3dMM corr3dMM = corr3d.Corr3dMM
gradW = corr3d.Corr3dMM_gradWeights gradW = corr3d.Corr3dMM_gradWeights
...@@ -386,7 +386,7 @@ class TestCorr3D(utt.InferShapeTester): ...@@ -386,7 +386,7 @@ class TestCorr3D(utt.InferShapeTester):
raise SkipTest("Need cxx for this test") raise SkipTest("Need cxx for this test")
def rand(*shape): def rand(*shape):
r = numpy.asarray(numpy.random.rand(*shape), dtype='float64') r = np.asarray(np.random.rand(*shape), dtype='float64')
return r * 2 - 1 return r * 2 - 1
corr3dMM = corr3d.Corr3dMM corr3dMM = corr3d.Corr3dMM
gradI = corr3d.Corr3dMM_gradInputs gradI = corr3d.Corr3dMM_gradInputs
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论