mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #17384 from dkurt:efficientdet
This commit is contained in:
@@ -235,6 +235,17 @@ PERF_TEST_P_(DNNTestNetwork, Inception_v2_Faster_RCNN)
|
||||
Mat(cv::Size(800, 600), CV_32FC3));
|
||||
}
|
||||
|
||||
PERF_TEST_P_(DNNTestNetwork, EfficientDet)
|
||||
{
|
||||
if (backend == DNN_BACKEND_HALIDE || target != DNN_TARGET_CPU)
|
||||
throw SkipTestException("");
|
||||
Mat sample = imread(findDataFile("dnn/dog416.png"));
|
||||
resize(sample, sample, Size(512, 512));
|
||||
Mat inp;
|
||||
sample.convertTo(inp, CV_32FC3, 1.0/255);
|
||||
processNet("dnn/efficientdet-d0.pb", "dnn/efficientdet-d0.pbtxt", "", inp);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, DNNTestNetwork, dnnBackendsAndTargets());
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1542,22 +1542,32 @@ void TFImporter::populateNet(Net dstNet)
|
||||
|
||||
connect(layer_id, dstNet, parsePin(layer.input(0)), id, 0);
|
||||
}
|
||||
else if (type == "Mul")
|
||||
else if (type == "Mul" || type == "RealDiv")
|
||||
{
|
||||
bool haveConst = false;
|
||||
for(int ii = 0; !haveConst && ii < layer.input_size(); ++ii)
|
||||
int constId = -1;
|
||||
for(int ii = 0; ii < layer.input_size(); ++ii)
|
||||
{
|
||||
Pin input = parsePin(layer.input(ii));
|
||||
haveConst = value_id.find(input.name) != value_id.end();
|
||||
if (value_id.find(input.name) != value_id.end())
|
||||
{
|
||||
constId = ii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CV_Assert(!haveConst || layer.input_size() == 2);
|
||||
CV_Assert((constId != -1) || (layer.input_size() == 2));
|
||||
|
||||
if (haveConst)
|
||||
if (constId != -1)
|
||||
{
|
||||
// Multiplication by constant.
|
||||
CV_Assert(layer.input_size() == 2);
|
||||
Mat scaleMat = getTensorContent(getConstBlob(layer, value_id));
|
||||
CV_Assert(scaleMat.type() == CV_32FC1);
|
||||
if (type == "RealDiv")
|
||||
{
|
||||
if (constId == 0)
|
||||
CV_Error(Error::StsNotImplemented, "Division of constant over variable");
|
||||
scaleMat = 1.0f / scaleMat;
|
||||
}
|
||||
|
||||
int id;
|
||||
if (scaleMat.total() == 1) // is a scalar.
|
||||
@@ -1659,11 +1669,15 @@ void TFImporter::populateNet(Net dstNet)
|
||||
int id;
|
||||
if (equalInpShapes || netInputShapes.empty())
|
||||
{
|
||||
layerParams.set("operation", "prod");
|
||||
layerParams.set("operation", type == "RealDiv" ? "div" : "prod");
|
||||
id = dstNet.addLayer(name, "Eltwise", layerParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type == "RealDiv")
|
||||
CV_Error(Error::StsNotImplemented, "Division of non equal tensors");
|
||||
id = dstNet.addLayer(name, "Scale", layerParams);
|
||||
}
|
||||
|
||||
layer_id[name] = id;
|
||||
|
||||
|
||||
@@ -1128,4 +1128,37 @@ TEST_P(Test_TensorFlow_nets, Mask_RCNN)
|
||||
expectNoFallbacks(net);
|
||||
}
|
||||
|
||||
TEST_P(Test_TensorFlow_nets, EfficientDet)
|
||||
{
|
||||
if (target != DNN_TARGET_CPU)
|
||||
{
|
||||
if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
|
||||
if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL);
|
||||
if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
|
||||
}
|
||||
checkBackend();
|
||||
std::string proto = findDataFile("dnn/efficientdet-d0.pbtxt");
|
||||
std::string model = findDataFile("dnn/efficientdet-d0.pb");
|
||||
|
||||
Net net = readNetFromTensorflow(model, proto);
|
||||
Mat img = imread(findDataFile("dnn/dog416.png"));
|
||||
Mat blob = blobFromImage(img, 1.0/255, Size(512, 512), Scalar(123.675, 116.28, 103.53));
|
||||
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
net.setInput(blob);
|
||||
// Output has shape 1x1xNx7 where N - number of detections.
|
||||
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
|
||||
Mat out = net.forward();
|
||||
|
||||
// References are from test for TensorFlow model.
|
||||
Mat ref = (Mat_<float>(3, 7) << 0, 1, 0.8437444, 0.153996080160141, 0.20534580945968628, 0.7463544607162476, 0.7414066195487976,
|
||||
0, 17, 0.8245924, 0.16657517850399017, 0.3996818959712982, 0.4111558794975281, 0.9306337833404541,
|
||||
0, 7, 0.8039304, 0.6118435263633728, 0.13175517320632935, 0.9065558314323425, 0.2943994700908661);
|
||||
double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 4e-3 : 1e-5;
|
||||
double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 2e-3 : 1e-4;
|
||||
normAssertDetections(ref, out, "", 0.5, scoreDiff, iouDiff);
|
||||
expectNoFallbacksFromIE(net);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user