forked from huawei/mindspore2022
make external nodeparser lightweight and add nodeparser ut
This commit is contained in:
parent
9bcacc6e23
commit
1615e4907f
|
|
@ -22,10 +22,25 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include "include/registry/parser_context.h"
|
||||
#include "proto/onnx.pb.h"
|
||||
#include "proto/caffe.pb.h"
|
||||
#include "proto/graph.pb.h"
|
||||
#include "schema/schema_generated.h"
|
||||
|
||||
namespace onnx {
|
||||
class GraphProto;
|
||||
class NodeProto;
|
||||
} // namespace onnx
|
||||
|
||||
namespace caffe {
|
||||
class LayerParameter;
|
||||
} // namespace caffe
|
||||
|
||||
namespace tensorflow {
|
||||
class NodeDef;
|
||||
} // namespace tensorflow
|
||||
|
||||
namespace tflite {
|
||||
struct OperatorT;
|
||||
struct SubGraphT;
|
||||
struct ModelT;
|
||||
} // namespace tflite
|
||||
|
||||
namespace mindspore {
|
||||
namespace ops {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export LD_LIBRARY_PATH=./:${TENSORRT_PATH}/lib:${CUDA_HOME}/lib64:${LD_LIBRARY_P
|
|||
cp -r ${CUR_DIR}/ut/test_data/* ./
|
||||
cp -r ${CUR_DIR}/ut/src/runtime/kernel/arm/test_data/* ./
|
||||
cp -r ${CUR_DIR}/ut/tools/converter/parser/tflite/test_data/* ./
|
||||
cp -r ${CUR_DIR}/ut/tools/converter/registry/test_data/* ./
|
||||
# prepare data for dataset
|
||||
TEST_DATA_DIR=${CUR_DIR}/../../../tests/ut/data/dataset/
|
||||
cp -fr $TEST_DATA_DIR/testPK ./data
|
||||
|
|
@ -64,6 +65,7 @@ echo 'run common ut tests'
|
|||
./lite-test --gtest_filter="TestResizeOpenCL*"
|
||||
./lite-test --gtest_filter="TestSwishOpenCLCI.Fp32CI"
|
||||
./lite-test --gtest_filter="ModelParserRegistryTest.TestRegistry"
|
||||
./lite-test --gtest_filter="NodeParserRegistryTest.TestRegistry"
|
||||
./lite-test --gtest_filter="PassRegistryTest.TestRegistry"
|
||||
./lite-test --gtest_filter="TestRegistry.TestAdd"
|
||||
./lite-test --gtest_filter="TestRegistryCustomOp.TestCustomAdd"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include <vector>
|
||||
#include "common/common_test.h"
|
||||
#include "ut/tools/converter/registry/model_parser_test.h"
|
||||
#include "ut/tools/converter/registry/parser/model_parser_test.h"
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
|
||||
using mindspore::converter::ConverterParameters;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "api/ir/func_graph.h"
|
||||
#include "common/common_test.h"
|
||||
#include "include/registry/model_parser.h"
|
||||
#include "include/registry/model_parser_registry.h"
|
||||
#include "include/registry/node_parser_registry.h"
|
||||
#include "ops/addn.h"
|
||||
#include "proto/graph.pb.h"
|
||||
|
||||
using mindspore::converter::kFmkTypeTf;
|
||||
namespace mindspore {
|
||||
namespace converter {
|
||||
class AddNodeParser : public NodeParser {
|
||||
public:
|
||||
ops::PrimitiveC *Parse(const tensorflow::NodeDef &tf_op,
|
||||
const std::map<std::string, const tensorflow::NodeDef *> &tf_node_map,
|
||||
std::vector<std::string> *inputs, int *output_size) override {
|
||||
auto prim = std::make_unique<ops::AddN>();
|
||||
if (prim == nullptr) {
|
||||
MS_LOG(ERROR) << "make a shared_ptr failed.";
|
||||
return nullptr;
|
||||
}
|
||||
*output_size = 1;
|
||||
for (int i = 0; i < tf_op.input_size(); ++i) {
|
||||
inputs->push_back(tf_op.input(i));
|
||||
}
|
||||
return prim.release();
|
||||
}
|
||||
};
|
||||
REG_NODE_PARSER(kFmkTypeTf, Add, std::make_shared<AddNodeParser>());
|
||||
} // namespace converter
|
||||
|
||||
class NodeParserRegistryTest : public CommonTest {
|
||||
public:
|
||||
NodeParserRegistryTest() = default;
|
||||
void SetUp() override {
|
||||
auto model_parser = registry::ModelParserRegistry::GetModelParser(kFmkTypeTf);
|
||||
if (model_parser == nullptr) {
|
||||
return;
|
||||
}
|
||||
converter::ConverterParameters converter_parameters;
|
||||
converter_parameters.fmk = kFmkTypeTf;
|
||||
converter_parameters.model_file = "./tf_add.pb";
|
||||
func_graph_ = model_parser->Parse(converter_parameters);
|
||||
}
|
||||
api::FuncGraphPtr func_graph_ = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(NodeParserRegistryTest, TestRegistry) {
|
||||
ASSERT_NE(func_graph_, nullptr);
|
||||
auto node_list = api::FuncGraph::TopoSort(func_graph_->get_return());
|
||||
std::vector<CNodePtr> cnodes;
|
||||
for (auto &node : node_list) {
|
||||
if (node->isa<CNode>()) {
|
||||
cnodes.push_back(node->cast<CNodePtr>());
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(cnodes.size(), 2);
|
||||
auto cnode = cnodes.front();
|
||||
ASSERT_EQ(cnode->size(), 3);
|
||||
auto prim = GetValueNode<std::shared_ptr<ops::AddN>>(cnode->input(0));
|
||||
ASSERT_NE(prim, nullptr);
|
||||
}
|
||||
} // namespace mindspore
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ut/tools/converter/registry/model_parser_test.h"
|
||||
#include "ut/tools/converter/registry/parser/model_parser_test.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "include/errorcode.h"
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
#include <vector>
|
||||
#include "include/registry/model_parser.h"
|
||||
#include "include/registry/model_parser_registry.h"
|
||||
#include "ut/tools/converter/registry/node_parser_test.h"
|
||||
#include "ut/tools/converter/registry/parser/node_parser_test.h"
|
||||
|
||||
namespace mindspore {
|
||||
class ModelParserTest : public converter::ModelParser {
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ut/tools/converter/registry/node_parser_test.h"
|
||||
#include "ut/tools/converter/registry/parser/node_parser_test.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
#include "ops/custom.h"
|
||||
#include "tools/converter/optimizer_manager.h"
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
#include "ut/tools/converter/registry/model_parser_test.h"
|
||||
#include "ut/tools/converter/registry/parser/model_parser_test.h"
|
||||
|
||||
using mindspore::converter::ConverterParameters;
|
||||
using mindspore::converter::kFmkTypeCaffe;
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue