Skip to content

Commit d44dbc4

Browse files
committed
fix errors
1 parent 3e7ce58 commit d44dbc4

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

paddle/fluid/operators/random_crop_op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct RandomCropFunctor {
129129
for (int i = num_batchsize_dims_; i < rank_; ++i) {
130130
typename Random<DeviceContext>::template UniformIntDist<size_t> dist(
131131
0, x_dims_[i] - out_dims_[i]);
132-
offsets[i] = dist(engine);
132+
offsets[i - num_batchsize_dims_] = dist(engine);
133133
}
134134

135135
const T* x = x_ + ins_idx * prod_x_ins_dims_;

python/paddle/fluid/tests/unittests/op_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ def find_actual(target_name, fetch_list):
336336
actual_t = np.array(actual)
337337
expect = self.outputs[out_name]
338338
expect_t = expect[0] if isinstance(expect, tuple) else expect
339+
import pdb
340+
pdb.set_trace()
339341
self.assertTrue(
340342
np.allclose(
341343
actual_t, expect_t, atol=atol),

python/paddle/fluid/tests/unittests/test_random_crop_op.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,26 @@
2020

2121
class TestRandomCropOp(OpTest):
2222
def setUp(self):
23-
to_crop = np.random.random((1, 10, 15)).astype("float32")
23+
to_crop = np.array([[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]] *
24+
5).astype("float32")
25+
self.possible_res = [
26+
np.array([[1, 2, 3], [5, 6, 7]]), np.array([[2, 3, 4], [6, 7, 8]]),
27+
np.array([[5, 6, 7], [9, 10, 11]]),
28+
np.array([[6, 7, 8], [10, 11, 12]])
29+
]
2430
self.op_type = "random_crop"
2531
self.inputs = {'X': to_crop, 'Seed': np.array([10])}
26-
self.outputs = {'Out': np.array([1, 2, 3]), 'SeedOut': np.array([2])}
27-
self.attrs = {'shape': [5, 5]}
32+
self.outputs = {'Out': np.array([]), 'SeedOut': np.array([])}
33+
self.attrs = {'shape': [2, 3]}
2834

2935
def test_check_output(self):
30-
self.check_output()
36+
self.check_output_customized(self.verify_output)
37+
38+
def verify_output(self, outs):
39+
out = np.array(outs[1])
40+
for ins in out[:]:
41+
is_equal = [(ins == res).all() for res in self.possible_res]
42+
self.assertIn(True, is_equal)
3143

3244

3345
if __name__ == "__main__":

0 commit comments

Comments
 (0)