mirror of
https://github.com/opencv/opencv.git
synced 2025-07-30 17:37:05 +08:00
Merge pull request #15639 from alalek:dnn_test_fix_data
This commit is contained in:
commit
8115b004b9
@ -62,6 +62,7 @@ def printParams(backend, target):
|
|||||||
}
|
}
|
||||||
print('%s/%s' % (backendNames[backend], targetNames[target]))
|
print('%s/%s' % (backendNames[backend], targetNames[target]))
|
||||||
|
|
||||||
|
testdata_required = bool(os.environ.get('OPENCV_DNN_TEST_REQUIRE_TESTDATA', False))
|
||||||
|
|
||||||
class dnn_test(NewOpenCVTests):
|
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])
|
self.dnnBackendsAndTargets.append([cv.dnn.DNN_BACKEND_INFERENCE_ENGINE, cv.dnn.DNN_TARGET_OPENCL_FP16])
|
||||||
|
|
||||||
def find_dnn_file(self, filename, required=True):
|
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()),
|
return self.find_file(filename, [os.environ.get('OPENCV_DNN_TEST_DATA_PATH', os.getcwd()),
|
||||||
os.environ['OPENCV_TEST_DATA_PATH']],
|
os.environ['OPENCV_TEST_DATA_PATH']],
|
||||||
required=required)
|
required=required)
|
||||||
|
|
||||||
def checkIETarget(self, backend, target):
|
def checkIETarget(self, backend, target):
|
||||||
proto = self.find_dnn_file('dnn/layers/layer_convolution.prototxt', required=True)
|
proto = self.find_dnn_file('dnn/layers/layer_convolution.prototxt')
|
||||||
model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel', required=True)
|
model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel')
|
||||||
net = cv.dnn.readNet(proto, model)
|
net = cv.dnn.readNet(proto, model)
|
||||||
net.setPreferableBackend(backend)
|
net.setPreferableBackend(backend)
|
||||||
net.setPreferableTarget(target)
|
net.setPreferableTarget(target)
|
||||||
@ -134,8 +137,11 @@ class dnn_test(NewOpenCVTests):
|
|||||||
|
|
||||||
def test_model(self):
|
def test_model(self):
|
||||||
img_path = self.find_dnn_file("dnn/street.png")
|
img_path = self.find_dnn_file("dnn/street.png")
|
||||||
weights = self.find_dnn_file("dnn/MobileNetSSD_deploy.caffemodel")
|
weights = self.find_dnn_file("dnn/MobileNetSSD_deploy.caffemodel", required=False)
|
||||||
config = self.find_dnn_file("dnn/MobileNetSSD_deploy.prototxt")
|
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)
|
frame = cv.imread(img_path)
|
||||||
model = cv.dnn_DetectionModel(weights, config)
|
model = cv.dnn_DetectionModel(weights, config)
|
||||||
model.setInputParams(size=(300, 300), mean=(127.5, 127.5, 127.5), scale=1.0/127.5)
|
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):
|
def test_classification_model(self):
|
||||||
img_path = self.find_dnn_file("dnn/googlenet_0.png")
|
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")
|
config = self.find_dnn_file("dnn/squeezenet_v1.1.prototxt")
|
||||||
ref = np.load(self.find_dnn_file("dnn/squeezenet_v1.1_prob.npy"))
|
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)
|
frame = cv.imread(img_path)
|
||||||
model = cv.dnn_ClassificationModel(config, weights)
|
model = cv.dnn_ClassificationModel(config, weights)
|
||||||
@ -177,9 +185,8 @@ class dnn_test(NewOpenCVTests):
|
|||||||
|
|
||||||
|
|
||||||
def test_face_detection(self):
|
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')
|
||||||
proto = self.find_dnn_file('dnn/opencv_face_detector.prototxt', required=testdata_required)
|
model = self.find_dnn_file('dnn/opencv_face_detector.caffemodel', required=False)
|
||||||
model = self.find_dnn_file('dnn/opencv_face_detector.caffemodel', required=testdata_required)
|
|
||||||
if proto is None or model is None:
|
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.")
|
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):
|
def test_async(self):
|
||||||
timeout = 10*1000*10**6 # in nanoseconds (10 sec)
|
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')
|
||||||
proto = self.find_dnn_file('dnn/layers/layer_convolution.prototxt', required=testdata_required)
|
model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel')
|
||||||
model = self.find_dnn_file('dnn/layers/layer_convolution.caffemodel', required=testdata_required)
|
|
||||||
if proto is None or model is None:
|
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.")
|
raise unittest.SkipTest("Missing DNN test files (dnn/layers/layer_convolution.{prototxt/caffemodel}). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.")
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
namespace opencv_test { namespace {
|
namespace opencv_test { namespace {
|
||||||
|
|
||||||
template<typename TString>
|
template<typename TString>
|
||||||
static std::string _tf(TString filename)
|
static std::string _tf(TString filename, bool required = true)
|
||||||
{
|
{
|
||||||
String rootFolder = "dnn/";
|
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 img_path = _tf("grace_hopper_227.png");
|
||||||
std::string config_file = _tf("bvlc_alexnet.prototxt");
|
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};
|
Size size{227, 227};
|
||||||
float norm = 1e-4;
|
float norm = 1e-4;
|
||||||
@ -127,7 +127,7 @@ TEST_P(Test_Model, DetectRegion)
|
|||||||
Rect2d(58, 141, 117, 249)};
|
Rect2d(58, 141, 117, 249)};
|
||||||
|
|
||||||
std::string img_path = _tf("dog416.png");
|
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");
|
std::string config_file = _tf("yolo-voc.cfg");
|
||||||
|
|
||||||
double scale = 1.0 / 255.0;
|
double scale = 1.0 / 255.0;
|
||||||
@ -160,7 +160,7 @@ TEST_P(Test_Model, DetectionOutput)
|
|||||||
Rect2d(132, 223, 207, 344)};
|
Rect2d(132, 223, 207, 344)};
|
||||||
|
|
||||||
std::string img_path = _tf("dog416.png");
|
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");
|
std::string config_file = _tf("rfcn_pascal_voc_resnet50.prototxt");
|
||||||
|
|
||||||
Scalar mean = Scalar(102.9801, 115.9465, 122.7717);
|
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);
|
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");
|
std::string config_file = _tf("MobileNetSSD_deploy.prototxt");
|
||||||
|
|
||||||
Scalar mean = Scalar(127.5, 127.5, 127.5);
|
Scalar mean = Scalar(127.5, 127.5, 127.5);
|
||||||
@ -228,7 +228,7 @@ TEST_P(Test_Model, Detection_normalized)
|
|||||||
std::vector<float> refConfidences = {0.999222f};
|
std::vector<float> refConfidences = {0.999222f};
|
||||||
std::vector<Rect2d> refBoxes = {Rect2d(0, 4, 227, 222)};
|
std::vector<Rect2d> 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");
|
std::string config_file = _tf("MobileNetSSD_deploy.prototxt");
|
||||||
|
|
||||||
Scalar mean = Scalar(127.5, 127.5, 127.5);
|
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 inp = _tf("dog416.png");
|
||||||
std::string weights_file = _tf("fcn8s-heavy-pascal.prototxt");
|
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");
|
std::string exp = _tf("segmentation_exp.png");
|
||||||
|
|
||||||
Size size{128, 128};
|
Size size{128, 128};
|
||||||
|
Loading…
Reference in New Issue
Block a user