Skip to content

Commit ba3cf47

Browse files
authored
Merge pull request opencv#17386 from l-bat:tf_clamp_subgraph
* Added ClipByValue subgraph * Return const nodes
1 parent 9e09828 commit ba3cf47

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

modules/dnn/src/tensorflow/tf_graph_simplifier.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,21 @@ class PReLUSubgraph : public TFSubgraph
725725
bool negativeScales;
726726
};
727727

728+
class ClipByValueSubgraph : public TFSubgraph
729+
{
730+
public:
731+
ClipByValueSubgraph()
732+
{
733+
int input = addNodeToMatch("");
734+
int maxValue = addNodeToMatch("Const");
735+
int minimum = addNodeToMatch("Minimum", input, maxValue);
736+
int minValue = addNodeToMatch("Const");
737+
addNodeToMatch("Maximum", minimum, minValue);
738+
739+
setFusedNode("ClipByValue", input, minValue, maxValue);
740+
}
741+
};
742+
728743
void simplifySubgraphs(tensorflow::GraphDef& net)
729744
{
730745
std::vector<Ptr<Subgraph> > subgraphs;
@@ -749,6 +764,7 @@ void simplifySubgraphs(tensorflow::GraphDef& net)
749764
subgraphs.push_back(Ptr<Subgraph>(new PReLUSubgraph(false)));
750765
subgraphs.push_back(Ptr<Subgraph>(new FlattenProdSubgraph()));
751766
subgraphs.push_back(Ptr<Subgraph>(new ResizeBilinearSubgraphDown()));
767+
subgraphs.push_back(Ptr<Subgraph>(new ClipByValueSubgraph()));
752768

753769
for (int i = 0; i < net.node_size(); ++i)
754770
{

modules/dnn/test/test_tf_importer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,11 @@ TEST_P(Test_TensorFlow_layers, tf2_dense)
977977
runTensorFlowNet("tf2_dense");
978978
}
979979

980+
TEST_P(Test_TensorFlow_layers, clip_by_value)
981+
{
982+
runTensorFlowNet("clip_by_value");
983+
}
984+
980985
TEST_P(Test_TensorFlow_layers, tf2_prelu)
981986
{
982987
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)

0 commit comments

Comments
 (0)