diff --git a/paddle/fluid/operators/random_crop_op.cc b/paddle/fluid/operators/random_crop_op.cc index d92b8bbbb58f25513489967f9739caeafc29db6a..b14b559e31dd422f8ebe4002988a9746dfdf28a2 100644 --- a/paddle/fluid/operators/random_crop_op.cc +++ b/paddle/fluid/operators/random_crop_op.cc @@ -74,8 +74,8 @@ namespace ops = paddle::operators; namespace f = paddle::framework; REGISTER_OPERATOR(random_crop, ops::RandomCropOp, ops::RandomCropOpMaker, ops::RandomCropOpInferShape, f::EmptyGradOpMaker); + template using Kernel = ops::RandomCropKernel; - REGISTER_OP_CPU_KERNEL(random_crop, Kernel, Kernel, Kernel, Kernel, Kernel); diff --git a/paddle/fluid/operators/random_crop_op.cu b/paddle/fluid/operators/random_crop_op.cu new file mode 100644 index 0000000000000000000000000000000000000000..2782911b4fefc6f7cd37abc6df79a03803c8d07b --- /dev/null +++ b/paddle/fluid/operators/random_crop_op.cu @@ -0,0 +1,20 @@ +// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "paddle/fluid/operators/random_crop_op.h" + +template +using Kernel = ops::RandomCropKernel; +REGISTER_OP_CUDA_KERNEL(random_crop, Kernel, Kernel, Kernel, + Kernel, Kernel); diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index c337e0f4f202959688ba992e60370eae1e572c2f..3f04dcccd6aa29ec8d5cd445320356cfa3d5db2d 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -3990,15 +3990,16 @@ def upsampling_bilinear2d(input, out_shape=None, scale=None, name=None): return out -def random_crop(input, shape, seed=0): +def random_crop(input, shape, seed=1): helper = LayerHelper("random_crop", **locals()) dtype = helper.input_dtype() out = helper.create_tmp_variable(dtype) if isinstance(seed, int): + seed_value = seed seed = helper.create_global_variable( persistable=True, shape=[1], dtype="int32") helper.set_variable_initializer( - var=seed, initializer=Constant(value=seed)) + var=seed, initializer=Constant(value=seed_value)) elif not isinstance(seed, Variable): raise ValueError("'seed' must be a Variable or an int.") seed_out = helper.create_tmp_variable(dtype="int32") diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index b7e62533b33f26456324a9c62d9fd1e324126525..b611470fa1ff326df960c349b71006f52d586d8e 100644 --- a/python/paddle/fluid/tests/unittests/op_test.py +++ b/python/paddle/fluid/tests/unittests/op_test.py @@ -336,8 +336,6 @@ class OpTest(unittest.TestCase): actual_t = np.array(actual) expect = self.outputs[out_name] expect_t = expect[0] if isinstance(expect, tuple) else expect - import pdb - pdb.set_trace() self.assertTrue( np.allclose( actual_t, expect_t, atol=atol),