MCPcopy Create free account
hub / github.com/alibaba/MNN / compareNet

Function compareNet

tools/cpp/modelCompare.cpp:36–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34using namespace MNN;
35
36static void compareNet(Interpreter* net, Interpreter* net2, MNNForwardType expectType, float tolerance,
37 const std::map<std::string, std::shared_ptr<Tensor>>& inputs, const std::string& stopOp, BackendConfig::PrecisionMode precision, int modeNum) {
38 std::vector<std::shared_ptr<MNN::Tensor>> correctResult;
39 int index;
40 MNN::ScheduleConfig expectConfig;
41 BackendConfig backendConfig;
42 backendConfig.precision = precision;
43 expectConfig.type = expectType;
44 expectConfig.backendConfig = &backendConfig;
45 expectConfig.mode = modeNum;
46 auto expectSession = net->createSession(expectConfig);
47 auto compareSession = net2->createSession(expectConfig);
48
49 bool allCorrect = true;
50
51 MNN::TensorCallBackWithInfo beginCallBack = [&](const std::vector<MNN::Tensor*>& t, const OperatorInfo* op) {
52 if (op->name() == stopOp) {
53 return false;
54 }
55 return true;
56 };
57 MNN::TensorCallBackWithInfo saveExpect = [&](const std::vector<MNN::Tensor*>& t, const OperatorInfo* op) {
58 if (op->name() == stopOp) {
59 return false;
60 }
61 if (op->type() == "Raster") {
62 return true;
63 }
64 for (int i=0; i<t.size(); ++i) {
65 auto tensor = t[i];
66 if (tensor->elementSize() <= 0) {
67 return true;
68 }
69 if (tensor->buffer().device == 0 && tensor->buffer().host == nullptr) {
70 return true;
71 }
72 std::shared_ptr<MNN::Tensor> copyTensor(MNN::Tensor::createHostTensorFromDevice(tensor, true));
73 correctResult.emplace_back(copyTensor);
74 }
75 return true;
76 };
77 MNN::TensorCallBackWithInfo compareExpect = [&](const std::vector<MNN::Tensor*>& t, const OperatorInfo* op) {
78 if (op->name() == stopOp) {
79 return false;
80 }
81 if (op->type() == "Raster") {
82 return true;
83 }
84 for (int i=0; i<t.size(); ++i) {
85 auto tensor = t[i];
86 if (tensor->elementSize() <= 0) {
87 return true;
88 }
89 if (tensor->buffer().device == 0 && tensor->buffer().host == nullptr) {
90 return true;
91 }
92 std::shared_ptr<MNN::Tensor> copyTensor(MNN::Tensor::createHostTensorFromDevice(tensor, true));
93 auto expectTensor = correctResult[index++];

Callers 1

mainFunction · 0.85

Calls 12

getSessionInputMethod · 0.80
copyFromHostTensorMethod · 0.80
createSessionMethod · 0.45
nameMethod · 0.45
typeMethod · 0.45
sizeMethod · 0.45
bufferMethod · 0.45
getMethod · 0.45
c_strMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected