From 3bce3dbce14a0ec4f65f54ed73cd268e3f5964ce Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Wed, 30 May 2018 15:13:38 +0800 Subject: [PATCH] fix a bug --- paddle/fluid/framework/operator.cc | 1 + python/paddle/fluid/layers/nn.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index d70f26026c2..30f784598a8 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 3f04dcccd6a..ec95efd699b 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, -- GitLab