提交 642b3356 编写于 作者: J juncaipeng 提交者: Tao Luo

Update test precision from fp32 to fp64 (#21805)

上级 04909137
......@@ -25,7 +25,7 @@ from paddle.fluid import Program, program_guard
class TestMeanOp(OpTest):
def setUp(self):
self.op_type = "mean"
self.dtype = np.float32
self.dtype = np.float64
self.init_dtype_type()
self.inputs = {'X': np.random.random((10, 10)).astype(self.dtype)}
self.outputs = {'Out': np.mean(self.inputs["X"])}
......
......@@ -59,13 +59,13 @@ class TestMineHardExamplesOp(OpTest):
self.sample_size = 0
self.mining_type = "max_negative"
self.cls_loss = np.array([[0.1, 0.1, 0.3],
[0.3, 0.1, 0.1]]).astype('float32')
[0.3, 0.1, 0.1]]).astype('float64')
self.loc_loss = np.array([[0.1, 0.2, 0.3],
[0.3, 0.4, 0.1]]).astype('float32')
[0.3, 0.4, 0.1]]).astype('float64')
self.match_dis = np.array([[0.2, 0.4, 0.8],
[0.1, 0.9, 0.3]]).astype('float32')
[0.1, 0.9, 0.3]]).astype('float64')
self.match_indices = np.array([[0, -1, -1],
[-1, 0, -1]]).astype('int32')
......@@ -83,10 +83,10 @@ class TestMineHardExamplesOpHardExample(TestMineHardExamplesOp):
self.sample_size = 2
self.cls_loss = np.array([[0.5, 0.1, 0.3],
[0.3, 0.1, 0.1]]).astype('float32')
[0.3, 0.1, 0.1]]).astype('float64')
self.loc_loss = np.array([[0.2, 0.2, 0.3],
[0.3, 0.1, 0.2]]).astype('float32')
[0.3, 0.1, 0.2]]).astype('float64')
self.match_indices = np.array([[0, -1, -1],
[-1, 0, -1]]).astype('int32')
......
......@@ -25,7 +25,7 @@ from paddle.fluid import Program, program_guard
class TestMulOp(OpTest):
def setUp(self):
self.op_type = "mul"
self.dtype = np.float32
self.dtype = np.float64
self.init_dtype_type()
self.inputs = {
'X': np.random.random((2, 5)).astype(self.dtype),
......@@ -69,7 +69,7 @@ class TestMulOpError(unittest.TestCase):
class TestMulOp2(OpTest):
def setUp(self):
self.op_type = "mul"
self.dtype = np.float32
self.dtype = np.float64
self.init_dtype_type()
self.inputs = {
'X': np.random.random((3, 4, 4, 3)).astype(self.dtype),
......
......@@ -26,10 +26,10 @@ class TestMultiplexOp(OpTest):
index = np.arange(0, rows).astype('int32')
np.random.shuffle(index)
index = np.reshape(index, (rows, 1))
ins1 = np.random.random((rows, 25)).astype("float32")
ins2 = np.random.random((rows, 25)).astype("float32")
ins3 = np.random.random((rows, 25)).astype("float32")
ins4 = np.random.random((rows, 25)).astype("float32")
ins1 = np.random.random((rows, 25)).astype("float64")
ins2 = np.random.random((rows, 25)).astype("float64")
ins3 = np.random.random((rows, 25)).astype("float64")
ins4 = np.random.random((rows, 25)).astype("float64")
self.inputs = {
'Ids': index,
'X': [('x1', ins1), ('x2', ins2), ('x3', ins3), ('x4', ins4)]
......
......@@ -79,7 +79,7 @@ class TestNearestInterpOp(OpTest):
self.data_layout = 'NCHW'
self.init_test_case()
self.op_type = "nearest_interp"
input_np = np.random.random(self.input_shape).astype("float32")
input_np = np.random.random(self.input_shape).astype("float64")
if self.data_layout == "NCHW":
in_h = self.input_shape[2]
......@@ -340,11 +340,11 @@ class TestNearestInterpOp_attr_tensor(OpTest):
'align_corners': self.align_corners,
}
input_np = np.random.random(self.input_shape).astype("float32")
input_np = np.random.random(self.input_shape).astype("float64")
self.inputs = {'X': input_np}
if self.scale_by_1Dtensor:
self.inputs['Scale'] = np.array([self.scale]).astype("float32")
self.inputs['Scale'] = np.array([self.scale]).astype("float64")
elif self.scale > 0:
out_h = int(self.input_shape[2] * self.scale)
out_w = int(self.input_shape[3] * self.scale)
......
......@@ -25,7 +25,7 @@ class TestPixelShuffle(OpTest):
n, c, h, w = 2, 9, 4, 4
up_factor = 3
shape = [n, c, h, w]
x = np.random.random(shape).astype("float32")
x = np.random.random(shape).astype("float64")
new_shape = (n, c // (up_factor * up_factor), up_factor, up_factor, h,
w)
# reshape to (num,output_channel,upscale_factor,upscale_factor,h,w)
......
......@@ -39,7 +39,7 @@ def max_pool2D_forward_naive(x,
ceil_mode=False,
exclusive=True,
adaptive=False,
data_type=np.float32):
data_type=np.float64):
N, C, H, W = x.shape
if global_pool == 1:
ksize = [H, W]
......@@ -79,7 +79,7 @@ def avg_pool2D_forward_naive(x,
ceil_mode=False,
exclusive=True,
adaptive=False,
data_type=np.float32):
data_type=np.float64):
N, C, H, W = x.shape
if global_pool == 1:
ksize = [H, W]
......@@ -320,7 +320,7 @@ class TestPool2D_Op(OpTest):
self.use_cudnn = False
def init_data_type(self):
self.dtype = np.float32
self.dtype = np.float64
def init_pool_type(self):
self.pool_type = "avg"
......
......@@ -209,7 +209,7 @@ class TestPool3d_Op(OpTest):
def setUp(self):
self.op_type = "pool3d"
self.init_kernel_type()
self.dtype = np.float32
self.dtype = np.float64
self.init_test_case()
self.padding_algorithm = "EXPLICIT"
self.init_paddings()
......
......@@ -140,11 +140,11 @@ class TestMaxPoolWithIndex_Op(OpTest):
self.init_global()
self.init_adaptive()
input = np.random.random(self.shape).astype("float32")
input = np.random.random(self.shape).astype("float64")
output, mask = self.pool_forward_naive(input, self.ksize, self.strides,
self.paddings, self.global_pool,
self.adaptive)
output = output.astype("float32")
output = output.astype("float64")
mask = mask.astype("int32")
self.attrs = {
......
......@@ -47,7 +47,7 @@ class TestPSROIPoolOp(OpTest):
self.pooled_height = 2
self.pooled_width = 2
self.x = np.random.random(self.x_dim).astype('float32')
self.x = np.random.random(self.x_dim).astype('float64')
def make_rois(self):
rois = []
......@@ -67,7 +67,7 @@ class TestPSROIPoolOp(OpTest):
roi = [bno, x1, y1, x2, y2]
rois.append(roi)
self.rois_num = len(rois)
self.rois = np.array(rois).astype('float32')
self.rois = np.array(rois).astype('float64')
def calc_psroi_pool(self):
output_shape = (self.rois_num, self.output_channels, self.pooled_height,
......@@ -117,7 +117,7 @@ class TestPSROIPoolOp(OpTest):
bin_area = (hend - hstart) * (wend - wstart)
out_data[i, c, ph, pw] = 0. if is_empty else (
out_sum / float(bin_area))
self.outs = out_data.astype('float32')
self.outs = out_data.astype('float64')
def setUp(self):
self.op_type = 'psroi_pool'
......
......@@ -21,7 +21,7 @@ from op_test import OpTest
class TestReverseOp(OpTest):
def initTestCase(self):
self.x = np.random.random((3, 40)).astype('float32')
self.x = np.random.random((3, 40)).astype('float64')
self.axis = [0]
def setUp(self):
......@@ -43,25 +43,25 @@ class TestReverseOp(OpTest):
class TestCase0(TestReverseOp):
def initTestCase(self):
self.x = np.random.random((3, 40)).astype('float32')
self.x = np.random.random((3, 40)).astype('float64')
self.axis = [1]
class TestCase1(TestReverseOp):
def initTestCase(self):
self.x = np.random.random((3, 40)).astype('float32')
self.x = np.random.random((3, 40)).astype('float64')
self.axis = [0, 1]
class TestCase2(TestReverseOp):
def initTestCase(self):
self.x = np.random.random((3, 4, 10)).astype('float32')
self.x = np.random.random((3, 4, 10)).astype('float64')
self.axis = [0, 2]
class TestCase3(TestReverseOp):
def initTestCase(self):
self.x = np.random.random((3, 4, 10)).astype('float32')
self.x = np.random.random((3, 4, 10)).astype('float64')
self.axis = [1, 2]
......
......@@ -50,16 +50,16 @@ class TestROIAlignOp(OpTest):
self.pooled_width = 2
self.sampling_ratio = -1
self.x = np.random.random(self.x_dim).astype('float32')
self.x = np.random.random(self.x_dim).astype('float64')
def pre_calc(self, x_i, roi_xmin, roi_ymin, roi_bin_grid_h, roi_bin_grid_w,
bin_size_h, bin_size_w):
count = roi_bin_grid_h * roi_bin_grid_w
bilinear_pos = np.zeros(
[self.channels, self.pooled_height, self.pooled_width, count, 4],
np.float32)
np.float64)
bilinear_w = np.zeros(
[self.pooled_height, self.pooled_width, count, 4], np.float32)
[self.pooled_height, self.pooled_width, count, 4], np.float64)
for ph in range(self.pooled_width):
for pw in range(self.pooled_height):
c = 0
......@@ -109,7 +109,7 @@ class TestROIAlignOp(OpTest):
def calc_roi_align(self):
self.out_data = np.zeros(
(self.rois_num, self.channels, self.pooled_height,
self.pooled_width)).astype('float32')
self.pooled_width)).astype('float64')
for i in range(self.rois_num):
roi = self.rois[i]
......@@ -157,7 +157,7 @@ class TestROIAlignOp(OpTest):
roi = [bno, x1, y1, x2, y2]
rois.append(roi)
self.rois_num = len(rois)
self.rois = np.array(rois).astype("float32")
self.rois = np.array(rois).astype("float64")
def setUp(self):
self.op_type = "roi_align"
......
......@@ -51,7 +51,7 @@ class TestROIPoolOp(OpTest):
self.pooled_height = 2
self.pooled_width = 2
self.x = np.random.random(self.x_dim).astype('float32')
self.x = np.random.random(self.x_dim).astype('float64')
def calc_roi_pool(self):
out_data = np.zeros((self.rois_num, self.channels, self.pooled_height,
......@@ -103,7 +103,7 @@ class TestROIPoolOp(OpTest):
argmax_data[i, c, ph,
pw] = h * self.width + w
self.outs = out_data.astype('float32')
self.outs = out_data.astype('float64')
self.argmaxes = argmax_data.astype('int64')
def make_rois(self):
......@@ -125,7 +125,7 @@ class TestROIPoolOp(OpTest):
roi = [bno, x1, y1, x2, y2]
rois.append(roi)
self.rois_num = len(rois)
self.rois = np.array(rois).astype("float32")
self.rois = np.array(rois).astype("float64")
def setUp(self):
self.op_type = "roi_pool"
......
......@@ -66,9 +66,9 @@ class TestScatterNdAddSimpleOp(OpTest):
def setUp(self):
self.op_type = "scatter_nd_add"
#ref_np = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8]).astype("float32")
ref_np = np.random.random([100]).astype("float32")
ref_np = np.random.random([100]).astype("float64")
index_np = np.random.randint(0, 100, [100, 1]).astype("int32")
updates_np = np.random.random([100]).astype("float32")
updates_np = np.random.random([100]).astype("float64")
expect_np = numpy_scatter_nd_add(ref_np.copy(), index_np, updates_np)
#expect_np = [ 0. 23. 12. 14. 4. 17. 6. 7. 8.]
......@@ -89,10 +89,10 @@ class TestScatterNdAddWithEmptyIndex(OpTest):
def setUp(self):
self.op_type = "scatter_nd_add"
ref_np = np.array([[65, 17], [-14, -25]]).astype("float32")
ref_np = np.array([[65, 17], [-14, -25]]).astype("float64")
index_np = np.array([[], []]).astype("int32")
updates_np = np.array([[[-1, -2], [1, 2]],
[[3, 4], [-3, -4]]]).astype("float32")
[[3, 4], [-3, -4]]]).astype("float64")
expect_np = numpy_scatter_nd_add(ref_np.copy(), index_np, updates_np)
#expect_np = [[67, 19], [-16, -27]]
......@@ -115,12 +115,12 @@ class TestScatterNdAddWithHighRankSame(OpTest):
def setUp(self):
self.op_type = "scatter_nd_add"
shape = (10, 9, 8, 1, 15)
ref_np = np.random.rand(*shape).astype("float32")
ref_np = np.random.rand(*shape).astype("float64")
index_np = np.vstack(
[np.random.randint(
0, s, size=150) for s in shape]).T.astype("int32")
update_shape = judge_update_shape(ref_np, index_np)
updates_np = np.random.rand(*update_shape).astype("float32")
updates_np = np.random.rand(*update_shape).astype("float64")
expect_np = numpy_scatter_nd_add(ref_np.copy(), index_np, updates_np)
self.inputs = {'X': ref_np, 'Index': index_np, 'Updates': updates_np}
......
......@@ -24,7 +24,7 @@ class SeluTest(OpTest):
def setUp(self):
self.op_type = "selu"
self.x_shape = [3, 5, 5, 10]
self.dtype = np.float32
self.dtype = np.float64
self.init_x_shape()
self.init_dtype()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册