TEST_P(Test_Darknet_nets, YOLOv3) { // batchId, classId, confidence, left, top, right, bottom Mat ref = (Mat_<float>(9, 7) << 0, 7, 0.952983f, 0.614622f, 0.150257f, 0.901369f, 0.289251f, // a truck 0, 1, 0.987908f, 0.150913f, 0.221933f, 0.742255f, 0.74626f, // a bicycle 0, 16, 0.998836f, 0.160024f, 0.389964f, 0.417885f, 0.943716f, // a dog (COCO) 1, 9, 0.384801f, 0.659824f, 0.372389f, 0.673926f, 0.429412f, // a traffic light 1, 9, 0.733283f, 0.376029f, 0.315694f, 0.401776f, 0.395165f, // a traffic light 1, 9, 0.785352f, 0.665503f, 0.373543f, 0.688893f, 0.439245f, // a traffic light 1, 0, 0.980052f, 0.195856f, 0.378454f, 0.258626f, 0.629258f, // a person 1, 2, 0.989633f, 0.450719f, 0.463353f, 0.496305f, 0.522258f, // a car 1, 2, 0.997412f, 0.647584f, 0.459939f, 0.821038f, 0.663947f); // a car double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.0047 : 8e-5; double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.018 : 3e-4; std::string config_file = "yolov3.cfg"; std::string weights_file = "yolov3.weights"; // batch size 1 testDarknetModel(config_file, weights_file, ref.rowRange(0, 3), scoreDiff, iouDiff); if ((backend != DNN_BACKEND_INFERENCE_ENGINE || target != DNN_TARGET_MYRIAD) && (backend != DNN_BACKEND_INFERENCE_ENGINE || target != DNN_TARGET_OPENCL)) { // batch size 2 testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff); } }
TEST_P(Test_Darknet_nets, TinyYoloVoc) { #if defined(INF_ENGINE_RELEASE) if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X) throw SkipTestException("Test is disabled for MyriadX (need to update check function)"); #endif // batchId, classId, confidence, left, top, right, bottom Mat ref = (Mat_<float>(4, 7) << 0, 6, 0.761967f, 0.579042f, 0.159161f, 0.894482f, 0.31994f, // a car 0, 11, 0.780595f, 0.129696f, 0.386467f, 0.445275f, 0.920994f, // a dog 1, 6, 0.651450f, 0.460526f, 0.458019f, 0.522527f, 0.5341f, // a car 1, 6, 0.928758f, 0.651024f, 0.463539f, 0.823784f, 0.654998f); // a car double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 8e-3 : 8e-5; double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.018 : 3e-4; std::string config_file = "tiny-yolo-voc.cfg"; std::string weights_file = "tiny-yolo-voc.weights"; { SCOPED_TRACE("batch size 1"); testDarknetModel(config_file, weights_file, ref.rowRange(0, 2), scoreDiff, iouDiff); } #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD) throw SkipTestException("Test with 'batch size 2' is disabled for Myriad target (fixed in 2018R5)"); #endif { SCOPED_TRACE("batch size 2"); testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff); } }
void testDarknetModel(const std::string& cfg, const std::string& weights, const cv::Mat& ref, double scoreDiff, double iouDiff, float confThreshold = 0.24, float nmsThreshold = 0.4) { CV_Assert(ref.cols == 7); std::vector<std::vector<int> > refClassIds; std::vector<std::vector<float> > refScores; std::vector<std::vector<Rect2d> > refBoxes; for (int i = 0; i < ref.rows; ++i) { int batchId = static_cast<int>(ref.at<float>(i, 0)); int classId = static_cast<int>(ref.at<float>(i, 1)); float score = ref.at<float>(i, 2); float left = ref.at<float>(i, 3); float top = ref.at<float>(i, 4); float right = ref.at<float>(i, 5); float bottom = ref.at<float>(i, 6); Rect2d box(left, top, right - left, bottom - top); if (batchId >= refClassIds.size()) { refClassIds.resize(batchId + 1); refScores.resize(batchId + 1); refBoxes.resize(batchId + 1); } refClassIds[batchId].push_back(classId); refScores[batchId].push_back(score); refBoxes[batchId].push_back(box); } testDarknetModel(cfg, weights, refClassIds, refScores, refBoxes, scoreDiff, iouDiff, confThreshold, nmsThreshold); }
void testDarknetModel(const std::string& cfg, const std::string& weights, const std::vector<int>& refClassIds, const std::vector<float>& refConfidences, const std::vector<Rect2d>& refBoxes, double scoreDiff, double iouDiff, float confThreshold = 0.24, float nmsThreshold = 0.4) { testDarknetModel(cfg, weights, std::vector<std::vector<int> >(1, refClassIds), std::vector<std::vector<float> >(1, refConfidences), std::vector<std::vector<Rect2d> >(1, refBoxes), scoreDiff, iouDiff, confThreshold, nmsThreshold); }
TEST_P(Test_Darknet_nets, YOLOv3) { #if defined(INF_ENGINE_RELEASE) if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X) throw SkipTestException("Test is disabled for MyriadX"); #endif // batchId, classId, confidence, left, top, right, bottom Mat ref = (Mat_<float>(9, 7) << 0, 7, 0.952983f, 0.614622f, 0.150257f, 0.901369f, 0.289251f, // a truck 0, 1, 0.987908f, 0.150913f, 0.221933f, 0.742255f, 0.74626f, // a bicycle 0, 16, 0.998836f, 0.160024f, 0.389964f, 0.417885f, 0.943716f, // a dog (COCO) 1, 9, 0.384801f, 0.659824f, 0.372389f, 0.673926f, 0.429412f, // a traffic light 1, 9, 0.733283f, 0.376029f, 0.315694f, 0.401776f, 0.395165f, // a traffic light 1, 9, 0.785352f, 0.665503f, 0.373543f, 0.688893f, 0.439245f, // a traffic light 1, 0, 0.980052f, 0.195856f, 0.378454f, 0.258626f, 0.629258f, // a person 1, 2, 0.989633f, 0.450719f, 0.463353f, 0.496305f, 0.522258f, // a car 1, 2, 0.997412f, 0.647584f, 0.459939f, 0.821038f, 0.663947f); // a car double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.0047 : 8e-5; double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.018 : 3e-4; std::string config_file = "yolov3.cfg"; std::string weights_file = "yolov3.weights"; { SCOPED_TRACE("batch size 1"); testDarknetModel(config_file, weights_file, ref.rowRange(0, 3), scoreDiff, iouDiff); } #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2018050000) if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL) throw SkipTestException("Test with 'batch size 2' is disabled for DLIE/OpenCL target"); #endif { SCOPED_TRACE("batch size 2"); testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff); } }
TEST_P(Test_Darknet_nets, TinyYoloVoc) { // batchId, classId, confidence, left, top, right, bottom Mat ref = (Mat_<float>(4, 7) << 0, 6, 0.761967f, 0.579042f, 0.159161f, 0.894482f, 0.31994f, // a car 0, 11, 0.780595f, 0.129696f, 0.386467f, 0.445275f, 0.920994f, // a dog 1, 6, 0.651450f, 0.460526f, 0.458019f, 0.522527f, 0.5341f, // a car 1, 6, 0.928758f, 0.651024f, 0.463539f, 0.823784f, 0.654998f); // a car double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 8e-3 : 8e-5; double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.018 : 3e-4; std::string config_file = "tiny-yolo-voc.cfg"; std::string weights_file = "tiny-yolo-voc.weights"; // batch size 1 testDarknetModel(config_file, weights_file, ref.rowRange(0, 2), scoreDiff, iouDiff); #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE == 2018040000 if (backend == DNN_BACKEND_INFERENCE_ENGINE && target != DNN_TARGET_MYRIAD) #endif // batch size 2 testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff); }
TEST_P(Test_Darknet_nets, YoloVoc) { // batchId, classId, confidence, left, top, right, bottom Mat ref = (Mat_<float>(6, 7) << 0, 6, 0.750469f, 0.577374f, 0.127391f, 0.902949f, 0.300809f, // a car 0, 1, 0.780879f, 0.270762f, 0.264102f, 0.732475f, 0.745412f, // a bicycle 0, 11, 0.901615f, 0.1386f, 0.338509f, 0.421337f, 0.938789f, // a dog 1, 14, 0.623813f, 0.183179f, 0.381921f, 0.247726f, 0.625847f, // a person 1, 6, 0.667770f, 0.446555f, 0.453578f, 0.499986f, 0.519167f, // a car 1, 6, 0.844947f, 0.637058f, 0.460398f, 0.828508f, 0.66427f); // a car double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 1e-2 : 8e-5; double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.018 : 3e-4; double nmsThreshold = (target == DNN_TARGET_MYRIAD) ? 0.397 : 0.4; std::string config_file = "yolo-voc.cfg"; std::string weights_file = "yolo-voc.weights"; // batch size 1 testDarknetModel(config_file, weights_file, ref.rowRange(0, 3), scoreDiff, iouDiff); // batch size 2 testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff, 0.24, nmsThreshold); }
TEST_P(Test_Darknet_nets, YoloVoc) { #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16) throw SkipTestException("Test is disabled"); #endif #if defined(INF_ENGINE_RELEASE) if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X) throw SkipTestException("Test is disabled for MyriadX (need to update check function)"); #endif // batchId, classId, confidence, left, top, right, bottom Mat ref = (Mat_<float>(6, 7) << 0, 6, 0.750469f, 0.577374f, 0.127391f, 0.902949f, 0.300809f, // a car 0, 1, 0.780879f, 0.270762f, 0.264102f, 0.732475f, 0.745412f, // a bicycle 0, 11, 0.901615f, 0.1386f, 0.338509f, 0.421337f, 0.938789f, // a dog 1, 14, 0.623813f, 0.183179f, 0.381921f, 0.247726f, 0.625847f, // a person 1, 6, 0.667770f, 0.446555f, 0.453578f, 0.499986f, 0.519167f, // a car 1, 6, 0.844947f, 0.637058f, 0.460398f, 0.828508f, 0.66427f); // a car double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 1e-2 : 8e-5; double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.018 : 3e-4; double nmsThreshold = (target == DNN_TARGET_MYRIAD) ? 0.397 : 0.4; std::string config_file = "yolo-voc.cfg"; std::string weights_file = "yolo-voc.weights"; { SCOPED_TRACE("batch size 1"); testDarknetModel(config_file, weights_file, ref.rowRange(0, 3), scoreDiff, iouDiff); } { SCOPED_TRACE("batch size 2"); testDarknetModel(config_file, weights_file, ref, scoreDiff, iouDiff, 0.24, nmsThreshold); } }