Skip to content

Commit 7c42e5d

Browse files
JiayiFengreyoung
authored andcommitted
Polish RandomCropOp
1 parent 632108d commit 7c42e5d

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

paddle/fluid/operators/random_crop_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ namespace ops = paddle::operators;
7474
namespace f = paddle::framework;
7575
REGISTER_OPERATOR(random_crop, ops::RandomCropOp, ops::RandomCropOpMaker,
7676
ops::RandomCropOpInferShape, f::EmptyGradOpMaker);
77+
7778
template <typename T>
7879
using Kernel = ops::RandomCropKernel<paddle::platform::CPUDeviceContext, T>;
79-
8080
REGISTER_OP_CPU_KERNEL(random_crop, Kernel<float>, Kernel<int>, Kernel<double>,
8181
Kernel<uint8_t>, Kernel<int16_t>);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "paddle/fluid/operators/random_crop_op.h"
16+
17+
template <typename T>
18+
using Kernel = ops::RandomCropKernel<paddle::platform::CUDADeviceContext, T>;
19+
REGISTER_OP_CUDA_KERNEL(random_crop, Kernel<float>, Kernel<int>, Kernel<double>,
20+
Kernel<uint8_t>, Kernel<int16_t>);

python/paddle/fluid/layers/nn.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,15 +3990,16 @@ def _is_list_or_turple_(data):
39903990
return out
39913991

39923992

3993-
def random_crop(input, shape, seed=0):
3993+
def random_crop(input, shape, seed=1):
39943994
helper = LayerHelper("random_crop", **locals())
39953995
dtype = helper.input_dtype()
39963996
out = helper.create_tmp_variable(dtype)
39973997
if isinstance(seed, int):
3998+
seed_value = seed
39983999
seed = helper.create_global_variable(
39994000
persistable=True, shape=[1], dtype="int32")
40004001
helper.set_variable_initializer(
4001-
var=seed, initializer=Constant(value=seed))
4002+
var=seed, initializer=Constant(value=seed_value))
40024003
elif not isinstance(seed, Variable):
40034004
raise ValueError("'seed' must be a Variable or an int.")
40044005
seed_out = helper.create_tmp_variable(dtype="int32")

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@ 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()
341339
self.assertTrue(
342340
np.allclose(
343341
actual_t, expect_t, atol=atol),

0 commit comments

Comments
 (0)