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

Update test precision from fp32 to fp64 (#21848)

上级 2b1f08c7
...@@ -25,11 +25,11 @@ class TestSqueezeOp(OpTest): ...@@ -25,11 +25,11 @@ class TestSqueezeOp(OpTest):
def setUp(self): def setUp(self):
self.op_type = "squeeze2" self.op_type = "squeeze2"
self.init_test_case() self.init_test_case()
self.inputs = {"X": np.random.random(self.ori_shape).astype("float32")} self.inputs = {"X": np.random.random(self.ori_shape).astype("float64")}
self.init_attrs() self.init_attrs()
self.outputs = { self.outputs = {
"Out": self.inputs["X"].reshape(self.new_shape), "Out": self.inputs["X"].reshape(self.new_shape),
"XShape": np.random.random(self.ori_shape).astype("float32") "XShape": np.random.random(self.ori_shape).astype("float64")
} }
def test_check_output(self): def test_check_output(self):
......
...@@ -27,7 +27,7 @@ class TestSqueezeOp(OpTest): ...@@ -27,7 +27,7 @@ class TestSqueezeOp(OpTest):
def setUp(self): def setUp(self):
self.op_type = "squeeze" self.op_type = "squeeze"
self.init_test_case() self.init_test_case()
self.inputs = {"X": np.random.random(self.ori_shape).astype("float32")} self.inputs = {"X": np.random.random(self.ori_shape).astype("float64")}
self.init_attrs() self.init_attrs()
self.outputs = {"Out": self.inputs["X"].reshape(self.new_shape), } self.outputs = {"Out": self.inputs["X"].reshape(self.new_shape), }
......
...@@ -22,7 +22,7 @@ class TestStackOpBase(OpTest): ...@@ -22,7 +22,7 @@ class TestStackOpBase(OpTest):
self.num_inputs = 4 self.num_inputs = 4
self.input_dim = (5, 6, 7) self.input_dim = (5, 6, 7)
self.axis = 0 self.axis = 0
self.dtype = 'float32' self.dtype = 'float64'
def initParameters(self): def initParameters(self):
pass pass
......
...@@ -234,7 +234,7 @@ class TestStridedSliceOp_starts_ListTensor(OpTest): ...@@ -234,7 +234,7 @@ class TestStridedSliceOp_starts_ListTensor(OpTest):
} }
def config(self): def config(self):
self.input = np.random.random([3, 4, 5, 6]).astype("float32") self.input = np.random.random([3, 4, 5, 6]).astype("float64")
self.starts = [1, 0, 2] self.starts = [1, 0, 2]
self.ends = [3, 3, 4] self.ends = [3, 3, 4]
self.axes = [0, 1, 2] self.axes = [0, 1, 2]
...@@ -273,7 +273,7 @@ class TestStridedSliceOp_ends_ListTensor(OpTest): ...@@ -273,7 +273,7 @@ class TestStridedSliceOp_ends_ListTensor(OpTest):
} }
def config(self): def config(self):
self.input = np.random.random([3, 4, 5, 6]).astype("float32") self.input = np.random.random([3, 4, 5, 6]).astype("float64")
self.starts = [1, 0, 0] self.starts = [1, 0, 0]
self.ends = [3, 3, 4] self.ends = [3, 3, 4]
self.axes = [0, 1, 2] self.axes = [0, 1, 2]
...@@ -310,7 +310,7 @@ class TestStridedSliceOp_starts_Tensor(OpTest): ...@@ -310,7 +310,7 @@ class TestStridedSliceOp_starts_Tensor(OpTest):
} }
def config(self): def config(self):
self.input = np.random.random([3, 4, 5, 6]).astype("float32") self.input = np.random.random([3, 4, 5, 6]).astype("float64")
self.starts = [1, 0, 2] self.starts = [1, 0, 2]
self.ends = [2, 3, 4] self.ends = [2, 3, 4]
self.axes = [0, 1, 2] self.axes = [0, 1, 2]
...@@ -345,7 +345,7 @@ class TestStridedSliceOp_ends_Tensor(OpTest): ...@@ -345,7 +345,7 @@ class TestStridedSliceOp_ends_Tensor(OpTest):
} }
def config(self): def config(self):
self.input = np.random.random([3, 4, 5, 6]).astype("float32") self.input = np.random.random([3, 4, 5, 6]).astype("float64")
self.starts = [1, 0, 2] self.starts = [1, 0, 2]
self.ends = [2, 3, 4] self.ends = [2, 3, 4]
self.axes = [0, 1, 2] self.axes = [0, 1, 2]
...@@ -386,7 +386,7 @@ class TestStridedSliceOp_listTensor_Tensor(OpTest): ...@@ -386,7 +386,7 @@ class TestStridedSliceOp_listTensor_Tensor(OpTest):
} }
def config(self): def config(self):
self.input = np.random.random([3, 4, 5, 6]).astype("float32") self.input = np.random.random([3, 4, 5, 6]).astype("float64")
self.starts = [1, 0, 2] self.starts = [1, 0, 2]
self.ends = [2, 3, 4] self.ends = [2, 3, 4]
self.axes = [0, 1, 2] self.axes = [0, 1, 2]
...@@ -421,7 +421,7 @@ class TestStridedSliceOp_strides_Tensor(OpTest): ...@@ -421,7 +421,7 @@ class TestStridedSliceOp_strides_Tensor(OpTest):
} }
def config(self): def config(self):
self.input = np.random.random([3, 4, 5, 6]).astype("float32") self.input = np.random.random([3, 4, 5, 6]).astype("float64")
self.starts = [1, -1, 2] self.starts = [1, -1, 2]
self.ends = [2, 0, 4] self.ends = [2, 0, 4]
self.axes = [0, 1, 2] self.axes = [0, 1, 2]
...@@ -440,7 +440,7 @@ class TestStridedSliceOp_strides_Tensor(OpTest): ...@@ -440,7 +440,7 @@ class TestStridedSliceOp_strides_Tensor(OpTest):
# Test python API # Test python API
class TestStridedSliceAPI(unittest.TestCase): class TestStridedSliceAPI(unittest.TestCase):
def test_1(self): def test_1(self):
input = np.random.random([3, 4, 5, 6]).astype("float32") input = np.random.random([3, 4, 5, 6]).astype("float64")
minus_1 = fluid.layers.fill_constant([1], "int32", -1) minus_1 = fluid.layers.fill_constant([1], "int32", -1)
minus_3 = fluid.layers.fill_constant([1], "int32", -3) minus_3 = fluid.layers.fill_constant([1], "int32", -3)
starts = fluid.layers.data( starts = fluid.layers.data(
...@@ -454,7 +454,7 @@ class TestStridedSliceAPI(unittest.TestCase): ...@@ -454,7 +454,7 @@ class TestStridedSliceAPI(unittest.TestCase):
name="x", name="x",
shape=[3, 4, 5, 6], shape=[3, 4, 5, 6],
append_batch_size=False, append_batch_size=False,
dtype="float32") dtype="float64")
out_1 = fluid.layers.strided_slice( out_1 = fluid.layers.strided_slice(
x, x,
axes=[0, 1, 2], axes=[0, 1, 2],
......
...@@ -36,7 +36,7 @@ class TestSumOp(OpTest): ...@@ -36,7 +36,7 @@ class TestSumOp(OpTest):
self.attrs = {'use_mkldnn': self.use_mkldnn} self.attrs = {'use_mkldnn': self.use_mkldnn}
def init_kernel_type(self): def init_kernel_type(self):
self.dtype = np.float32 self.dtype = np.float64
def test_check_output(self): def test_check_output(self):
self.check_output() self.check_output()
...@@ -53,7 +53,7 @@ class TestSelectedRowsSumOp(unittest.TestCase): ...@@ -53,7 +53,7 @@ class TestSelectedRowsSumOp(unittest.TestCase):
self.height = 10 self.height = 10
self.row_numel = 12 self.row_numel = 12
self.rows = [0, 1, 2, 3, 4, 5, 6] self.rows = [0, 1, 2, 3, 4, 5, 6]
self.dtype = np.float32 self.dtype = np.float64
self.init_kernel_type() self.init_kernel_type()
def check_with_place(self, place, inplace): def check_with_place(self, place, inplace):
...@@ -144,7 +144,7 @@ class TestLoDTensorAndSelectedRowsOp(TestSelectedRowsSumOp): ...@@ -144,7 +144,7 @@ class TestLoDTensorAndSelectedRowsOp(TestSelectedRowsSumOp):
self.height = 10 self.height = 10
self.row_numel = 12 self.row_numel = 12
self.rows = [0, 1, 2, 2, 4, 5, 6] self.rows = [0, 1, 2, 2, 4, 5, 6]
self.dtype = np.float32 self.dtype = np.float64
def check_with_place(self, place, inplace): def check_with_place(self, place, inplace):
scope = core.Scope() scope = core.Scope()
......
...@@ -33,9 +33,9 @@ class TestTeacherStudentSigmoidLossOp(OpTest): ...@@ -33,9 +33,9 @@ class TestTeacherStudentSigmoidLossOp(OpTest):
self.inputs = { self.inputs = {
'X': logit( 'X': logit(
np.random.uniform(0, 1, (batch_size, num_classes)) np.random.uniform(0, 1, (batch_size, num_classes))
.astype("float32")), .astype("float64")),
'Label': np.random.uniform(0, 2, (batch_size, num_classes)) 'Label': np.random.uniform(0, 2, (batch_size, num_classes))
.astype("float32") .astype("float64")
} }
outs = [] outs = []
for index, label in enumerate(self.inputs["Label"]): for index, label in enumerate(self.inputs["Label"]):
......
...@@ -39,7 +39,7 @@ class TestTemporalShift(OpTest): ...@@ -39,7 +39,7 @@ class TestTemporalShift(OpTest):
def setUp(self): def setUp(self):
self.initTestCase() self.initTestCase()
self.op_type = 'temporal_shift' self.op_type = 'temporal_shift'
x = np.random.random(self.x_shape).astype('float32') x = np.random.random(self.x_shape).astype('float64')
self.attrs = { self.attrs = {
"seg_num": self.seg_num, "seg_num": self.seg_num,
......
...@@ -25,13 +25,13 @@ class TestTransposeOp(OpTest): ...@@ -25,13 +25,13 @@ class TestTransposeOp(OpTest):
def setUp(self): def setUp(self):
self.init_op_type() self.init_op_type()
self.initTestCase() self.initTestCase()
self.inputs = {'X': np.random.random(self.shape).astype("float32")} self.inputs = {'X': np.random.random(self.shape).astype("float64")}
self.attrs = { self.attrs = {
'axis': list(self.axis), 'axis': list(self.axis),
'use_mkldnn': self.use_mkldnn, 'use_mkldnn': self.use_mkldnn,
} }
self.outputs = { self.outputs = {
'XShape': np.random.random(self.shape).astype("float32"), 'XShape': np.random.random(self.shape).astype("float64"),
'Out': self.inputs['X'].transpose(self.axis) 'Out': self.inputs['X'].transpose(self.axis)
} }
...@@ -83,7 +83,7 @@ class TestCase4(TestTransposeOp): ...@@ -83,7 +83,7 @@ class TestCase4(TestTransposeOp):
class TestTransposeOpError(unittest.TestCase): class TestTransposeOpError(unittest.TestCase):
def test_errors(self): def test_errors(self):
with program_guard(Program(), Program()): with program_guard(Program(), Program()):
x = fluid.layers.data(name='x', shape=[10, 5, 3], dtype='float32') x = fluid.layers.data(name='x', shape=[10, 5, 3], dtype='float64')
def test_x_Variable_check(): def test_x_Variable_check():
# the Input(x)'s type must be Variable # the Input(x)'s type must be Variable
......
...@@ -64,19 +64,19 @@ class TestTreeConvOp(OpTest): ...@@ -64,19 +64,19 @@ class TestTreeConvOp(OpTest):
adj = np.tile(adj, (self.batch_size, 1, 1)) adj = np.tile(adj, (self.batch_size, 1, 1))
self.op_type = 'tree_conv' self.op_type = 'tree_conv'
vectors = np.random.random( vectors = np.random.random(
(self.batch_size, self.n, self.fea_size)).astype('float32') (self.batch_size, self.n, self.fea_size)).astype('float64')
self.inputs = { self.inputs = {
'EdgeSet': adj, 'EdgeSet': adj,
'NodesVector': vectors, 'NodesVector': vectors,
'Filter': np.random.random((self.fea_size, 3, self.output_size, 'Filter': np.random.random((self.fea_size, 3, self.output_size,
self.num_filters)).astype('float32') self.num_filters)).astype('float64')
} }
self.attrs = {'max_depth': self.max_depth} self.attrs = {'max_depth': self.max_depth}
vectors = [] vectors = []
for i in range(self.batch_size): for i in range(self.batch_size):
vector = self.get_output_naive(i) vector = self.get_output_naive(i)
vectors.append(vector) vectors.append(vector)
self.outputs = {'Out': np.array(vectors).astype('float32'), } self.outputs = {'Out': np.array(vectors).astype('float64'), }
def test_check_output(self): def test_check_output(self):
self.check_output() self.check_output()
...@@ -91,7 +91,7 @@ class TestTreeConvOp(OpTest): ...@@ -91,7 +91,7 @@ class TestTreeConvOp(OpTest):
for e in st: for e in st:
og[e[0]].append(e[1]) og[e[0]].append(e[1])
patches = collect_node_patch(og, self.max_depth) patches = collect_node_patch(og, self.max_depth)
W = np.array(self.inputs['Filter']).astype('float32') W = np.array(self.inputs['Filter']).astype('float64')
W = np.transpose(W, axes=[1, 0, 2, 3]) W = np.transpose(W, axes=[1, 0, 2, 3])
vec = [] vec = []
for i, patch in enumerate(patches, 1): for i, patch in enumerate(patches, 1):
...@@ -103,7 +103,7 @@ class TestTreeConvOp(OpTest): ...@@ -103,7 +103,7 @@ class TestTreeConvOp(OpTest):
eta_r = (1.0 - eta_t) * (1.0 - eta_l) eta_r = (1.0 - eta_t) * (1.0 - eta_l)
x = self.inputs['NodesVector'][batch_id][v[0] - 1] x = self.inputs['NodesVector'][batch_id][v[0] - 1]
eta = np.array([eta_l, eta_r, eta_t]).reshape( eta = np.array([eta_l, eta_r, eta_t]).reshape(
(3, 1)).astype('float32') (3, 1)).astype('float64')
Wconvi = np.tensordot(eta, W, axes=([0], [0])) Wconvi = np.tensordot(eta, W, axes=([0], [0]))
x = np.array(x).reshape((1, 1, self.fea_size)) x = np.array(x).reshape((1, 1, self.fea_size))
res = np.tensordot(x, Wconvi, axes=2) res = np.tensordot(x, Wconvi, axes=2)
...@@ -114,7 +114,7 @@ class TestTreeConvOp(OpTest): ...@@ -114,7 +114,7 @@ class TestTreeConvOp(OpTest):
[ [
vec, np.zeros( vec, np.zeros(
(self.n - vec.shape[0], W.shape[2], W.shape[3]), (self.n - vec.shape[0], W.shape[2], W.shape[3]),
dtype='float32') dtype='float64')
], ],
axis=0) axis=0)
return vec return vec
...@@ -38,7 +38,7 @@ class TestUnfoldOp(OpTest): ...@@ -38,7 +38,7 @@ class TestUnfoldOp(OpTest):
self.batch_size, self.input_channels, self.input_height, self.batch_size, self.input_channels, self.input_height,
self.input_width self.input_width
] ]
self.x = np.random.rand(*input_shape).astype(np.float32) self.x = np.random.rand(*input_shape).astype(np.float64)
def calc_unfold(self): def calc_unfold(self):
output_shape = [0] * 3 output_shape = [0] * 3
...@@ -52,7 +52,7 @@ class TestUnfoldOp(OpTest): ...@@ -52,7 +52,7 @@ class TestUnfoldOp(OpTest):
out_width = int((self.input_width + self.paddings[1] + self.paddings[3] out_width = int((self.input_width + self.paddings[1] + self.paddings[3]
- dkernel_w) / self.strides[1]) + 1 - dkernel_w) / self.strides[1]) + 1
output_shape[2] = out_height * out_width output_shape[2] = out_height * out_width
output = np.zeros(output_shape).astype(np.float32) output = np.zeros(output_shape).astype(np.float64)
############ calculate output ############## ############ calculate output ##############
for i in range(output_shape[0]): for i in range(output_shape[0]):
for j in range(output_shape[1]): for j in range(output_shape[1]):
......
...@@ -41,7 +41,7 @@ class TestUnpoolOp(OpTest): ...@@ -41,7 +41,7 @@ class TestUnpoolOp(OpTest):
def setUp(self): def setUp(self):
self.op_type = "unpool" self.op_type = "unpool"
self.init_test_case() self.init_test_case()
pre_input = np.random.random(self.shape).astype("float32") pre_input = np.random.random(self.shape).astype("float64")
nsize, csize, hsize, wsize = pre_input.shape nsize, csize, hsize, wsize = pre_input.shape
hsize_out = (hsize - self.ksize[0] + 2 * self.paddings[0]) // \ hsize_out = (hsize - self.ksize[0] + 2 * self.paddings[0]) // \
self.strides[0] + 1 self.strides[0] + 1
...@@ -67,9 +67,9 @@ class TestUnpoolOp(OpTest): ...@@ -67,9 +67,9 @@ class TestUnpoolOp(OpTest):
(r_start + arg // self.ksize[1]) * wsize + \ (r_start + arg // self.ksize[1]) * wsize + \
c_start + arg % self.ksize[1] c_start + arg % self.ksize[1]
output = self.unpool2d_forward_naive(input, indices, self.ksize, \ output = self.unpool2d_forward_naive(input, indices, self.ksize, \
self.strides, self.paddings).astype("float32") self.strides, self.paddings).astype("float64")
self.inputs = { self.inputs = {
'X': input.astype('float32'), 'X': input.astype('float64'),
'Indices': indices.astype('int32') 'Indices': indices.astype('int32')
} }
self.attrs = { self.attrs = {
...@@ -78,7 +78,7 @@ class TestUnpoolOp(OpTest): ...@@ -78,7 +78,7 @@ class TestUnpoolOp(OpTest):
'ksize': self.ksize, 'ksize': self.ksize,
'unpooling_type': self.unpooling_type, 'unpooling_type': self.unpooling_type,
} }
self.outputs = {'Out': output.astype('float32')} self.outputs = {'Out': output.astype('float64')}
def test_check_output(self): def test_check_output(self):
self.check_output() self.check_output()
......
...@@ -25,11 +25,11 @@ class TestUnsqueezeOp(OpTest): ...@@ -25,11 +25,11 @@ class TestUnsqueezeOp(OpTest):
def setUp(self): def setUp(self):
self.init_test_case() self.init_test_case()
self.op_type = "unsqueeze2" self.op_type = "unsqueeze2"
self.inputs = {"X": np.random.random(self.ori_shape).astype("float32")} self.inputs = {"X": np.random.random(self.ori_shape).astype("float64")}
self.init_attrs() self.init_attrs()
self.outputs = { self.outputs = {
"Out": self.inputs["X"].reshape(self.new_shape), "Out": self.inputs["X"].reshape(self.new_shape),
"XShape": np.random.random(self.ori_shape).astype("float32") "XShape": np.random.random(self.ori_shape).astype("float64")
} }
def test_check_output(self): def test_check_output(self):
...@@ -91,13 +91,13 @@ class TestUnsqueezeOp_AxesTensorList(OpTest): ...@@ -91,13 +91,13 @@ class TestUnsqueezeOp_AxesTensorList(OpTest):
(1)).astype('int32') * ele)) (1)).astype('int32') * ele))
self.inputs = { self.inputs = {
"X": np.random.random(self.ori_shape).astype("float32"), "X": np.random.random(self.ori_shape).astype("float64"),
"AxesTensorList": axes_tensor_list "AxesTensorList": axes_tensor_list
} }
self.init_attrs() self.init_attrs()
self.outputs = { self.outputs = {
"Out": self.inputs["X"].reshape(self.new_shape), "Out": self.inputs["X"].reshape(self.new_shape),
"XShape": np.random.random(self.ori_shape).astype("float32") "XShape": np.random.random(self.ori_shape).astype("float64")
} }
def test_check_output(self): def test_check_output(self):
...@@ -150,13 +150,13 @@ class TestUnsqueezeOp_AxesTensor(OpTest): ...@@ -150,13 +150,13 @@ class TestUnsqueezeOp_AxesTensor(OpTest):
self.op_type = "unsqueeze2" self.op_type = "unsqueeze2"
self.inputs = { self.inputs = {
"X": np.random.random(self.ori_shape).astype("float32"), "X": np.random.random(self.ori_shape).astype("float64"),
"AxesTensor": np.array(self.axes).astype("int32") "AxesTensor": np.array(self.axes).astype("int32")
} }
self.init_attrs() self.init_attrs()
self.outputs = { self.outputs = {
"Out": self.inputs["X"].reshape(self.new_shape), "Out": self.inputs["X"].reshape(self.new_shape),
"XShape": np.random.random(self.ori_shape).astype("float32") "XShape": np.random.random(self.ori_shape).astype("float64")
} }
def test_check_output(self): def test_check_output(self):
...@@ -205,8 +205,8 @@ class TestUnsqueezeOp4_AxesTensor(TestUnsqueezeOp_AxesTensor): ...@@ -205,8 +205,8 @@ class TestUnsqueezeOp4_AxesTensor(TestUnsqueezeOp_AxesTensor):
# test api # test api
class TestUnsqueezeAPI(unittest.TestCase): class TestUnsqueezeAPI(unittest.TestCase):
def test_api(self): def test_api(self):
input = np.random.random([3, 2, 5]).astype("float32") input = np.random.random([3, 2, 5]).astype("float64")
x = fluid.data(name='x', shape=[3, 2, 5], dtype="float32") x = fluid.data(name='x', shape=[3, 2, 5], dtype="float64")
positive_3_int32 = fluid.layers.fill_constant([1], "int32", 3) positive_3_int32 = fluid.layers.fill_constant([1], "int32", 3)
positive_1_int64 = fluid.layers.fill_constant([1], "int64", 1) positive_1_int64 = fluid.layers.fill_constant([1], "int64", 1)
axes_tensor_int32 = fluid.data( axes_tensor_int32 = fluid.data(
......
...@@ -25,7 +25,7 @@ class TestUnsqueezeOp(OpTest): ...@@ -25,7 +25,7 @@ class TestUnsqueezeOp(OpTest):
def setUp(self): def setUp(self):
self.init_test_case() self.init_test_case()
self.op_type = "unsqueeze" self.op_type = "unsqueeze"
self.inputs = {"X": np.random.random(self.ori_shape).astype("float32")} self.inputs = {"X": np.random.random(self.ori_shape).astype("float64")}
self.init_attrs() self.init_attrs()
self.outputs = {"Out": self.inputs["X"].reshape(self.new_shape)} self.outputs = {"Out": self.inputs["X"].reshape(self.new_shape)}
......
...@@ -21,7 +21,7 @@ class TestUnStackOpBase(OpTest): ...@@ -21,7 +21,7 @@ class TestUnStackOpBase(OpTest):
def initDefaultParameters(self): def initDefaultParameters(self):
self.input_dim = (5, 6, 7) self.input_dim = (5, 6, 7)
self.axis = 0 self.axis = 0
self.dtype = 'float32' self.dtype = 'float64'
def initParameters(self): def initParameters(self):
pass pass
......
...@@ -79,7 +79,7 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs): ...@@ -79,7 +79,7 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs):
use_label_smooth = attrs['use_label_smooth'] use_label_smooth = attrs['use_label_smooth']
input_size = downsample_ratio * h input_size = downsample_ratio * h
x = x.reshape((n, mask_num, 5 + class_num, h, w)).transpose((0, 1, 3, 4, 2)) x = x.reshape((n, mask_num, 5 + class_num, h, w)).transpose((0, 1, 3, 4, 2))
loss = np.zeros((n)).astype('float32') loss = np.zeros((n)).astype('float64')
smooth_weight = min(1.0 / class_num, 1.0 / 40) smooth_weight = min(1.0 / class_num, 1.0 / 40)
label_pos = 1.0 - smooth_weight if use_label_smooth else 1.0 label_pos = 1.0 - smooth_weight if use_label_smooth else 1.0
...@@ -103,7 +103,7 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs): ...@@ -103,7 +103,7 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs):
pred_box = pred_box.reshape((n, -1, 4)) pred_box = pred_box.reshape((n, -1, 4))
pred_obj = x[:, :, :, :, 4].reshape((n, -1)) pred_obj = x[:, :, :, :, 4].reshape((n, -1))
objness = np.zeros(pred_box.shape[:2]).astype('float32') objness = np.zeros(pred_box.shape[:2]).astype('float64')
ious = batch_xywh_box_iou(pred_box, gtbox) ious = batch_xywh_box_iou(pred_box, gtbox)
ious_max = np.max(ious, axis=-1) ious_max = np.max(ious, axis=-1)
objness = np.where(ious_max > ignore_thresh, -np.ones_like(objness), objness = np.where(ious_max > ignore_thresh, -np.ones_like(objness),
...@@ -158,7 +158,7 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs): ...@@ -158,7 +158,7 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs):
elif objness[i, j] == 0: elif objness[i, j] == 0:
loss[i] += sce(pred_obj[i, j], 0.0) loss[i] += sce(pred_obj[i, j], 0.0)
return (loss, objness.reshape((n, mask_num, h, w)).astype('float32'), \ return (loss, objness.reshape((n, mask_num, h, w)).astype('float64'), \
gt_matches.astype('int32')) gt_matches.astype('int32'))
...@@ -166,8 +166,8 @@ class TestYolov3LossOp(OpTest): ...@@ -166,8 +166,8 @@ class TestYolov3LossOp(OpTest):
def setUp(self): def setUp(self):
self.initTestCase() self.initTestCase()
self.op_type = 'yolov3_loss' self.op_type = 'yolov3_loss'
x = logit(np.random.uniform(0, 1, self.x_shape).astype('float32')) x = logit(np.random.uniform(0, 1, self.x_shape).astype('float64'))
gtbox = np.random.random(size=self.gtbox_shape).astype('float32') gtbox = np.random.random(size=self.gtbox_shape).astype('float64')
gtlabel = np.random.randint(0, self.class_num, self.gtbox_shape[:2]) gtlabel = np.random.randint(0, self.class_num, self.gtbox_shape[:2])
gtmask = np.random.randint(0, 2, self.gtbox_shape[:2]) gtmask = np.random.randint(0, 2, self.gtbox_shape[:2])
gtbox = gtbox * gtmask[:, :, np.newaxis] gtbox = gtbox * gtmask[:, :, np.newaxis]
...@@ -184,13 +184,13 @@ class TestYolov3LossOp(OpTest): ...@@ -184,13 +184,13 @@ class TestYolov3LossOp(OpTest):
self.inputs = { self.inputs = {
'X': x, 'X': x,
'GTBox': gtbox.astype('float32'), 'GTBox': gtbox.astype('float64'),
'GTLabel': gtlabel.astype('int32'), 'GTLabel': gtlabel.astype('int32'),
} }
gtscore = np.ones(self.gtbox_shape[:2]).astype('float32') gtscore = np.ones(self.gtbox_shape[:2]).astype('float64')
if self.gtscore: if self.gtscore:
gtscore = np.random.random(self.gtbox_shape[:2]).astype('float32') gtscore = np.random.random(self.gtbox_shape[:2]).astype('float64')
self.inputs['GTScore'] = gtscore self.inputs['GTScore'] = gtscore
loss, objness, gt_matches = YOLOv3Loss(x, gtbox, gtlabel, gtscore, loss, objness, gt_matches = YOLOv3Loss(x, gtbox, gtlabel, gtscore,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册