/* 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. */ #pragma once #include #include "common/log.h" #include "framework/executor.h" #include "io.h" #include "operators/conv_op.h" #include "operators/pool_op.h" #include "operators/softmax_op.h" using paddle_mobile::Executor; using paddle_mobile::framework::BlockDesc; using paddle_mobile::framework::DDim; using paddle_mobile::framework::LoDTensor; using paddle_mobile::framework::OpDesc; using paddle_mobile::framework::Program; using paddle_mobile::framework::Tensor; using paddle_mobile::framework::Variable; using std::string; template class Executor4Test : public Executor { public: Executor4Test(Program p, string op_type) : Executor(p) { if (this->program_.originProgram == nullptr) { LOG(paddle_mobile::LogLevel::kLOG_ERROR) << "to_predict_program_ == nullptr"; } const std::vector> blocks = this->to_predict_program_->Blocks(); for (std::shared_ptr block_desc : blocks) { std::vector> ops = block_desc->Ops(); for (std::shared_ptr op : ops) { if (op->Type() == op_type) { std::shared_ptr op_ptr = std::make_shared( op->Type(), op->GetInputs(), op->GetOutputs(), op->GetAttrMap(), this->program_.scope); this->ops_of_block_[*block_desc.get()].push_back(op_ptr); break; } } } } std::shared_ptr predict(const Tensor &t, string input, string output, const DDim &dDim) { auto scope = this->program_.scope; Variable *g_feed_value = scope->Var(input); auto tensor = g_feed_value->GetMutable(); tensor->ShareDataWith(t); Variable *con_output = scope->Var(output); auto *output_tensor = con_output->GetMutable(); output_tensor->mutable_data(dDim); std::shared_ptr out_tensor = std::make_shared(); out_tensor.reset(output_tensor); Executor::predict(t, 0); return out_tensor; } };