diff --git a/src/framework/operator.h b/src/framework/operator.h index 9e1c077fe350b7b203100a279ec1d01fe8d38caf..5a40a9266309845e2ad1950b227fe44863d8053e 100644 --- a/src/framework/operator.h +++ b/src/framework/operator.h @@ -58,6 +58,7 @@ class OperatorBase : PaddleMobileObject { std::shared_ptr scope); virtual ~OperatorBase() {} virtual void Run() const = 0; + virtual void InferShape() const = 0; const VariableNameMap &Inputs() const { return inputs_; } const VariableNameMap &Outputs() const { return outputs_; } @@ -87,8 +88,8 @@ class OperatorWithKernel : public OperatorBase { const VariableNameMap &outputs, const AttributeMap &attrs, std::shared_ptr scope) : OperatorBase(type, inputs, outputs, attrs, scope) {} - virtual void InferShape() const = 0; virtual void Run() const = 0; + virtual void InferShape() const = 0; }; template diff --git a/src/framework/scope.cpp b/src/framework/scope.cpp index ba5da674a45badff18966a91e070df324e9a8352..c5ee2d39fa7a7bf4c1c7b1c2f3fb8f1e92f4e455 100644 --- a/src/framework/scope.cpp +++ b/src/framework/scope.cpp @@ -34,19 +34,10 @@ Variable *Scope::Var(const std::string &name) { } pvar = new Variable; vars_[name] = pvar; - pvar->name_ = &(vars_.find(name)->first); + pvar->name_ = vars_.find(name)->first; return pvar; } -// Variable* Scope::Var(std::string* name) { -// auto var_name = string::Sprintf("%p.%d", this, -// vars_.size()); -// if (name != nullptr) { -// *name = var_name; -// } -// return Var(var_name); -// } - Variable *Scope::FindVar(const std::string &name) const { auto *pvar = FindVarLocally(name); if (pvar != nullptr) { diff --git a/src/framework/tensor.h b/src/framework/tensor.h index 203cf24e5f12fc2a9917e246db2364389c8e20b4..7fdb52c435c64e3365d028e843969f7a648ba604 100644 --- a/src/framework/tensor.h +++ b/src/framework/tensor.h @@ -14,6 +14,7 @@ limitations under the License. */ #pragma once +#include #include #include #include @@ -217,18 +218,14 @@ class Tensor { } inline void check_memory_size() const { - // PADDLE_ENFORCE_NOT_NULL( - // holder_, "Tensor holds no memory. Call - // Tensor::mutable_data - // first."); - // PADDLE_ENFORCE_LE( - // numel() * SizeOfType(type()), memory_size(), - // "Tensor's dims_ is out of bound. Call - // Tensor::mutable_data " - // "first to re-allocate memory.\n" - // "or maybe the required data-type mismatches the data - // already - // stored."); + PADDLE_MOBILE_ENFORCE( + holder_, "Tensor holds no memory. Call Tensor::mutable_data first."); + PADDLE_MOBILE_ENFORCE( + numel() * SizeOfType(type()) <= memory_size(), + "Tensor's dims_ is out of bound. CallTensor::mutable_data " + "first to re-allocate memory.\n" + "or maybe the required data-type mismatches the data\ + already stored."); } inline DataLayout layout() const { return layout_; } diff --git a/src/framework/variable.h b/src/framework/variable.h index 1ab824bab3114f0d29ed218551ad01887aabada5..3d8dd5158046f58dd4d206427328867140e95344 100644 --- a/src/framework/variable.h +++ b/src/framework/variable.h @@ -19,10 +19,13 @@ limitations under the License. */ #include #include #include +#include "../common/variant.h" #include "paddle_mobile_object.h" namespace paddle_mobile { namespace framework { +using std::string; + class Variable : public PaddleMobileObject { public: template @@ -30,17 +33,23 @@ class Variable : public PaddleMobileObject { return static_cast(holder_->Ptr()); } + template + const T GetValue() const { + return variant.Get(); + } + + template + void SetValue(T value) { + variant.Set(value); + } + bool IsInitialized() const { return holder_ != nullptr; } - const std::string *Name() { return name_; } + const std::string Name() { return name_; } template T *GetMutable() { if (!IsType()) { - if (*Name() == "pixel") { - // std::cout << " reset " << *Name() << - // std::endl; - } holder_.reset(new PlaceholderImp(new T())); } return static_cast(holder_->Ptr()); @@ -48,15 +57,6 @@ class Variable : public PaddleMobileObject { template bool IsType() const { - if (holder_) { - // printf("not null \n"); - printf(" holder type : %s, this type %s \n", holder_->Type().name(), - typeid(T).name()); - } - - // std::cout << " " << holder_->Type() << " " << - // typeid(T) << - // std::endl; return holder_ != nullptr && holder_->Type() == typeid(T); } @@ -64,7 +64,7 @@ class Variable : public PaddleMobileObject { std::type_index Type() const { return holder_->Type(); } - void SetName(const std::string *name) { name_ = name; } + void SetName(const string name) { name_ = name; } private: struct Placeholder { @@ -87,10 +87,10 @@ class Variable : public PaddleMobileObject { std::unique_ptr ptr_; const std::type_info &type_; }; - + Variant variant; std::unique_ptr holder_; friend class Scope; - const std::string *name_; + string name_; }; } // namespace framework } // namespace paddle_mobile diff --git a/src/io.cpp b/src/io.cpp index fbf5798fa297622f6963d4352d65ca16ae54d5df..f03e9a56e2db258b23e3db0f348e9956cb580e46 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -27,6 +27,7 @@ limitations under the License. */ #include "framework/tensor.h" namespace paddle_mobile { +using framework::Variable; void ReadBinaryFile(const std::string &filename, std::string *contents) { std::ifstream fin(filename, std::ios::in | std::ios::binary); @@ -204,10 +205,12 @@ const framework::Program Loader::Load( var_desc->Type() != framework::VARTYPE_TYPE_FEED_MINIBATCH && var_desc->Type() != framework::VARTYPE_TYPE_FETCH_LIST) { // DLOG << "to load var "; - LoadVar(var, *var_desc, dirname + "/" + var_desc->Name()); + auto dim = var_desc->Tensor_desc().Dims(); + auto tensor = var->GetMutable(); + tensor->Resize(framework::make_ddim(dim)); } else { auto dim = var_desc->Tensor_desc().Dims(); - PADDLE_MOBILE_ENFORCE(dim.size() > 0, "dim size is 0"); + PADDLE_MOBILE_ENFORCE(dim.size() > 1, "dim size is 0"); dim[0] = 1; auto tensor = var->GetMutable(); tensor->Resize(framework::make_ddim(dim)); @@ -243,11 +246,39 @@ Executor::Executor(const framework::Program p) : program_(p) { std::vector> ops = block_desc->Ops(); for (int j = 0; j < ops.size(); ++j) { std::shared_ptr op = ops[j]; - // auto op_base = - // framework::OpRegistry::CreateOp(op->Type(), - // op->GetInputs(), op->GetOutputs(), - // op->GetAttrMap(), program_.scope); - // op_base->InferShape(); + auto op_base = framework::OpRegistry::CreateOp( + op->Type(), op->GetInputs(), op->GetOutputs(), op->GetAttrMap(), + program_.scope); + op_base->InferShape(); + ops_of_block_[*block_desc.get()].push_back(op_base); + } + } + InitMemory(); +} + +template +Executor::Executor(const framework::Program p, int batch_size) + : program_(p), batch_size_(batch_size) { + if (use_optimize_) { + to_predict_program_ = program_.optimizeProgram; + } else { + to_predict_program_ = program_.originProgram; + } + Variable *variable_ptr = program_.scope->Var("batch_size"); + variable_ptr[0].SetValue(batch_size); + const std::vector> blocks = + to_predict_program_->Blocks(); + for (int i = 0; i < blocks.size(); ++i) { + std::shared_ptr block_desc = blocks[i]; + std::vector> ops = block_desc->Ops(); + for (int j = 0; j < ops.size(); ++j) { + std::shared_ptr op = ops[j]; + auto op_base = framework::OpRegistry::CreateOp( + op->Type(), op->GetInputs(), op->GetOutputs(), op->GetAttrMap(), + program_.scope); + op_base->InferShape(); + + ops_of_block_[*block_desc.get()].push_back(op_base); } } InitMemory(); @@ -342,6 +373,9 @@ void Executor::InitMemory() { auto var = program_.scope->Var(var_desc->Name()); if (var_desc->Persistable()) { auto tensor = var->template GetMutable(); + if (var_desc->Name() == "feed" || var_desc->Name() == "fetch") { + continue; + } LoadMemory(*var_desc, tensor, program_.model_path + "/" + var_desc->Name()); } else { @@ -381,9 +415,11 @@ std::shared_ptr Executor::predict( template void Executor::predict(const framework::Tensor &t, int block_id) { - // framework::Variable *g_feed_value = program_.scope->Var("feed"); - // auto feed_tensor = g_feed_value->GetMutable(); - // feed_tensor->ShareDataWith(t); + framework::Variable *g_feed_value = program_.scope->Var("feed"); + auto feed_tensor = g_feed_value->GetMutable(); + feed_tensor->Resize(t.dims()); + + feed_tensor->ShareDataWith(t); std::shared_ptr to_predict_block = to_predict_program_->Block(block_id); diff --git a/src/io.h b/src/io.h index d0ed5e67526d65e3d7d1a8f7ba72e9b2f7730a42..678441a9e05dacf4e1f6a41705c1499c3ea99238 100644 --- a/src/io.h +++ b/src/io.h @@ -47,6 +47,8 @@ class Executor { Executor(const framework::Program p); + Executor(const framework::Program p, int batch_size); + std::shared_ptr predict(framework::Tensor &t); std::vector predict(const std::vector &input, @@ -57,6 +59,7 @@ class Executor { void LoadMemory(const framework::VarDesc var_desc, framework::LoDTensor *tensor, const std::string &file_path); framework::Program program_; + int batch_size_ = 1; std::shared_ptr to_predict_program_; void predict(const framework::Tensor &t, int block_id); std::map::InferShape() const { std::vector dilations = param_.Dilations(); + PADDLE_MOBILE_ENFORCE((in_dims.size() == filter_dims.size() && + dilations.size() == paddings.size() && + paddings.size() == strides.size()), + "ConvParam is not suitable"); + std::vector output_shape({in_dims[0], filter_dims[0]}); for (size_t i = 0; i < strides.size(); ++i) { output_shape.push_back(ConvOutputSize(in_dims[i + 2], filter_dims[i + 2], diff --git a/src/operators/feed_op.cpp b/src/operators/feed_op.cpp index 72f64e85b0c268f7f09a89c10bbc53b54dc11e1f..a40eac098c7bef442befa1758b21904269cc22d5 100644 --- a/src/operators/feed_op.cpp +++ b/src/operators/feed_op.cpp @@ -13,3 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "feed_op.h" +namespace paddle_mobile { +namespace operators { + +template class FeedOp; +} +} // namespace paddle_mobile diff --git a/src/operators/feed_op.h b/src/operators/feed_op.h index 45d26b9fde2b95345f24ec90d387cc32e5768d07..426d5f6220db4e5ee05465288ab3b2f76735da52 100644 --- a/src/operators/feed_op.h +++ b/src/operators/feed_op.h @@ -21,7 +21,7 @@ namespace paddle_mobile { namespace operators { template -class FeedOp : framework::OperatorBase { +class FeedOp : public framework::OperatorBase { public: FeedOp(const std::string &type, const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap attrs, @@ -32,8 +32,9 @@ class FeedOp : framework::OperatorBase { void Run() const { param_.Out()->ShareDataWith(*param_.InputX()); } void InferShape() const { - auto x_dims = param_.InputX()->dims(); - param_.Out()->Resize(x_dims); + auto out_dims = param_.Out()->dims(); + out_dims[0] = param_.BatchSize(); + param_.Out()->Resize(out_dims); } protected: @@ -41,8 +42,8 @@ class FeedOp : framework::OperatorBase { }; namespace ops = paddle_mobile::operators; -// USE_OP(Feed); -// REGISTER_OPERATOR(Feed, ops::FeedOp); +USE_OP(feed); +REGISTER_OPERATOR(feed, ops::FeedOp); } // namespace operators } // namespace paddle_mobile diff --git a/src/operators/fetch_op.cpp b/src/operators/fetch_op.cpp index 67e0c9c7a27047c2d4a833ab2b3a7b02cb90b7d5..45d6afc07b597156a746b7cd6657c3b58f1b9950 100644 --- a/src/operators/fetch_op.cpp +++ b/src/operators/fetch_op.cpp @@ -12,8 +12,10 @@ 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. */ -// -// Created by liuRuiLong on 2018/5/25. -// - #include "fetch_op.h" +namespace paddle_mobile { +namespace operators { + +template class FetchOp; +} +} // namespace paddle_mobile diff --git a/src/operators/fetch_op.h b/src/operators/fetch_op.h index 40b2bbfa13339bde1fe6b08c78125355d68a1889..7dddd67992990c67ebb73172ac516cb0c0d525d3 100644 --- a/src/operators/fetch_op.h +++ b/src/operators/fetch_op.h @@ -21,7 +21,7 @@ namespace paddle_mobile { namespace operators { template -class FetchOp : framework::OperatorBase { +class FetchOp : public framework::OperatorBase { public: FetchOp(const std::string &type, const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap attrs, @@ -29,7 +29,12 @@ class FetchOp : framework::OperatorBase { : framework::OperatorBase(type, inputs, outputs, attrs, scope), param_(inputs, outputs, attrs, *scope) {} - void Run() const { param_.Out()->ShareDataWith(*param_.InputX()); } + void Run() const { + param_.Out()->ShareDataWith(*param_.InputX()); + for (int i = 0; i < param_.Out()->numel(); ++i) { + DLOG << param_.Out()->template data()[i]; + } + } void InferShape() const { auto x_dims = param_.InputX()->dims(); @@ -41,8 +46,8 @@ class FetchOp : framework::OperatorBase { }; namespace ops = paddle_mobile::operators; -// USE_OP(Fetch); -// REGISTER_OPERATOR(Fetch, ops::FetchOp); +USE_OP(fetch); +REGISTER_OPERATOR(fetch, ops::FetchOp); } // namespace operators } // namespace paddle_mobile diff --git a/src/operators/op_param.h b/src/operators/op_param.h index 315ee92ccff5b0887e98d67cffe0d46f2110da1b..5ac6fc67af584331a1c28a8ce9a5578f4eb55cd4 100644 --- a/src/operators/op_param.h +++ b/src/operators/op_param.h @@ -197,8 +197,8 @@ class ConvParam : OpParam { const framework::AttributeMap &attrs, const framework::Scope &scope) { filter_ = FilterFrom(inputs, scope); - input_ = InputFrom(inputs, scope); - output_ = OutputFrom(outputs, scope); + input_ = InputFrom(inputs, scope); + output_ = OutputFrom(outputs, scope); strides_ = GetAttr>("strides", attrs); paddings_ = GetAttr>("paddings", attrs); dilations_ = GetAttr>("dilations", attrs); @@ -237,9 +237,9 @@ class ElementwiseAddParam : OpParam { const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - input_y_ = InputYFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + input_y_ = InputYFrom(inputs, scope); + out_ = OutFrom(outputs, scope); axis_ = GetAttr("axis", attrs); } @@ -263,9 +263,9 @@ class MulParam : OpParam { MulParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - input_y_ = InputYFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + input_y_ = InputYFrom(inputs, scope); + out_ = OutFrom(outputs, scope); x_num_col_dims_ = GetAttr("x_num_col_dims", attrs); y_num_col_dims_ = GetAttr("y_num_col_dims", attrs); } @@ -293,19 +293,19 @@ class ConcatParam : public OpParam { ConcatParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - inputs_ = InputMultiFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + inputs_ = InputMultiFrom(inputs, scope); + out_ = OutFrom(outputs, scope); axis_ = GetAttr("axis", attrs); } - vector Inputs() const { return inputs_; } + vector Inputs() const { return inputs_; } Tensor *Out() const { return out_; } const int &Axis() const { return axis_; } private: - vector inputs_; + vector inputs_; Tensor *out_; int axis_; }; @@ -315,9 +315,9 @@ class LrnParam : public OpParam { LrnParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - out_ = OutFrom(outputs, scope); - mid_out_ = MidOutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); + mid_out_ = MidOutFrom(outputs, scope); n_ = GetAttr("n", attrs); alpha_ = GetAttr("alpha", attrs); beta_ = GetAttr("beta", attrs); @@ -356,12 +356,12 @@ class BatchNormParam : OpParam { BatchNormParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - output_y_ = OutputYFrom(outputs, scope); - input_bias_ = InputBiasFrom(inputs, scope); - input_mean_ = InputMeanFrom(inputs, scope); - input_scale_ = InputScaleFrom(inputs, scope); - input_variance_ = InputVarianceFrom(inputs, scope); + input_x_ = InputXFrom(inputs, scope); + output_y_ = OutputYFrom(outputs, scope); + input_bias_ = InputBiasFrom(inputs, scope); + input_mean_ = InputMeanFrom(inputs, scope); + input_scale_ = InputScaleFrom(inputs, scope); + input_variance_ = InputVarianceFrom(inputs, scope); epsilon_ = GetAttr("epsilon", attrs); momentum_ = GetAttr("momentum", attrs); is_test_ = GetAttr("is_test", attrs); @@ -404,9 +404,9 @@ class PoolParam : public OpParam { PoolParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_ = InputXFrom(inputs, scope); + input_ = InputXFrom(inputs, scope); - output_ = OutFrom(outputs, scope); + output_ = OutFrom(outputs, scope); pooling_type_ = GetAttr("pooling_type", attrs); ksize_ = GetAttr>("ksize", attrs); strides_ = GetAttr>("strides", attrs); @@ -447,10 +447,11 @@ class PriorBoxParam : public OpParam { PriorBoxParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_ = InputFrom(inputs, scope); - input_image_ = InputImageFrom(inputs, scope); - output_boxes_ = OutputBoxesFrom(outputs, scope); - output_variances_ = OutputVariancesFrom(outputs, scope); + input_ = InputFrom(inputs, scope); + input_image_ = InputImageFrom(inputs, scope); + output_boxes_ = OutputBoxesFrom(outputs, scope); + output_variances_ = + OutputVariancesFrom(outputs, scope); min_sizes_ = GetAttr>("min_sizes", attrs); max_sizes_ = GetAttr>("max_sizes", attrs); aspect_ratios_ = GetAttr>("aspect_ratios", attrs); @@ -508,10 +509,11 @@ class BoxCoderParam : public OpParam { BoxCoderParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_priorbox_ = InputPriorBoxFrom(inputs, scope); - input_priorboxvar_ = InputPriorBoxVarFrom(inputs, scope); - input_targetbox_ = InputTargetBoxFrom(inputs, scope); - output_box_ = OutputBoxFrom(outputs, scope); + input_priorbox_ = InputPriorBoxFrom(inputs, scope); + input_priorboxvar_ = + InputPriorBoxVarFrom(inputs, scope); + input_targetbox_ = InputTargetBoxFrom(inputs, scope); + output_box_ = OutputBoxFrom(outputs, scope); code_type_ = GetAttr("code_type", attrs); } const Tensor *InputPriorBox() const { return input_priorbox_; } @@ -537,8 +539,8 @@ class SoftmaxParam : public OpParam { SoftmaxParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); } const Tensor *InputX() const { return input_x_; } Tensor *Out() const { return out_; } @@ -553,8 +555,8 @@ class SigmoidParam : public OpParam { SigmoidParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); } const Tensor *InputX() const { return input_x_; } Tensor *Out() const { return out_; } @@ -568,9 +570,9 @@ class MultiClassNMSParam : public OpParam { MultiClassNMSParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const AttributeMap &attrs, const Scope &scope) { - input_bboxes_ = InputBBoxesFrom(inputs, scope); - input_scores_ = InputScoresFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_bboxes_ = InputBBoxesFrom(inputs, scope); + input_scores_ = InputScoresFrom(inputs, scope); + out_ = OutFrom(outputs, scope); background_label_ = GetAttr("background_label", attrs); nms_top_k_ = GetAttr("nms_top_k", attrs); keep_top_k_ = GetAttr("keep_top_k", attrs); @@ -612,17 +614,20 @@ class MultiClassNMSParam : public OpParam { class FeedParam : public OpParam { public: FeedParam(const VariableNameMap &inputs, const VariableNameMap &outputs, - const framework::AttributeMap &attrs, - const framework::Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + const framework::AttributeMap &attrs, framework::Scope &scope) { + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); + auto var = scope.Var("batch_size"); + batch_size = var->GetValue(); } const Tensor *InputX() const { return input_x_; } Tensor *Out() const { return out_; } + const int BatchSize() const { return batch_size; } private: Tensor *input_x_; Tensor *out_; + int batch_size; }; class FetchParam : public OpParam { @@ -630,8 +635,8 @@ class FetchParam : public OpParam { FetchParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const framework::AttributeMap &attrs, const framework::Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); } const Tensor *InputX() const { return input_x_; } Tensor *Out() const { return out_; } @@ -645,8 +650,8 @@ class TransposeParam : public OpParam { public: TransposeParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const AttributeMap &attrs, const Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); axis_ = GetAttr>("axis", attrs); } @@ -666,9 +671,9 @@ class ReshapeParam : public OpParam { public: ReshapeParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const AttributeMap &attrs, const Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - input_shape_ = InputShapeFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + input_shape_ = InputShapeFrom(inputs, scope); + out_ = OutFrom(outputs, scope); shape_ = GetAttr>("shape", attrs); inplace_ = GetAttr("inplace", attrs); } @@ -695,8 +700,8 @@ class ReluParam : public OpParam { public: ReluParam(const VariableNameMap &inputs, const VariableNameMap &outputs, const AttributeMap &attrs, const Scope &scope) { - input_x_ = InputXFrom(inputs, scope); - out_ = OutFrom(outputs, scope); + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); } const Tensor *InputX() const { return input_x_; } diff --git a/src/operators/pool_op.cpp b/src/operators/pool_op.cpp index a8521e0e735bf7a0c733922cd523968009f2765b..3096199dc3e3157f9fa0048ad35f796e24113f28 100644 --- a/src/operators/pool_op.cpp +++ b/src/operators/pool_op.cpp @@ -49,7 +49,6 @@ void PoolOp::InferShape() const { paddings[i], strides[i], ceil_mode)); } param_.Output()->Resize(framework::make_ddim(output_shape)); - DLOG << "infer shape out size =" << param_.Output()->numel(); } template class PoolOp; } // namespace operators diff --git a/test/net/test_googlenet.cpp b/test/net/test_googlenet.cpp index b62f9ea35cc3d0fc1bed57d0604cab084e0ade3d..ee03ed0b146da6312337d6961803534358a6fe2e 100644 --- a/test/net/test_googlenet.cpp +++ b/test/net/test_googlenet.cpp @@ -24,7 +24,7 @@ int main() { // ../../../test/models/mobilenet auto program = loader.Load(std::string("../models/googlenet")); - paddle_mobile::Executor executor(program); + paddle_mobile::Executor executor(program, 1); std::vector input; std::vector dims{1, 3, 224, 224};