From f0058bbed3716d0cfc214dc7dc0be02ab2eb74f4 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 4 Oct 2019 16:48:05 +0300 Subject: [PATCH] dnn(test): fix optional test data --- modules/dnn/misc/python/test/test_dnn.py | 28 +++++++++++++++++----------- modules/dnn/test/test_model.cpp | 16 ++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/modules/dnn/misc/python/test/test_dnn.py b/modules/dnn/misc/python/test/test_dnn.py index 7230e16..253def7 100644 --- a/modules/dnn/misc/python/test/test_dnn.py +++ b/modules/dnn/misc/python/test/test_dnn.py @@ -62,6 +62,7 @@ def printParams(backend, target): } print('%s/%s' % (backendNames[backend], targetNames[target])) +testdata_required = bool(os.environ.get('OPENCV_DNN_TEST_REQUIRE_TESTDATA', False)) class dnn_test(NewOpenCVTests): @@ -87,13 +88,15 @@ class dnn_test(NewOpenCVTests): self.dnnBackendsAndTargets.append([cv.dnn.DNN_BACKEND_INFERENCE_ENGINE, cv.dnn.DNN_TARGET_OPENCL_FP16]) def find_dnn_file(self, filename, required=True): + if not required: + required = testdata_required return self.find_file(filename, [os.environ.get('OPENCV_DNN_TEST_DATA_PATH', os.getcwd()), os.environ['OPENCV_TEST_DATA_PATH']], required=required) def checkIETarget(self, backend, target): - proto = self.find_dnn_file('dnn/layers/layer_convolution.prototxt', required=True) - model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel', required=True) + proto = self.find_dnn_file('dnn/layers/layer_convolution.prototxt') + model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel') net = cv.dnn.readNet(proto, model) net.setPreferableBackend(backend) net.setPreferableTarget(target) @@ -134,8 +137,11 @@ class dnn_test(NewOpenCVTests): def test_model(self): img_path = self.find_dnn_file("dnn/street.png") - weights = self.find_dnn_file("dnn/MobileNetSSD_deploy.caffemodel") - config = self.find_dnn_file("dnn/MobileNetSSD_deploy.prototxt") + weights = self.find_dnn_file("dnn/MobileNetSSD_deploy.caffemodel", required=False) + config = self.find_dnn_file("dnn/MobileNetSSD_deploy.prototxt", required=False) + if weights is None or config is None: + raise unittest.SkipTest("Missing DNN test files (dnn/MobileNetSSD_deploy.{prototxt/caffemodel}). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.") + frame = cv.imread(img_path) model = cv.dnn_DetectionModel(weights, config) model.setInputParams(size=(300, 300), mean=(127.5, 127.5, 127.5), scale=1.0/127.5) @@ -163,9 +169,11 @@ class dnn_test(NewOpenCVTests): def test_classification_model(self): img_path = self.find_dnn_file("dnn/googlenet_0.png") - weights = self.find_dnn_file("dnn/squeezenet_v1.1.caffemodel") + weights = self.find_dnn_file("dnn/squeezenet_v1.1.caffemodel", required=False) config = self.find_dnn_file("dnn/squeezenet_v1.1.prototxt") ref = np.load(self.find_dnn_file("dnn/squeezenet_v1.1_prob.npy")) + if weights is None or config is None: + raise unittest.SkipTest("Missing DNN test files (dnn/squeezenet_v1.1.{prototxt/caffemodel}). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.") frame = cv.imread(img_path) model = cv.dnn_ClassificationModel(config, weights) @@ -177,9 +185,8 @@ class dnn_test(NewOpenCVTests): def test_face_detection(self): - testdata_required = bool(os.environ.get('OPENCV_DNN_TEST_REQUIRE_TESTDATA', False)) - proto = self.find_dnn_file('dnn/opencv_face_detector.prototxt', required=testdata_required) - model = self.find_dnn_file('dnn/opencv_face_detector.caffemodel', required=testdata_required) + proto = self.find_dnn_file('dnn/opencv_face_detector.prototxt') + model = self.find_dnn_file('dnn/opencv_face_detector.caffemodel', required=False) if proto is None or model is None: raise unittest.SkipTest("Missing DNN test files (dnn/opencv_face_detector.{prototxt/caffemodel}). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.") @@ -216,9 +223,8 @@ class dnn_test(NewOpenCVTests): def test_async(self): timeout = 10*1000*10**6 # in nanoseconds (10 sec) - testdata_required = bool(os.environ.get('OPENCV_DNN_TEST_REQUIRE_TESTDATA', False)) - proto = self.find_dnn_file('dnn/layers/layer_convolution.prototxt', required=testdata_required) - model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel', required=testdata_required) + proto = self.find_dnn_file('dnn/layers/layer_convolution.prototxt') + model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel') if proto is None or model is None: raise unittest.SkipTest("Missing DNN test files (dnn/layers/layer_convolution.{prototxt/caffemodel}). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.") diff --git a/modules/dnn/test/test_model.cpp b/modules/dnn/test/test_model.cpp index 5bc5bd3..d079415 100644 --- a/modules/dnn/test/test_model.cpp +++ b/modules/dnn/test/test_model.cpp @@ -8,10 +8,10 @@ namespace opencv_test { namespace { template -static std::string _tf(TString filename) +static std::string _tf(TString filename, bool required = true) { String rootFolder = "dnn/"; - return findDataFile(rootFolder + filename); + return findDataFile(rootFolder + filename, required); } @@ -96,7 +96,7 @@ TEST_P(Test_Model, Classify) std::string img_path = _tf("grace_hopper_227.png"); std::string config_file = _tf("bvlc_alexnet.prototxt"); - std::string weights_file = _tf("bvlc_alexnet.caffemodel"); + std::string weights_file = _tf("bvlc_alexnet.caffemodel", false); Size size{227, 227}; float norm = 1e-4; @@ -127,7 +127,7 @@ TEST_P(Test_Model, DetectRegion) Rect2d(58, 141, 117, 249)}; std::string img_path = _tf("dog416.png"); - std::string weights_file = _tf("yolo-voc.weights"); + std::string weights_file = _tf("yolo-voc.weights", false); std::string config_file = _tf("yolo-voc.cfg"); double scale = 1.0 / 255.0; @@ -160,7 +160,7 @@ TEST_P(Test_Model, DetectionOutput) Rect2d(132, 223, 207, 344)}; std::string img_path = _tf("dog416.png"); - std::string weights_file = _tf("resnet50_rfcn_final.caffemodel"); + std::string weights_file = _tf("resnet50_rfcn_final.caffemodel", false); std::string config_file = _tf("rfcn_pascal_voc_resnet50.prototxt"); Scalar mean = Scalar(102.9801, 115.9465, 122.7717); @@ -203,7 +203,7 @@ TEST_P(Test_Model, DetectionMobilenetSSD) refBoxes.emplace_back(left, top, width, height); } - std::string weights_file = _tf("MobileNetSSD_deploy.caffemodel"); + std::string weights_file = _tf("MobileNetSSD_deploy.caffemodel", false); std::string config_file = _tf("MobileNetSSD_deploy.prototxt"); Scalar mean = Scalar(127.5, 127.5, 127.5); @@ -228,7 +228,7 @@ TEST_P(Test_Model, Detection_normalized) std::vector refConfidences = {0.999222f}; std::vector refBoxes = {Rect2d(0, 4, 227, 222)}; - std::string weights_file = _tf("MobileNetSSD_deploy.caffemodel"); + std::string weights_file = _tf("MobileNetSSD_deploy.caffemodel", false); std::string config_file = _tf("MobileNetSSD_deploy.prototxt"); Scalar mean = Scalar(127.5, 127.5, 127.5); @@ -247,7 +247,7 @@ TEST_P(Test_Model, Segmentation) { std::string inp = _tf("dog416.png"); std::string weights_file = _tf("fcn8s-heavy-pascal.prototxt"); - std::string config_file = _tf("fcn8s-heavy-pascal.caffemodel"); + std::string config_file = _tf("fcn8s-heavy-pascal.caffemodel", false); std::string exp = _tf("segmentation_exp.png"); Size size{128, 128}; -- 2.7.4