Skip to content
Permalink
Browse files
Merge pull request #17386 from l-bat:tf_clamp_subgraph
* Added ClipByValue subgraph

* Return const nodes
  • Loading branch information
l-bat committed May 26, 2020
1 parent 9e09828 commit ba3cf4760069b53b2388155e15b095e0897d9659
Showing 2 changed files with 21 additions and 0 deletions.
@@ -725,6 +725,21 @@ class PReLUSubgraph : public TFSubgraph
bool negativeScales;
};

class ClipByValueSubgraph : public TFSubgraph
{
public:
ClipByValueSubgraph()
{
int input = addNodeToMatch("");
int maxValue = addNodeToMatch("Const");
int minimum = addNodeToMatch("Minimum", input, maxValue);
int minValue = addNodeToMatch("Const");
addNodeToMatch("Maximum", minimum, minValue);

setFusedNode("ClipByValue", input, minValue, maxValue);
}
};

void simplifySubgraphs(tensorflow::GraphDef& net)
{
std::vector<Ptr<Subgraph> > subgraphs;
@@ -749,6 +764,7 @@ void simplifySubgraphs(tensorflow::GraphDef& net)
subgraphs.push_back(Ptr<Subgraph>(new PReLUSubgraph(false)));
subgraphs.push_back(Ptr<Subgraph>(new FlattenProdSubgraph()));
subgraphs.push_back(Ptr<Subgraph>(new ResizeBilinearSubgraphDown()));
subgraphs.push_back(Ptr<Subgraph>(new ClipByValueSubgraph()));

for (int i = 0; i < net.node_size(); ++i)
{
@@ -977,6 +977,11 @@ TEST_P(Test_TensorFlow_layers, tf2_dense)
runTensorFlowNet("tf2_dense");
}

TEST_P(Test_TensorFlow_layers, clip_by_value)
{
runTensorFlowNet("clip_by_value");
}

TEST_P(Test_TensorFlow_layers, tf2_prelu)
{
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)

0 comments on commit ba3cf47

Please sign in to comment.