Merge pull request #19671 from SamFC10:sam-darknet

pull/19686/head^2
Alexander Alekhin 4 years ago
commit 358878caf7
  1. 31
      modules/dnn/src/darknet/darknet_io.cpp
  2. 5
      modules/dnn/test/test_darknet_importer.cpp

@ -558,6 +558,29 @@ namespace cv {
fused_layer_names.push_back(last_layer); fused_layer_names.push_back(last_layer);
} }
void setSAM(int from)
{
cv::dnn::LayerParams eltwise_param;
eltwise_param.name = "SAM-name";
eltwise_param.type = "Eltwise";
eltwise_param.set<std::string>("operation", "prod");
eltwise_param.set<std::string>("output_channels_mode", "same");
darknet::LayerParameter lp;
std::string layer_name = cv::format("sam_%d", layer_id);
lp.layer_name = layer_name;
lp.layer_type = eltwise_param.type;
lp.layerParams = eltwise_param;
lp.bottom_indexes.push_back(last_layer);
lp.bottom_indexes.push_back(fused_layer_names.at(from));
last_layer = layer_name;
net->layers.push_back(lp);
layer_id++;
fused_layer_names.push_back(last_layer);
}
void setUpsample(int scaleFactor) void setUpsample(int scaleFactor)
{ {
cv::dnn::LayerParams param; cv::dnn::LayerParams param;
@ -837,6 +860,14 @@ namespace cv {
from = from < 0 ? from + layers_counter : from; from = from < 0 ? from + layers_counter : from;
setParams.setScaleChannels(from); setParams.setScaleChannels(from);
} }
else if (layer_type == "sam")
{
std::string bottom_layer = getParam<std::string>(layer_params, "from", "");
CV_Assert(!bottom_layer.empty());
int from = std::atoi(bottom_layer.c_str());
from = from < 0 ? from + layers_counter : from;
setParams.setSAM(from);
}
else if (layer_type == "upsample") else if (layer_type == "upsample")
{ {
int scaleFactor = getParam<int>(layer_params, "stride", 1); int scaleFactor = getParam<int>(layer_params, "stride", 1);

@ -770,6 +770,11 @@ TEST_P(Test_Darknet_layers, relu)
testDarknetLayer("relu"); testDarknetLayer("relu");
} }
TEST_P(Test_Darknet_layers, sam)
{
testDarknetLayer("sam", true);
}
INSTANTIATE_TEST_CASE_P(/**/, Test_Darknet_layers, dnnBackendsAndTargets()); INSTANTIATE_TEST_CASE_P(/**/, Test_Darknet_layers, dnnBackendsAndTargets());
}} // namespace }} // namespace

Loading…
Cancel
Save