diff --git a/PhysicsTools/MXNet/test/BuildFile.xml b/PhysicsTools/MXNet/test/BuildFile.xml new file mode 100644 index 0000000000000..fc4718f406f6f --- /dev/null +++ b/PhysicsTools/MXNet/test/BuildFile.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/PhysicsTools/MXNet/test/data/testmxnet-0000.params b/PhysicsTools/MXNet/test/data/testmxnet-0000.params new file mode 100644 index 0000000000000..3c6a87622c521 Binary files /dev/null and b/PhysicsTools/MXNet/test/data/testmxnet-0000.params differ diff --git a/PhysicsTools/MXNet/test/data/testmxnet-symbol.json b/PhysicsTools/MXNet/test/data/testmxnet-symbol.json new file mode 100644 index 0000000000000..c423651756d8e --- /dev/null +++ b/PhysicsTools/MXNet/test/data/testmxnet-symbol.json @@ -0,0 +1,79 @@ +{ + "nodes": [ + { + "op": "null", + "name": "data", + "inputs": [] + }, + { + "op": "null", + "name": "dense0_weight", + "attrs": { + "__dtype__": "0", + "__lr_mult__": "1.0", + "__shape__": "(7, 0)", + "__wd_mult__": "1.0" + }, + "inputs": [] + }, + { + "op": "null", + "name": "dense0_bias", + "attrs": { + "__dtype__": "0", + "__init__": "zeros", + "__lr_mult__": "1.0", + "__shape__": "(7,)", + "__wd_mult__": "1.0" + }, + "inputs": [] + }, + { + "op": "FullyConnected", + "name": "dense0_fwd", + "attrs": { + "flatten": "True", + "no_bias": "False", + "num_hidden": "7" + }, + "inputs": [[0, 0, 0], [1, 0, 0], [2, 0, 0]] + }, + { + "op": "null", + "name": "dense1_weight", + "attrs": { + "__dtype__": "0", + "__lr_mult__": "1.0", + "__shape__": "(3, 0)", + "__wd_mult__": "1.0" + }, + "inputs": [] + }, + { + "op": "null", + "name": "dense1_bias", + "attrs": { + "__dtype__": "0", + "__init__": "zeros", + "__lr_mult__": "1.0", + "__shape__": "(3,)", + "__wd_mult__": "1.0" + }, + "inputs": [] + }, + { + "op": "FullyConnected", + "name": "dense1_fwd", + "attrs": { + "flatten": "True", + "no_bias": "False", + "num_hidden": "3" + }, + "inputs": [[3, 0, 0], [4, 0, 0], [5, 0, 0]] + } + ], + "arg_nodes": [0, 1, 2, 4, 5], + "node_row_ptr": [0, 1, 2, 3, 4, 5, 6, 7], + "heads": [[6, 0, 0]], + "attrs": {"mxnet_version": ["int", 10200]} +} \ No newline at end of file diff --git a/PhysicsTools/MXNet/test/testMXNetPredictor.cc b/PhysicsTools/MXNet/test/testMXNetPredictor.cc new file mode 100644 index 0000000000000..23067fac668d5 --- /dev/null +++ b/PhysicsTools/MXNet/test/testMXNetPredictor.cc @@ -0,0 +1,58 @@ +#include + +#include "FWCore/ParameterSet/interface/FileInPath.h" +#include "PhysicsTools/MXNet/interface/MXNetPredictor.h" + +class testMXNetPredictor : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(testMXNetPredictor); + CPPUNIT_TEST(checkAll); + CPPUNIT_TEST_SUITE_END(); + +public: + void checkAll(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(testMXNetPredictor); + +void testMXNetPredictor::checkAll() +{ + + // load model and params into BufferFile + std::string model_path = edm::FileInPath("PhysicsTools/MXNet/test/data/testmxnet-symbol.json").fullPath(); + std::string param_path = edm::FileInPath("PhysicsTools/MXNet/test/data/testmxnet-0000.params").fullPath(); + + mxnet::BufferFile *model_file = new mxnet::BufferFile(model_path); + CPPUNIT_ASSERT(model_file != nullptr); + CPPUNIT_ASSERT(model_file->GetLength() > 0); + + mxnet::BufferFile *param_file = new mxnet::BufferFile(param_path); + CPPUNIT_ASSERT(param_file != nullptr); + CPPUNIT_ASSERT(param_file->GetLength() > 0); + + // create predictor + mxnet::MXNetPredictor predictor; + + // set input shape + std::vector input_names {"data"}; + std::vector> input_shapes {{1, 3}}; + CPPUNIT_ASSERT_NO_THROW( predictor.set_input_shapes(input_names, input_shapes) ); + + // load model from BufferFile + CPPUNIT_ASSERT_NO_THROW( predictor.load_model(model_file, param_file) ); + + // run predictor + std::vector> data {{1, 2, 3,}}; + std::vector outputs; + CPPUNIT_ASSERT_NO_THROW( outputs = predictor.predict(data) ); + + // check outputs + CPPUNIT_ASSERT(outputs.size() == 3); + CPPUNIT_ASSERT(outputs.at(0) == 42); + CPPUNIT_ASSERT(outputs.at(1) == 42); + CPPUNIT_ASSERT(outputs.at(2) == 42); + + delete model_file; + delete param_file; + +} diff --git a/PhysicsTools/MXNet/test/testRunner.cpp b/PhysicsTools/MXNet/test/testRunner.cpp new file mode 100644 index 0000000000000..1482cf9a9ce85 --- /dev/null +++ b/PhysicsTools/MXNet/test/testRunner.cpp @@ -0,0 +1 @@ +#include