@@ -26,44 +26,6 @@ class ONNXModelsTest : public ::testing::Test {
2626
2727 std::unique_ptr<logging::Logger> logger_;
2828};
29- #ifdef ORT_RUN_EXTERNAL_ONNX_TESTS
30- // Tests that Resolve() properly clears the state of topological sorted nodes,
31- // inputs, outputs and valueInfo.
32- // Assumes the graph passed in has been previously resolved.
33- static void TestResolve (onnxruntime::Graph& graph) {
34- GraphViewer graph_viewer (graph);
35- auto & nodes_before = graph_viewer.GetNodesInTopologicalOrder ();
36- auto & inputs_before = graph.GetInputs ();
37- auto & outputs_before = graph.GetOutputs ();
38- auto & value_info_before = graph.GetValueInfo ();
39-
40- // Touch the graph to force Resolve() to recompute.
41- graph.SetGraphResolveNeeded ();
42- graph.SetGraphProtoSyncNeeded ();
43- ASSERT_STATUS_OK (graph.Resolve ());
44-
45- GraphViewer graph_viewer_2 (graph);
46- auto & nodes_after = graph_viewer_2.GetNodesInTopologicalOrder ();
47- auto & inputs_after = graph.GetInputs ();
48- auto & outputs_after = graph.GetOutputs ();
49- auto & value_info_after = graph.GetValueInfo ();
50-
51- // Multiple calls to Resolve() should not alter the sorted nodes,
52- // inputs, outputs and valueInfo. The internal state should be
53- // cleared.
54- EXPECT_EQ (nodes_before, nodes_after);
55- EXPECT_EQ (inputs_before, inputs_after);
56- EXPECT_EQ (outputs_before, outputs_after);
57- EXPECT_EQ (value_info_before, value_info_after);
58- }
59-
60- TEST_F (ONNXModelsTest, squeeze_net) {
61- // NOTE: this requires the current directory to be where onnxruntime_ir_UT.exe is located
62- std::shared_ptr<Model> model;
63- ASSERT_STATUS_OK (Model::Load (ORT_TSTR (" ../models/opset8/test_squeezenet/model.onnx" ), model, nullptr , *logger_));
64- TestResolve (model->MainGraph ());
65- }
66- #endif
6729
6830TEST_F (ONNXModelsTest, non_existing_model) {
6931 // NOTE: this requires the current directory to be where onnxruntime_ir_UT.exe is located
@@ -96,76 +58,6 @@ class ONNXModelsTest1 : public ::testing::TestWithParam<const ORTCHAR_T*> {
9658 return oss.str ();
9759 }
9860};
99- #ifdef ORT_RUN_EXTERNAL_ONNX_TESTS
100- TEST_F (ONNXModelsTest, bvlc_alexnet_1) {
101- using ::google::protobuf::io::CodedInputStream;
102- using ::google::protobuf::io::FileInputStream;
103- using ::google::protobuf::io::ZeroCopyInputStream;
104- int fd;
105- ASSERT_STATUS_OK (Env::Default ().FileOpenRd (ORT_TSTR (" ../models/opset8/test_bvlc_alexnet/model.onnx" ), fd));
106- ASSERT_TRUE (fd > 0 );
107- std::unique_ptr<ZeroCopyInputStream> raw_input (new FileInputStream (fd));
108- std::unique_ptr<CodedInputStream> coded_input (new CodedInputStream (raw_input.get ()));
109- // Allows protobuf library versions < 3.2.0 to parse messages greater than 64MB.
110- coded_input->SetTotalBytesLimit (INT_MAX);
111- ModelProto model_proto;
112- bool result = model_proto.ParseFromCodedStream (coded_input.get ());
113- coded_input.reset ();
114- raw_input.reset ();
115- EXPECT_TRUE (result);
116- ASSERT_STATUS_OK (Env::Default ().FileClose (fd));
117-
118- std::shared_ptr<Model> model;
119- ASSERT_STATUS_OK (Model::Load (ORT_TSTR (" ../models/opset8/test_bvlc_alexnet/model.onnx" ), model, nullptr ,
120- *logger_));
121-
122- // Check the graph input/output/value_info should have the same size as specified in the model file.
123- EXPECT_EQ (static_cast <size_t >(model_proto.graph ().value_info_size ()), model->MainGraph ().GetValueInfo ().size ());
124- EXPECT_EQ (static_cast <size_t >(model_proto.graph ().input_size ()), model->MainGraph ().GetInputs ().size () + model->MainGraph ().GetAllInitializedTensors ().size ());
125- EXPECT_EQ (static_cast <size_t >(model_proto.graph ().output_size ()), model->MainGraph ().GetOutputs ().size ());
126- TestResolve (model->MainGraph ());
127- }
128-
129- TEST_P (ONNXModelsTest1, LoadFromFile) {
130- std::shared_ptr<Model> model;
131- ASSERT_STATUS_OK (Model::Load (GetModelFileName (), model, nullptr ,
132- *logger_));
133- TestResolve (model->MainGraph ());
134- }
135-
136- TEST_P (ONNXModelsTest1, LoadFromProtobuf) {
137- using ::google::protobuf::io::CodedInputStream;
138- using ::google::protobuf::io::FileInputStream;
139- using ::google::protobuf::io::ZeroCopyInputStream;
140- int fd;
141- ASSERT_STATUS_OK (Env::Default ().FileOpenRd (GetModelFileName (), fd));
142- ASSERT_TRUE (fd > 0 );
143- std::unique_ptr<ZeroCopyInputStream> raw_input (new FileInputStream (fd));
144- std::unique_ptr<CodedInputStream> coded_input (new CodedInputStream (raw_input.get ()));
145- coded_input->SetTotalBytesLimit (INT_MAX);
146- ModelProto model_proto;
147- bool result = model_proto.ParseFromCodedStream (coded_input.get ());
148- coded_input.reset ();
149- raw_input.reset ();
150- ASSERT_TRUE (result);
151- ASSERT_STATUS_OK (Env::Default ().FileClose (fd));
152- std::shared_ptr<Model> model;
153- ASSERT_STATUS_OK (Model::Load (std::move (model_proto), model, nullptr ,
154- *logger_));
155- TestResolve (model->MainGraph ());
156- }
157-
158- #ifndef DISABLE_CONTRIB_OPS
159- INSTANTIATE_TEST_SUITE_P (ONNXModelsTests,
160- ONNXModelsTest1,
161- ::testing::Values (ORT_TSTR(" bvlc_alexnet" ), ORT_TSTR(" bvlc_googlenet" ), ORT_TSTR(" bvlc_reference_caffenet" ), ORT_TSTR(" bvlc_reference_rcnn_ilsvrc13" ), ORT_TSTR(" densenet121" ), ORT_TSTR(" emotion_ferplus" ), ORT_TSTR(" inception_v1" ), ORT_TSTR(" inception_v2" ), ORT_TSTR(" mnist" ), ORT_TSTR(" resnet50" ), ORT_TSTR(" shufflenet" ), ORT_TSTR(" squeezenet" ), ORT_TSTR(" tiny_yolov2" ), ORT_TSTR(" vgg19" ), ORT_TSTR(" zfnet512" )));
162- #else
163- INSTANTIATE_TEST_SUITE_P (ONNXModelsTests,
164- ONNXModelsTest1,
165- ::testing::Values (ORT_TSTR(" bvlc_alexnet" ), ORT_TSTR(" bvlc_googlenet" ), ORT_TSTR(" bvlc_reference_caffenet" ), ORT_TSTR(" bvlc_reference_rcnn_ilsvrc13" ), ORT_TSTR(" densenet121" ), ORT_TSTR(" emotion_ferplus" ), ORT_TSTR(" inception_v1" ), ORT_TSTR(" inception_v2" ), ORT_TSTR(" mnist" ), ORT_TSTR(" resnet50" ), ORT_TSTR(" shufflenet" ), ORT_TSTR(" squeezenet" ), ORT_TSTR(" vgg19" ), ORT_TSTR(" zfnet512" )));
166- #endif
167-
168- #endif
16961
17062// test a model that conforms to ONNX IR v4 where there are initializers that are not graph inputs.
17163// a NodeArg should be created for all initializers in this case.
0 commit comments