mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -212,6 +212,44 @@ namespace cv {
|
||||
fused_layer_names.push_back(last_layer);
|
||||
}
|
||||
|
||||
void setAvgpool()
|
||||
{
|
||||
cv::dnn::LayerParams avgpool_param;
|
||||
avgpool_param.set<cv::String>("pool", "ave");
|
||||
avgpool_param.set<bool>("global_pooling", true);
|
||||
avgpool_param.name = "Pooling-name";
|
||||
avgpool_param.type = "Pooling";
|
||||
darknet::LayerParameter lp;
|
||||
|
||||
std::string layer_name = cv::format("avgpool_%d", layer_id);
|
||||
lp.layer_name = layer_name;
|
||||
lp.layer_type = avgpool_param.type;
|
||||
lp.layerParams = avgpool_param;
|
||||
lp.bottom_indexes.push_back(last_layer);
|
||||
last_layer = layer_name;
|
||||
net->layers.push_back(lp);
|
||||
layer_id++;
|
||||
fused_layer_names.push_back(last_layer);
|
||||
}
|
||||
|
||||
void setSoftmax()
|
||||
{
|
||||
cv::dnn::LayerParams softmax_param;
|
||||
softmax_param.name = "Softmax-name";
|
||||
softmax_param.type = "Softmax";
|
||||
darknet::LayerParameter lp;
|
||||
|
||||
std::string layer_name = cv::format("softmax_%d", layer_id);
|
||||
lp.layer_name = layer_name;
|
||||
lp.layer_type = softmax_param.type;
|
||||
lp.layerParams = softmax_param;
|
||||
lp.bottom_indexes.push_back(last_layer);
|
||||
last_layer = layer_name;
|
||||
net->layers.push_back(lp);
|
||||
layer_id++;
|
||||
fused_layer_names.push_back(last_layer);
|
||||
}
|
||||
|
||||
void setConcat(int number_of_inputs, int *input_indexes)
|
||||
{
|
||||
cv::dnn::LayerParams concat_param;
|
||||
@@ -541,6 +579,17 @@ namespace cv {
|
||||
int pad = getParam<int>(layer_params, "pad", 0);
|
||||
setParams.setMaxpool(kernel_size, pad, stride);
|
||||
}
|
||||
else if (layer_type == "avgpool")
|
||||
{
|
||||
setParams.setAvgpool();
|
||||
}
|
||||
else if (layer_type == "softmax")
|
||||
{
|
||||
int groups = getParam<int>(layer_params, "groups", 1);
|
||||
if (groups != 1)
|
||||
CV_Error(Error::StsNotImplemented, "Softmax from Darknet with groups != 1");
|
||||
setParams.setSoftmax();
|
||||
}
|
||||
else if (layer_type == "route")
|
||||
{
|
||||
std::string bottom_layers = getParam<std::string>(layer_params, "layers", "");
|
||||
|
||||
+11
-5
@@ -66,6 +66,15 @@ static bool DNN_DISABLE_MEMORY_OPTIMIZATIONS = utils::getConfigurationParameterB
|
||||
static bool DNN_OPENCL_ALLOW_ALL_DEVICES = utils::getConfigurationParameterBool("OPENCV_DNN_OPENCL_ALLOW_ALL_DEVICES", false);
|
||||
#endif
|
||||
|
||||
static int PARAM_DNN_BACKEND_DEFAULT = (int)utils::getConfigurationParameterSizeT("OPENCV_DNN_BACKEND_DEFAULT",
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
(size_t)DNN_BACKEND_INFERENCE_ENGINE
|
||||
#else
|
||||
(size_t)DNN_BACKEND_OPENCV
|
||||
#endif
|
||||
);
|
||||
|
||||
|
||||
using std::vector;
|
||||
using std::map;
|
||||
using std::make_pair;
|
||||
@@ -851,11 +860,8 @@ struct Net::Impl
|
||||
CV_TRACE_FUNCTION();
|
||||
|
||||
if (preferableBackend == DNN_BACKEND_DEFAULT)
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
preferableBackend = DNN_BACKEND_INFERENCE_ENGINE;
|
||||
#else
|
||||
preferableBackend = DNN_BACKEND_OPENCV;
|
||||
#endif
|
||||
preferableBackend = (Backend)PARAM_DNN_BACKEND_DEFAULT;
|
||||
|
||||
CV_Assert(preferableBackend != DNN_BACKEND_OPENCV ||
|
||||
preferableTarget == DNN_TARGET_CPU ||
|
||||
preferableTarget == DNN_TARGET_OPENCL ||
|
||||
|
||||
@@ -1641,6 +1641,27 @@ void TFImporter::populateNet(Net dstNet)
|
||||
connect(layer_id, dstNet, Pin(name), flattenId, 0);
|
||||
}
|
||||
}
|
||||
else if (type == "ClipByValue")
|
||||
{
|
||||
// op: "ClipByValue"
|
||||
// input: "input"
|
||||
// input: "mix"
|
||||
// input: "max"
|
||||
CV_Assert(layer.input_size() == 3);
|
||||
|
||||
Mat minValue = getTensorContent(getConstBlob(layer, value_id, 1));
|
||||
Mat maxValue = getTensorContent(getConstBlob(layer, value_id, 2));
|
||||
CV_Assert(minValue.total() == 1, minValue.type() == CV_32F,
|
||||
maxValue.total() == 1, maxValue.type() == CV_32F);
|
||||
|
||||
layerParams.set("min_value", minValue.at<float>(0));
|
||||
layerParams.set("max_value", maxValue.at<float>(0));
|
||||
|
||||
int id = dstNet.addLayer(name, "ReLU6", layerParams);
|
||||
layer_id[name] = id;
|
||||
|
||||
connect(layer_id, dstNet, parsePin(layer.input(0)), id, 0);
|
||||
}
|
||||
else if (type == "Abs" || type == "Tanh" || type == "Sigmoid" ||
|
||||
type == "Relu" || type == "Elu" ||
|
||||
type == "Identity" || type == "Relu6")
|
||||
|
||||
@@ -228,4 +228,9 @@ TEST(Test_Darknet, upsample)
|
||||
testDarknetLayer("upsample");
|
||||
}
|
||||
|
||||
TEST(Test_Darknet, avgpool_softmax)
|
||||
{
|
||||
testDarknetLayer("avgpool_softmax");
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
@@ -415,6 +415,7 @@ TEST(Test_TensorFlow, softmax)
|
||||
TEST(Test_TensorFlow, relu6)
|
||||
{
|
||||
runTensorFlowNet("keras_relu6");
|
||||
runTensorFlowNet("keras_relu6", DNN_TARGET_CPU, /*hasText*/ true);
|
||||
}
|
||||
|
||||
TEST(Test_TensorFlow, keras_mobilenet_head)
|
||||
|
||||
Reference in New Issue
Block a user