diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index d70f26026c28867e592a9f8e37cc53e6c1d6d85e..30f784598a897518a8ce3b7a9c65d3330bb93f37 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -466,6 +466,7 @@ class RuntimeInferShapeContext : public InferShapeContext { protected: DDim GetDim(const std::string& name) const override { Variable* var = scope_.FindVar(name); + PADDLE_ENFORCE_NOT_NULL(var); if (var->IsType()) { return var->Get().dims(); } else if (var->IsType()) { diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 3f04dcccd6aa29ec8d5cd445320356cfa3d5db2d..ec95efd699b12d6226fe3add35da7f94756649f9 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -3996,13 +3996,19 @@ def random_crop(input, shape, seed=1): 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_value)) + seed = helper.create_tmp_variable(dtype="int64") + helper.append_op( + type="fill_constant", + inputs={}, + outputs={"Out": seed}, + attrs={ + "dtype": seed.dtype, + "shape": [1], + "value": float(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") + seed_out = helper.create_tmp_variable(dtype="int64") helper.append_op( type="random_crop", inputs={"X": input,