add square layer

pull/21246/head
cqn2219076254 3 years ago
parent d24befa0bc
commit 252ce0b581
  1. 22
      modules/dnn/src/tensorflow/tf_importer.cpp
  2. 7
      modules/dnn/test/test_tf_importer.cpp

@ -598,7 +598,7 @@ private:
void parseLeakyRelu (tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams);
void parseActivation (tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams);
void parseExpandDims (tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams);
void parseSquare (tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams);
void parseCustomLayer (tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams);
};
@ -676,6 +676,7 @@ const TFImporter::DispatchMap TFImporter::buildDispatchMap()
dispatch["Abs"] = dispatch["Tanh"] = dispatch["Sigmoid"] = dispatch["Relu"] =
dispatch["Elu"] = dispatch["Exp"] = dispatch["Identity"] = dispatch["Relu6"] = &TFImporter::parseActivation;
dispatch["ExpandDims"] = &TFImporter::parseExpandDims;
dispatch["Square"] = &TFImporter::parseSquare;
return dispatch;
}
@ -1252,6 +1253,25 @@ void TFImporter::parseExpandDims(tensorflow::GraphDef& net, const tensorflow::No
}
}
// "Square"
void TFImporter::parseSquare(tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams)
{
const std::string& name = layer.name();
const int num_inputs = layer.input_size();
CV_CheckEQ(num_inputs, 1, "");
int id;
layerParams.set("operation", "prod");
id = dstNet.addLayer(name, "Eltwise", layerParams);
layer_id[name] = id;
Pin inp = parsePin(layer.input(0));
connect(layer_id, dstNet, inp, id, 0);
connect(layer_id, dstNet, inp, id, 1);
}
// "Flatten" "Squeeze"
void TFImporter::parseFlatten(tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams)
{

@ -670,6 +670,13 @@ TEST_P(Test_TensorFlow_layers, batch_matmul)
runTensorFlowNet("batch_matmul");
}
TEST_P(Test_TensorFlow_layers, square)
{
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
runTensorFlowNet("square");
}
TEST_P(Test_TensorFlow_layers, reshape)
{
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)

Loading…
Cancel
Save