mirror of
https://github.com/opencv/opencv.git
synced 2026-07-21 19:33:03 +04:00
Compare commits
14 Commits
4.5.4
...
4.2.0-openvino
| Author | SHA1 | Date | |
|---|---|---|---|
| 4de7015cfd | |||
| d42d34e2ee | |||
| 04d4af1a6d | |||
| cb64fdabb5 | |||
| 8cb0a37336 | |||
| aae15a4efa | |||
| b61b146f0e | |||
| 905c551b7b | |||
| 7c4398a0f6 | |||
| b3eb24cd07 | |||
| 5b5c2093bb | |||
| 010cc2e58a | |||
| 2f23737e66 | |||
| 43cb28bdb5 |
@@ -7,7 +7,7 @@ copy or use the software.
|
||||
For Open Source Computer Vision Library
|
||||
(3-clause BSD License)
|
||||
|
||||
Copyright (C) 2000-2019, Intel Corporation, all rights reserved.
|
||||
Copyright (C) 2000-2020, Intel Corporation, all rights reserved.
|
||||
Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
|
||||
Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
|
||||
Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
|
||||
|
||||
@@ -94,9 +94,9 @@ endif()
|
||||
|
||||
if(INF_ENGINE_TARGET)
|
||||
if(NOT INF_ENGINE_RELEASE)
|
||||
message(WARNING "InferenceEngine version have not been set, 2019R3 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
|
||||
message(WARNING "InferenceEngine version has not been set, 2020.1 will be used by default. Set INF_ENGINE_RELEASE variable if you experience build errors.")
|
||||
endif()
|
||||
set(INF_ENGINE_RELEASE "2019030000" CACHE STRING "Force IE version, should be in form YYYYAABBCC (e.g. 2018R2.0.2 -> 2018020002)")
|
||||
set(INF_ENGINE_RELEASE "2020010000" CACHE STRING "Force IE version, should be in form YYYYAABBCC (e.g. 2020.1.0.2 -> 2020010002)")
|
||||
set_target_properties(${INF_ENGINE_TARGET} PROPERTIES
|
||||
INTERFACE_COMPILE_DEFINITIONS "HAVE_INF_ENGINE=1;INF_ENGINE_RELEASE=${INF_ENGINE_RELEASE}"
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define CV_VERSION_MAJOR 4
|
||||
#define CV_VERSION_MINOR 2
|
||||
#define CV_VERSION_REVISION 0
|
||||
#define CV_VERSION_STATUS ""
|
||||
#define CV_VERSION_STATUS "-openvino"
|
||||
|
||||
#define CVAUX_STR_EXP(__A) #__A
|
||||
#define CVAUX_STR(__A) CVAUX_STR_EXP(__A)
|
||||
|
||||
@@ -109,6 +109,22 @@ public:
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
static inline bool checkIETarget(Target target)
|
||||
{
|
||||
#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2019R3)
|
||||
// Lightweight detection
|
||||
const std::vector<std::string> devices = getCore().GetAvailableDevices();
|
||||
for (std::vector<std::string>::const_iterator i = devices.begin(); i != devices.end(); ++i)
|
||||
{
|
||||
if (std::string::npos != i->find("MYRIAD") && target == DNN_TARGET_MYRIAD)
|
||||
return true;
|
||||
else if (std::string::npos != i->find("FPGA") && target == DNN_TARGET_FPGA)
|
||||
return true;
|
||||
else if (std::string::npos != i->find("CPU") && target == DNN_TARGET_CPU)
|
||||
return true;
|
||||
else if (std::string::npos != i->find("GPU") && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
cv::dnn::Net net;
|
||||
cv::dnn::LayerParams lp;
|
||||
lp.set("kernel_size", 1);
|
||||
@@ -132,6 +148,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
// Copyright (C) 2020, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#include "graph_simplifier.hpp"
|
||||
|
||||
#include <queue>
|
||||
|
||||
namespace cv { namespace dnn {
|
||||
|
||||
Subgraph::~Subgraph() {}
|
||||
|
||||
int Subgraph::addNodeToMatch(const std::string& op, int input_0, int input_1,
|
||||
int input_2, int input_3)
|
||||
{
|
||||
int nodeInputs[] = {input_0, input_1, input_2, input_3};
|
||||
int numInputs = 0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
numInputs += (int)(nodeInputs[i] != -1);
|
||||
}
|
||||
return addNodeToMatch(op, std::vector<int>(&nodeInputs[0], &nodeInputs[0] + numInputs));
|
||||
}
|
||||
|
||||
int Subgraph::addNodeToMatch(const std::string& op, const std::vector<int>& inputs_)
|
||||
{
|
||||
for (int i = 0; i < inputs_.size(); ++i)
|
||||
{
|
||||
CV_Assert(inputs_[i] < (int)nodes.size());
|
||||
}
|
||||
nodes.push_back(op);
|
||||
inputs.push_back(inputs_);
|
||||
return nodes.size() - 1;
|
||||
}
|
||||
|
||||
void Subgraph::setFusedNode(const std::string& op, int input_0, int input_1,
|
||||
int input_2, int input_3, int input_4, int input_5)
|
||||
{
|
||||
int nodeInputs[] = {input_0, input_1, input_2, input_3, input_4, input_5};
|
||||
int numInputs = 0;
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
CV_Assert(nodeInputs[i] < (int)nodes.size());
|
||||
numInputs += (int)(nodeInputs[i] != -1);
|
||||
}
|
||||
setFusedNode(op, std::vector<int>(&nodeInputs[0], &nodeInputs[0] + numInputs));
|
||||
}
|
||||
|
||||
void Subgraph::setFusedNode(const std::string& op, const std::vector<int>& inputs_)
|
||||
{
|
||||
fusedNodeInputs = inputs_;
|
||||
fusedNodeOp = op;
|
||||
}
|
||||
|
||||
int Subgraph::getInputNodeId(const Ptr<ImportGraphWrapper>& net,
|
||||
const Ptr<ImportNodeWrapper>& node,
|
||||
int inpId)
|
||||
{
|
||||
CV_Assert(inpId < node->getNumInputs());
|
||||
std::string name = node->getInputName(inpId);
|
||||
// If operation produces several tensors, they are specified by index
|
||||
// after ':' character. In example, "input:0".
|
||||
name = name.substr(0, name.rfind(':'));
|
||||
const int numNodes = net->getNumNodes();
|
||||
for (int i = 0; i < numNodes; ++i)
|
||||
{
|
||||
if (net->getNodeName(i) == name)
|
||||
return i;
|
||||
}
|
||||
CV_Error(Error::StsParseError, "Input node with name " + name + " not found");
|
||||
}
|
||||
|
||||
bool Subgraph::match(const Ptr<ImportGraphWrapper>& net, int nodeId,
|
||||
std::vector<int>& matchedNodesIds,
|
||||
std::vector<int>& targetNodesIds)
|
||||
{
|
||||
matchedNodesIds.clear();
|
||||
targetNodesIds.clear();
|
||||
|
||||
std::queue<int> nodesToMatch;
|
||||
std::queue<int> targetNodes;
|
||||
nodesToMatch.push(nodeId);
|
||||
targetNodes.push(nodes.size() - 1);
|
||||
while (!nodesToMatch.empty())
|
||||
{
|
||||
int nodeToMatch = nodesToMatch.front();
|
||||
int targetNodeId = targetNodes.front();
|
||||
nodesToMatch.pop();
|
||||
targetNodes.pop();
|
||||
|
||||
if (std::find(matchedNodesIds.begin(), matchedNodesIds.end(), nodeToMatch) !=
|
||||
matchedNodesIds.end())
|
||||
continue;
|
||||
|
||||
const Ptr<ImportNodeWrapper> node = net->getNode(nodeToMatch);
|
||||
if (node->getType() != nodes[targetNodeId])
|
||||
return false;
|
||||
|
||||
std::vector<int>& inputNodes = inputs[targetNodeId];
|
||||
if (inputNodes.size() != node->getNumInputs())
|
||||
return false;
|
||||
|
||||
for (int j = 0; j < inputNodes.size(); ++j)
|
||||
{
|
||||
if (nodes[inputNodes[j]].empty()) // Unknown input node type.
|
||||
continue;
|
||||
nodeId = getInputNodeId(net, node, j);
|
||||
const Ptr<ImportNodeWrapper> inpNode = net->getNode(nodeId);
|
||||
if (inpNode->getType() != "Const")
|
||||
{
|
||||
nodesToMatch.push(nodeId);
|
||||
targetNodes.push(inputNodes[j]);
|
||||
}
|
||||
else if (nodes[inputNodes[j]] != "Const")
|
||||
return false;
|
||||
}
|
||||
matchedNodesIds.push_back(nodeToMatch);
|
||||
targetNodesIds.push_back(targetNodeId);
|
||||
}
|
||||
|
||||
const int n = matchedNodesIds.size();
|
||||
std::vector<std::pair<int, int> > elements(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
elements[i] = std::make_pair(matchedNodesIds[i], targetNodesIds[i]);
|
||||
std::sort(elements.begin(), elements.end());
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
matchedNodesIds[i] = elements[i].first;
|
||||
targetNodesIds[i] = elements[i].second;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Subgraph::replace(const Ptr<ImportGraphWrapper>& net, const std::vector<int>& matchedNodesIds,
|
||||
const std::vector<int>& targetNodesIds)
|
||||
{
|
||||
// Extract names of input nodes.
|
||||
std::vector<std::string> inputsNames(fusedNodeInputs.size());
|
||||
for (int i = 0; i < fusedNodeInputs.size(); ++i)
|
||||
{
|
||||
std::string inpName;
|
||||
// Find input node name looking at inputs of fused nodes.
|
||||
for (int j = 0; j < matchedNodesIds.size() && inpName.empty(); ++j)
|
||||
{
|
||||
Ptr<ImportNodeWrapper> node = net->getNode(matchedNodesIds[j]);
|
||||
std::vector<int>& inpIndices = inputs[targetNodesIds[j]];
|
||||
|
||||
CV_Assert(node->getNumInputs() == inpIndices.size());
|
||||
for (int k = 0; k < inpIndices.size(); ++k)
|
||||
{
|
||||
if (inpIndices[k] == fusedNodeInputs[i])
|
||||
{
|
||||
inpName = node->getInputName(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CV_Assert(!inpName.empty());
|
||||
inputsNames[i] = inpName;
|
||||
}
|
||||
|
||||
// Remove matched nodes except the last one. Indices in ascending order are expected.
|
||||
Ptr<ImportNodeWrapper> node = net->getNode(matchedNodesIds.back());
|
||||
for (int i = matchedNodesIds.size() - 2; i >= 0; --i)
|
||||
net->removeNode(matchedNodesIds[i]);
|
||||
|
||||
// Modify the last node to be a fused one.
|
||||
node->setType(fusedNodeOp);
|
||||
node->setInputNames(inputsNames);
|
||||
|
||||
std::vector<Ptr<ImportNodeWrapper> > inputNodes(inputsNames.size());
|
||||
for (int i = 0; i < inputsNames.size(); ++i)
|
||||
{
|
||||
inputNodes[i] = net->getNode(getInputNodeId(net, node, i));
|
||||
}
|
||||
finalize(net, node, inputNodes);
|
||||
}
|
||||
|
||||
void Subgraph::finalize(const Ptr<ImportGraphWrapper>& net,
|
||||
const Ptr<ImportNodeWrapper>& fusedNode,
|
||||
std::vector<Ptr<ImportNodeWrapper> >& inputs) {}
|
||||
|
||||
void simplifySubgraphs(const Ptr<ImportGraphWrapper>& net,
|
||||
const std::vector<Ptr<Subgraph> >& patterns)
|
||||
{
|
||||
int numNodes = net->getNumNodes();
|
||||
std::vector<int> matchedNodesIds, targetNodesIds;
|
||||
for (int i = 0; i < numNodes; ++i)
|
||||
{
|
||||
for (int j = 0; j < patterns.size(); ++j)
|
||||
{
|
||||
if (patterns[j]->match(net, i, matchedNodesIds, targetNodesIds))
|
||||
{
|
||||
patterns[j]->replace(net, matchedNodesIds, targetNodesIds);
|
||||
numNodes -= matchedNodesIds.size() - 1; // #matchedNodes removed and one added.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace cv::dnn
|
||||
@@ -0,0 +1,100 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
// Copyright (C) 2020, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
|
||||
#ifndef __OPENCV_DNN_GRAPH_SIMPLIFIER_HPP__
|
||||
#define __OPENCV_DNN_GRAPH_SIMPLIFIER_HPP__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
namespace cv { namespace dnn {
|
||||
|
||||
class ImportNodeWrapper
|
||||
{
|
||||
public:
|
||||
virtual ~ImportNodeWrapper() {};
|
||||
|
||||
virtual int getNumInputs() const = 0;
|
||||
|
||||
virtual std::string getInputName(int idx) const = 0;
|
||||
|
||||
virtual std::string getType() const = 0;
|
||||
|
||||
virtual void setType(const std::string& type) = 0;
|
||||
|
||||
virtual void setInputNames(const std::vector<std::string>& inputs) = 0;
|
||||
};
|
||||
|
||||
class ImportGraphWrapper
|
||||
{
|
||||
public:
|
||||
virtual ~ImportGraphWrapper() {};
|
||||
|
||||
virtual Ptr<ImportNodeWrapper> getNode(int idx) const = 0;
|
||||
|
||||
virtual int getNumNodes() const = 0;
|
||||
|
||||
virtual std::string getNodeName(int idx) const = 0;
|
||||
|
||||
virtual void removeNode(int idx) = 0;
|
||||
};
|
||||
|
||||
class Subgraph // Interface to match and replace subgraphs.
|
||||
{
|
||||
public:
|
||||
virtual ~Subgraph();
|
||||
|
||||
// Add a node to be matched in the origin graph. Specify ids of nodes that
|
||||
// are expected to be inputs. Returns id of a newly added node.
|
||||
// TODO: Replace inputs to std::vector<int> in C++11
|
||||
int addNodeToMatch(const std::string& op, int input_0 = -1, int input_1 = -1,
|
||||
int input_2 = -1, int input_3 = -1);
|
||||
|
||||
int addNodeToMatch(const std::string& op, const std::vector<int>& inputs_);
|
||||
|
||||
// Specify resulting node. All the matched nodes in subgraph excluding
|
||||
// input nodes will be fused into this single node.
|
||||
// TODO: Replace inputs to std::vector<int> in C++11
|
||||
void setFusedNode(const std::string& op, int input_0 = -1, int input_1 = -1,
|
||||
int input_2 = -1, int input_3 = -1, int input_4 = -1,
|
||||
int input_5 = -1);
|
||||
|
||||
void setFusedNode(const std::string& op, const std::vector<int>& inputs_);
|
||||
|
||||
static int getInputNodeId(const Ptr<ImportGraphWrapper>& net,
|
||||
const Ptr<ImportNodeWrapper>& node,
|
||||
int inpId);
|
||||
|
||||
// Match TensorFlow subgraph starting from <nodeId> with a set of nodes to be fused.
|
||||
// Const nodes are skipped during matching. Returns true if nodes are matched and can be fused.
|
||||
virtual bool match(const Ptr<ImportGraphWrapper>& net, int nodeId,
|
||||
std::vector<int>& matchedNodesIds,
|
||||
std::vector<int>& targetNodesIds);
|
||||
|
||||
// Fuse matched subgraph.
|
||||
void replace(const Ptr<ImportGraphWrapper>& net, const std::vector<int>& matchedNodesIds,
|
||||
const std::vector<int>& targetNodesIds);
|
||||
|
||||
virtual void finalize(const Ptr<ImportGraphWrapper>& net,
|
||||
const Ptr<ImportNodeWrapper>& fusedNode,
|
||||
std::vector<Ptr<ImportNodeWrapper> >& inputs);
|
||||
|
||||
private:
|
||||
std::vector<std::string> nodes; // Nodes to be matched in the origin graph.
|
||||
std::vector<std::vector<int> > inputs; // Connections of an every node to it's inputs.
|
||||
|
||||
std::string fusedNodeOp; // Operation name of resulting fused node.
|
||||
std::vector<int> fusedNodeInputs; // Inputs of fused node.
|
||||
};
|
||||
|
||||
void simplifySubgraphs(const Ptr<ImportGraphWrapper>& net,
|
||||
const std::vector<Ptr<Subgraph> >& patterns);
|
||||
|
||||
}} // namespace dnn, namespace cv
|
||||
|
||||
#endif // __OPENCV_DNN_GRAPH_SIMPLIFIER_HPP__
|
||||
@@ -168,21 +168,26 @@ void InfEngineNgraphNet::init(Target targetId)
|
||||
{
|
||||
if (!hasNetOwner)
|
||||
{
|
||||
if (targetId == DNN_TARGET_OPENCL_FP16 || targetId == DNN_TARGET_MYRIAD) {
|
||||
if (targetId == DNN_TARGET_OPENCL_FP16)
|
||||
{
|
||||
auto nodes = ngraph_function->get_ordered_ops();
|
||||
for (auto& node : nodes) {
|
||||
for (auto& node : nodes)
|
||||
{
|
||||
auto parameter = std::dynamic_pointer_cast<ngraph::op::Parameter>(node);
|
||||
if (parameter && parameter->get_element_type() == ngraph::element::f32) {
|
||||
if (parameter && parameter->get_element_type() == ngraph::element::f32)
|
||||
{
|
||||
parameter->set_element_type(ngraph::element::f16);
|
||||
}
|
||||
auto constant = std::dynamic_pointer_cast<ngraph::op::Constant>(node);
|
||||
if (constant && constant->get_element_type() == ngraph::element::f32) {
|
||||
auto data = constant->get_vector<float>();
|
||||
std::vector<ngraph::float16> new_data(data.size());
|
||||
for (size_t i = 0; i < data.size(); ++i) {
|
||||
new_data[i] = ngraph::float16(data[i]);
|
||||
}
|
||||
auto new_const = std::make_shared<ngraph::op::Constant>(ngraph::element::f16, constant->get_shape(), new_data);
|
||||
if (constant && constant->get_element_type() == ngraph::element::f32)
|
||||
{
|
||||
const float* floatsData = constant->get_data_ptr<float>();
|
||||
size_t total = ngraph::shape_size(constant->get_shape());
|
||||
Mat floats(1, total, CV_32F, (void*)floatsData);
|
||||
Mat halfs;
|
||||
cv::convertFp16(floats, halfs);
|
||||
|
||||
auto new_const = std::make_shared<ngraph::op::Constant>(ngraph::element::f16, constant->get_shape(), halfs.data);
|
||||
new_const->set_friendly_name(constant->get_friendly_name());
|
||||
ngraph::replace_node(constant, new_const);
|
||||
}
|
||||
@@ -318,7 +323,14 @@ void InfEngineNgraphNet::initPlugin(InferenceEngine::CNNNetwork& net)
|
||||
}
|
||||
// Some of networks can work without a library of extra layers.
|
||||
// OpenCV fallbacks as extensions.
|
||||
ie.AddExtension(std::make_shared<InfEngineExtension>(), "CPU");
|
||||
try
|
||||
{
|
||||
ie.AddExtension(std::make_shared<InfEngineExtension>(), "CPU");
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
CV_LOG_INFO(NULL, "DNN-IE: Can't register OpenCV custom layers extension: " << e.what());
|
||||
}
|
||||
#ifndef _WIN32
|
||||
// Limit the number of CPU threads.
|
||||
if (device_name == "CPU")
|
||||
|
||||
@@ -114,7 +114,8 @@ public:
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_CUDA ||
|
||||
(backendId == DNN_BACKEND_HALIDE && haveHalide() && axis == 1 && !padding) || // By channels
|
||||
((backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && haveInfEngine() && !padding) ||
|
||||
(backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && haveInfEngine() && !padding) ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH ||
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan() && !padding);
|
||||
}
|
||||
|
||||
@@ -351,14 +352,45 @@ public:
|
||||
virtual Ptr<BackendNode> initNgraph(const std::vector<Ptr<BackendWrapper> >& inputs,
|
||||
const std::vector<Ptr<BackendNode> >& nodes) CV_OVERRIDE
|
||||
{
|
||||
InferenceEngine::DataPtr data = ngraphDataNode(inputs[0]);
|
||||
const int numDims = data->getDims().size();
|
||||
const int cAxis = clamp(axis, numDims);
|
||||
std::vector<size_t> maxDims(numDims, 0);
|
||||
|
||||
CV_Assert(inputs.size() == nodes.size());
|
||||
ngraph::NodeVector inp_nodes;
|
||||
for (auto& node : nodes) {
|
||||
inp_nodes.push_back(node.dynamicCast<InfEngineNgraphNode>()->node);
|
||||
}
|
||||
for (int i = 0; i < nodes.size(); ++i)
|
||||
{
|
||||
inp_nodes.push_back(nodes[i].dynamicCast<InfEngineNgraphNode>()->node);
|
||||
|
||||
InferenceEngine::DataPtr data = ngraphDataNode(inputs[0]);
|
||||
auto concat = std::make_shared<ngraph::op::Concat>(inp_nodes, clamp(axis, data->getDims().size()));
|
||||
std::vector<size_t> inpShape = ngraphDataNode(inputs[i])->getDims();
|
||||
for (int i = 0; i < numDims; ++i)
|
||||
maxDims[i] = std::max(maxDims[i], inpShape[i]);
|
||||
}
|
||||
for (int i = 0; i < inp_nodes.size(); ++i)
|
||||
{
|
||||
bool needPadding = false;
|
||||
std::vector<size_t> inpShape = ngraphDataNode(inputs[i])->getDims();
|
||||
std::vector<int64_t> begins(inpShape.size(), 0), ends(inpShape.size(), 0);
|
||||
for (int j = 0; j < inpShape.size(); ++j)
|
||||
{
|
||||
if (j != cAxis && inpShape[j] != maxDims[j])
|
||||
{
|
||||
needPadding = true;
|
||||
begins[j] = static_cast<int64_t>((maxDims[j] - inpShape[j]) / 2);
|
||||
ends[j] = static_cast<int64_t>(maxDims[j] - inpShape[j] - begins[j]);
|
||||
}
|
||||
}
|
||||
if (needPadding)
|
||||
{
|
||||
inp_nodes[i] = std::make_shared<ngraph::op::v1::Pad>(
|
||||
inp_nodes[i],
|
||||
std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{begins.size()}, begins.data()),
|
||||
std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{ends.size()}, ends.data()),
|
||||
ngraph::op::PadMode::CONSTANT);
|
||||
}
|
||||
}
|
||||
auto concat = std::make_shared<ngraph::op::Concat>(inp_nodes, cAxis);
|
||||
return Ptr<BackendNode>(new InfEngineNgraphNode(concat));
|
||||
}
|
||||
#endif // HAVE_DNN_NGRAPH
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
return bias == (int)bias;
|
||||
}
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) {
|
||||
return type == CHANNEL_NRM && bias == (int)bias;
|
||||
return bias == (int)bias;
|
||||
}
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_CUDA ||
|
||||
@@ -471,7 +471,15 @@ public:
|
||||
alphaSize *= (type == SPATIAL_NRM ? size*size : size);
|
||||
|
||||
auto& ieInpNode = nodes[0].dynamicCast<InfEngineNgraphNode>()->node;
|
||||
auto lrn = std::make_shared<ngraph::op::LRN>(ieInpNode, (double)alphaSize, (double)beta, (double)bias, (size_t)size);
|
||||
std::vector<int64_t> axes;
|
||||
if (type != SPATIAL_NRM) {
|
||||
axes = {1};
|
||||
} else {
|
||||
axes.resize(ieInpNode->get_shape().size() - 2);
|
||||
std::iota(axes.begin(), axes.end(), 2);
|
||||
}
|
||||
auto ngraph_axes = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, ngraph::Shape{axes.size()}, axes.data());
|
||||
auto lrn = std::make_shared<ngraph::op::LRN>(ieInpNode, ngraph_axes, alphaSize, beta, bias, size);
|
||||
return Ptr<BackendNode>(new InfEngineNgraphNode(lrn));
|
||||
}
|
||||
#endif // HAVE_DNN_NGRAPH
|
||||
|
||||
@@ -119,8 +119,10 @@ public:
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
return !zeroDev && (preferableTarget != DNN_TARGET_MYRIAD || eps <= 1e-7f);
|
||||
else if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
return true;
|
||||
else
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return backendId == DNN_BACKEND_OPENCV;
|
||||
|
||||
@@ -75,7 +75,10 @@ public:
|
||||
if (pnorm != 2)
|
||||
return false;
|
||||
|
||||
return preferableTarget == DNN_TARGET_MYRIAD ? !acrossSpatial : startAxis == 1;
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && preferableTarget == DNN_TARGET_MYRIAD)
|
||||
return !acrossSpatial;
|
||||
|
||||
return startAxis == 1;
|
||||
}
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
(backendId == DNN_BACKEND_CUDA && (pnorm == 1 || pnorm == 2));
|
||||
@@ -373,7 +376,6 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
// weight->get_shape().size() > 1 ~> channel_shared = false
|
||||
weight = std::make_shared<ngraph::op::Constant>(
|
||||
ngraph::element::f32, ngraph::Shape(shape), blobs[0].data);
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
else if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) {
|
||||
return type != STOCHASTIC;
|
||||
return !computeMaxIdx && type != STOCHASTIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
// Copyright (C) 2020, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
|
||||
#include "../precomp.hpp"
|
||||
|
||||
#include "../graph_simplifier.hpp"
|
||||
#include "onnx_graph_simplifier.hpp"
|
||||
|
||||
#include <queue>
|
||||
|
||||
namespace cv { namespace dnn {
|
||||
CV__DNN_INLINE_NS_BEGIN
|
||||
|
||||
// This wrapper can behave differently for fake input nodes and real graph nodes.
|
||||
class ONNXNodeWrapper : public ImportNodeWrapper
|
||||
{
|
||||
public:
|
||||
ONNXNodeWrapper(opencv_onnx::NodeProto* _node = 0) : node(_node) {}
|
||||
|
||||
virtual int getNumInputs() const CV_OVERRIDE
|
||||
{
|
||||
return node ? node->input_size() : 0;
|
||||
}
|
||||
|
||||
virtual std::string getInputName(int idx) const CV_OVERRIDE
|
||||
{
|
||||
CV_Assert_N(node, idx < node->input_size());
|
||||
return node->input(idx);
|
||||
}
|
||||
|
||||
virtual std::string getType() const CV_OVERRIDE
|
||||
{
|
||||
return node ? node->op_type() : "";
|
||||
}
|
||||
|
||||
virtual void setType(const std::string& type) CV_OVERRIDE
|
||||
{
|
||||
CV_Assert(node);
|
||||
node->set_op_type(type);
|
||||
}
|
||||
|
||||
virtual void setInputNames(const std::vector<std::string>& inputs) CV_OVERRIDE
|
||||
{
|
||||
CV_Assert(node);
|
||||
node->clear_input();
|
||||
for (int i = 0; i < inputs.size(); ++i)
|
||||
node->add_input(inputs[i]);
|
||||
}
|
||||
|
||||
opencv_onnx::NodeProto* node;
|
||||
};
|
||||
|
||||
// ONNX graph's inputs are separate from nodes so we index them before the rest of nodes.
|
||||
class ONNXGraphWrapper : public ImportGraphWrapper
|
||||
{
|
||||
public:
|
||||
ONNXGraphWrapper(opencv_onnx::GraphProto& _net) : net(_net)
|
||||
{
|
||||
numInputs = net.input_size();
|
||||
}
|
||||
|
||||
virtual Ptr<ImportNodeWrapper> getNode(int idx) const CV_OVERRIDE
|
||||
{
|
||||
opencv_onnx::NodeProto* node = 0;
|
||||
if (idx >= numInputs)
|
||||
node = net.mutable_node(idx - numInputs);
|
||||
return makePtr<ONNXNodeWrapper>(node);
|
||||
}
|
||||
|
||||
virtual int getNumNodes() const CV_OVERRIDE
|
||||
{
|
||||
return numInputs + net.node_size();
|
||||
}
|
||||
|
||||
virtual std::string getNodeName(int idx) const CV_OVERRIDE
|
||||
{
|
||||
if (idx < numInputs)
|
||||
return net.input(idx).name();
|
||||
else
|
||||
return net.node(idx - numInputs).output(0);
|
||||
}
|
||||
|
||||
virtual void removeNode(int idx) CV_OVERRIDE
|
||||
{
|
||||
CV_Assert(idx >= numInputs);
|
||||
net.mutable_node()->DeleteSubrange(idx - numInputs, 1);
|
||||
}
|
||||
|
||||
private:
|
||||
int numInputs;
|
||||
opencv_onnx::GraphProto& net;
|
||||
};
|
||||
|
||||
class SoftMaxSubgraph : public Subgraph
|
||||
{
|
||||
public:
|
||||
SoftMaxSubgraph() : axis(1)
|
||||
{
|
||||
int input = addNodeToMatch("");
|
||||
int inpExp = addNodeToMatch("Exp", input);
|
||||
int sum = addNodeToMatch("ReduceSum", inpExp);
|
||||
addNodeToMatch("Div", inpExp, sum);
|
||||
setFusedNode("Softmax", input);
|
||||
}
|
||||
|
||||
virtual bool match(const Ptr<ImportGraphWrapper>& net, int nodeId,
|
||||
std::vector<int>& matchedNodesIds,
|
||||
std::vector<int>& targetNodesIds) CV_OVERRIDE
|
||||
{
|
||||
if (Subgraph::match(net, nodeId, matchedNodesIds, targetNodesIds))
|
||||
{
|
||||
Ptr<ImportNodeWrapper> sum = net->getNode(matchedNodesIds[1]);
|
||||
opencv_onnx::NodeProto* node = sum.dynamicCast<ONNXNodeWrapper>()->node;
|
||||
|
||||
for (int i = 0; i < node->attribute_size(); i++)
|
||||
{
|
||||
opencv_onnx::AttributeProto attr = node->attribute(i);
|
||||
if (attr.name() != "axes")
|
||||
continue;
|
||||
if (attr.ints_size() != 1)
|
||||
CV_Error(Error::StsNotImplemented, format("Unexpected number of axes: %d", attr.ints_size()));
|
||||
axis = attr.ints(0);
|
||||
return true;
|
||||
}
|
||||
CV_Error(Error::StsNotImplemented, "Missed axes attribute");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void finalize(const Ptr<ImportGraphWrapper>&,
|
||||
const Ptr<ImportNodeWrapper>& fusedNode,
|
||||
std::vector<Ptr<ImportNodeWrapper> >&) CV_OVERRIDE
|
||||
{
|
||||
opencv_onnx::NodeProto* node = fusedNode.dynamicCast<ONNXNodeWrapper>()->node;
|
||||
opencv_onnx::AttributeProto* attr = node->add_attribute();
|
||||
attr->set_name("axis");
|
||||
attr->set_i(axis);
|
||||
}
|
||||
|
||||
private:
|
||||
int axis;
|
||||
};
|
||||
|
||||
void simplifySubgraphs(opencv_onnx::GraphProto& net)
|
||||
{
|
||||
std::vector<Ptr<Subgraph> > subgraphs;
|
||||
subgraphs.push_back(makePtr<SoftMaxSubgraph>());
|
||||
|
||||
simplifySubgraphs(Ptr<ImportGraphWrapper>(new ONNXGraphWrapper(net)), subgraphs);
|
||||
}
|
||||
|
||||
CV__DNN_INLINE_NS_END
|
||||
}} // namespace cv::dnn
|
||||
@@ -0,0 +1,30 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
// Copyright (C) 2020, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
|
||||
#ifndef __OPENCV_DNN_ONNX_SIMPLIFIER_HPP__
|
||||
#define __OPENCV_DNN_ONNX_SIMPLIFIER_HPP__
|
||||
|
||||
#include "../precomp.hpp"
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 5
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsuggest-override"
|
||||
#endif
|
||||
#include "opencv-onnx.pb.h"
|
||||
#if defined(__GNUC__) && __GNUC__ >= 5
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
namespace cv { namespace dnn {
|
||||
CV__DNN_INLINE_NS_BEGIN
|
||||
|
||||
void simplifySubgraphs(opencv_onnx::GraphProto& net);
|
||||
|
||||
CV__DNN_INLINE_NS_END
|
||||
}} // namespace dnn, namespace cv
|
||||
|
||||
#endif // __OPENCV_DNN_ONNX_SIMPLIFIER_HPP__
|
||||
@@ -26,6 +26,8 @@
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include "onnx_graph_simplifier.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace dnn {
|
||||
CV__DNN_INLINE_NS_BEGIN
|
||||
@@ -326,6 +328,9 @@ void ONNXImporter::populateNet(Net dstNet)
|
||||
{
|
||||
CV_Assert(model_proto.has_graph());
|
||||
opencv_onnx::GraphProto graph_proto = model_proto.graph();
|
||||
|
||||
simplifySubgraphs(graph_proto);
|
||||
|
||||
std::map<std::string, Mat> constBlobs = getGraphTensors(graph_proto);
|
||||
// List of internal blobs shapes.
|
||||
std::map<std::string, MatShape> outShapes;
|
||||
|
||||
@@ -564,16 +564,65 @@ static std::map<std::string, InferenceEngine::InferenceEnginePluginPtr>& getShar
|
||||
return sharedPlugins;
|
||||
}
|
||||
#else
|
||||
InferenceEngine::Core& getCore()
|
||||
static bool init_IE_plugins()
|
||||
{
|
||||
// load and hold IE plugins
|
||||
static InferenceEngine::Core* init_core = new InferenceEngine::Core(); // 'delete' is never called
|
||||
(void)init_core->GetAvailableDevices();
|
||||
return true;
|
||||
}
|
||||
static InferenceEngine::Core& create_IE_Core_instance()
|
||||
{
|
||||
static InferenceEngine::Core core;
|
||||
return core;
|
||||
}
|
||||
static InferenceEngine::Core& create_IE_Core_pointer()
|
||||
{
|
||||
// load and hold IE plugins
|
||||
static InferenceEngine::Core* core = new InferenceEngine::Core(); // 'delete' is never called
|
||||
return *core;
|
||||
}
|
||||
InferenceEngine::Core& getCore()
|
||||
{
|
||||
// to make happy memory leak tools use:
|
||||
// - OPENCV_DNN_INFERENCE_ENGINE_HOLD_PLUGINS=0
|
||||
// - OPENCV_DNN_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND=0
|
||||
static bool param_DNN_INFERENCE_ENGINE_HOLD_PLUGINS = utils::getConfigurationParameterBool("OPENCV_DNN_INFERENCE_ENGINE_HOLD_PLUGINS", true);
|
||||
static bool init_IE_plugins_ = param_DNN_INFERENCE_ENGINE_HOLD_PLUGINS && init_IE_plugins(); CV_UNUSED(init_IE_plugins_);
|
||||
|
||||
static bool param_DNN_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND =
|
||||
utils::getConfigurationParameterBool("OPENCV_DNN_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND",
|
||||
#ifdef _WIN32
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
);
|
||||
static InferenceEngine::Core& core = param_DNN_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND
|
||||
? create_IE_Core_pointer()
|
||||
: create_IE_Core_instance();
|
||||
return core;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(OPENCV_DNN_IE_VPU_TYPE_DEFAULT)
|
||||
static bool detectMyriadX_()
|
||||
{
|
||||
#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2019R3)
|
||||
// Lightweight detection
|
||||
InferenceEngine::Core& ie = getCore();
|
||||
const std::vector<std::string> devices = ie.GetAvailableDevices();
|
||||
for (std::vector<std::string>::const_iterator i = devices.begin(); i != devices.end(); ++i)
|
||||
{
|
||||
if (i->find("MYRIAD") != std::string::npos)
|
||||
{
|
||||
const std::string name = ie.GetMetric(*i, METRIC_KEY(FULL_DEVICE_NAME)).as<std::string>();
|
||||
CV_LOG_INFO(NULL, "Myriad device: " << name);
|
||||
return name.find("MyriadX") != std::string::npos || name.find("Myriad X") != std::string::npos;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
InferenceEngine::Builder::Network builder("");
|
||||
InferenceEngine::idx_t inpId = builder.addLayer(
|
||||
InferenceEngine::Builder::InputLayer().setPort(InferenceEngine::Port({1})));
|
||||
@@ -634,6 +683,7 @@ static bool detectMyriadX_()
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
#endif // !defined(OPENCV_DNN_IE_VPU_TYPE_DEFAULT)
|
||||
|
||||
@@ -723,7 +773,14 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::CNNNetwork& net)
|
||||
// Some of networks can work without a library of extra layers.
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2019R1)
|
||||
// OpenCV fallbacks as extensions.
|
||||
ie.AddExtension(std::make_shared<InfEngineExtension>(), "CPU");
|
||||
try
|
||||
{
|
||||
ie.AddExtension(std::make_shared<InfEngineExtension>(), "CPU");
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
CV_LOG_INFO(NULL, "DNN-IE: Can't register OpenCV custom layers extension: " << e.what());
|
||||
}
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
// Limit the number of CPU threads.
|
||||
@@ -1052,8 +1109,14 @@ void resetMyriadDevice()
|
||||
#if INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1)
|
||||
getSharedPlugins().erase("MYRIAD");
|
||||
#else
|
||||
// To unregister both "MYRIAD" and "HETERO:MYRIAD,CPU" plugins
|
||||
getCore() = InferenceEngine::Core();
|
||||
// Unregister both "MYRIAD" and "HETERO:MYRIAD,CPU" plugins
|
||||
InferenceEngine::Core& ie = getCore();
|
||||
try
|
||||
{
|
||||
ie.UnregisterPlugin("MYRIAD");
|
||||
ie.UnregisterPlugin("HETERO");
|
||||
}
|
||||
catch (...) {}
|
||||
#endif
|
||||
#endif // HAVE_INF_ENGINE
|
||||
}
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
#define INF_ENGINE_RELEASE_2019R1 2019010000
|
||||
#define INF_ENGINE_RELEASE_2019R2 2019020000
|
||||
#define INF_ENGINE_RELEASE_2019R3 2019030000
|
||||
#define INF_ENGINE_RELEASE_2020_1 2020010000
|
||||
|
||||
#ifndef INF_ENGINE_RELEASE
|
||||
#warning("IE version have not been provided via command-line. Using 2019R3 by default")
|
||||
#define INF_ENGINE_RELEASE INF_ENGINE_RELEASE_2019R3
|
||||
#warning("IE version have not been provided via command-line. Using 2019.1 by default")
|
||||
#define INF_ENGINE_RELEASE INF_ENGINE_RELEASE_2020_1
|
||||
#endif
|
||||
|
||||
#define INF_ENGINE_VER_MAJOR_GT(ver) (((INF_ENGINE_RELEASE) / 10000) > ((ver) / 10000))
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#ifdef HAVE_PROTOBUF
|
||||
|
||||
#include "../graph_simplifier.hpp"
|
||||
#include "tf_graph_simplifier.hpp"
|
||||
#include <queue>
|
||||
|
||||
@@ -18,203 +19,87 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
using ::google::protobuf::RepeatedField;
|
||||
using ::google::protobuf::MapPair;
|
||||
|
||||
class Subgraph // Interface to match and replace TensorFlow subgraphs.
|
||||
class TFNodeWrapper : public ImportNodeWrapper
|
||||
{
|
||||
public:
|
||||
virtual ~Subgraph() {}
|
||||
TFNodeWrapper(tensorflow::NodeDef* _node) : node(_node) {}
|
||||
|
||||
// Add a node to be matched in the origin graph. Specify ids of nodes that
|
||||
// are expected to be inputs. Returns id of a newly added node.
|
||||
// TODO: Replace inputs to std::vector<int> in C++11
|
||||
int addNodeToMatch(const std::string& op, int input_0 = -1, int input_1 = -1,
|
||||
int input_2 = -1, int input_3 = -1)
|
||||
virtual int getNumInputs() const CV_OVERRIDE
|
||||
{
|
||||
int nodeInputs[] = {input_0, input_1, input_2, input_3};
|
||||
int numInputs = 0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
numInputs += (int)(nodeInputs[i] != -1);
|
||||
}
|
||||
return addNodeToMatch(op, std::vector<int>(&nodeInputs[0], &nodeInputs[0] + numInputs));
|
||||
return node->input_size();
|
||||
}
|
||||
|
||||
int addNodeToMatch(const std::string& op, const std::vector<int>& inputs_)
|
||||
virtual std::string getInputName(int idx) const CV_OVERRIDE
|
||||
{
|
||||
for (int i = 0; i < inputs_.size(); ++i)
|
||||
{
|
||||
CV_Assert(inputs_[i] < (int)nodes.size());
|
||||
}
|
||||
nodes.push_back(op);
|
||||
inputs.push_back(inputs_);
|
||||
return nodes.size() - 1;
|
||||
return node->input(idx);
|
||||
}
|
||||
|
||||
// Specify resulting node. All the matched nodes in subgraph excluding
|
||||
// input nodes will be fused into this single node.
|
||||
// TODO: Replace inputs to std::vector<int> in C++11
|
||||
void setFusedNode(const std::string& op, int input_0 = -1, int input_1 = -1,
|
||||
int input_2 = -1, int input_3 = -1, int input_4 = -1,
|
||||
int input_5 = -1)
|
||||
virtual std::string getType() const CV_OVERRIDE
|
||||
{
|
||||
int nodeInputs[] = {input_0, input_1, input_2, input_3, input_4, input_5};
|
||||
int numInputs = 0;
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
CV_Assert(nodeInputs[i] < (int)nodes.size());
|
||||
numInputs += (int)(nodeInputs[i] != -1);
|
||||
}
|
||||
setFusedNode(op, std::vector<int>(&nodeInputs[0], &nodeInputs[0] + numInputs));
|
||||
return node->op();
|
||||
}
|
||||
|
||||
void setFusedNode(const std::string& op, const std::vector<int>& inputs_)
|
||||
virtual void setType(const std::string& type) CV_OVERRIDE
|
||||
{
|
||||
fusedNodeInputs = inputs_;
|
||||
fusedNodeOp = op;
|
||||
node->set_op(type);
|
||||
}
|
||||
|
||||
static int getInputNodeId(const tensorflow::GraphDef& net,
|
||||
const tensorflow::NodeDef& node,
|
||||
int inpId)
|
||||
virtual void setInputNames(const std::vector<std::string>& inputs) CV_OVERRIDE
|
||||
{
|
||||
CV_Assert(inpId < node.input_size());
|
||||
std::string name = node.input(inpId);
|
||||
// If operation produces several tensors, they are specified by index
|
||||
// after ':' character. In example, "input:0".
|
||||
name = name.substr(0, name.rfind(':'));
|
||||
const int numNodes = net.node_size();
|
||||
for (int i = 0; i < numNodes; ++i)
|
||||
{
|
||||
if (net.node(i).name() == name)
|
||||
return i;
|
||||
}
|
||||
CV_Error(Error::StsParseError, "Input node with name " + name + " not found");
|
||||
}
|
||||
|
||||
// Match TensorFlow subgraph starting from <nodeId> with a set of nodes to be fused.
|
||||
// Const nodes are skipped during matching. Returns true if nodes are matched and can be fused.
|
||||
virtual bool match(const tensorflow::GraphDef& net, int nodeId,
|
||||
std::vector<int>& matchedNodesIds,
|
||||
std::vector<int>& targetNodesIds)
|
||||
{
|
||||
matchedNodesIds.clear();
|
||||
targetNodesIds.clear();
|
||||
|
||||
std::queue<int> nodesToMatch;
|
||||
std::queue<int> targetNodes;
|
||||
nodesToMatch.push(nodeId);
|
||||
targetNodes.push(nodes.size() - 1);
|
||||
while (!nodesToMatch.empty())
|
||||
{
|
||||
int nodeToMatch = nodesToMatch.front();
|
||||
int targetNodeId = targetNodes.front();
|
||||
nodesToMatch.pop();
|
||||
targetNodes.pop();
|
||||
|
||||
if (std::find(matchedNodesIds.begin(), matchedNodesIds.end(), nodeToMatch) !=
|
||||
matchedNodesIds.end())
|
||||
continue;
|
||||
|
||||
const tensorflow::NodeDef& node = net.node(nodeToMatch);
|
||||
if (node.op() != nodes[targetNodeId])
|
||||
return false;
|
||||
|
||||
std::vector<int>& inputNodes = inputs[targetNodeId];
|
||||
if (inputNodes.size() != node.input_size())
|
||||
return false;
|
||||
|
||||
for (int j = 0; j < inputNodes.size(); ++j)
|
||||
{
|
||||
if (nodes[inputNodes[j]].empty()) // Unknown input node type.
|
||||
continue;
|
||||
nodeId = getInputNodeId(net, node, j);
|
||||
const tensorflow::NodeDef& inpNode = net.node(nodeId);
|
||||
if (inpNode.op() != "Const")
|
||||
{
|
||||
nodesToMatch.push(nodeId);
|
||||
targetNodes.push(inputNodes[j]);
|
||||
}
|
||||
else if (nodes[inputNodes[j]] != "Const")
|
||||
return false;
|
||||
}
|
||||
matchedNodesIds.push_back(nodeToMatch);
|
||||
targetNodesIds.push_back(targetNodeId);
|
||||
}
|
||||
|
||||
const int n = matchedNodesIds.size();
|
||||
std::vector<std::pair<int, int> > elements(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
elements[i] = std::make_pair(matchedNodesIds[i], targetNodesIds[i]);
|
||||
std::sort(elements.begin(), elements.end());
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
matchedNodesIds[i] = elements[i].first;
|
||||
targetNodesIds[i] = elements[i].second;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fuse matched subgraph.
|
||||
void replace(tensorflow::GraphDef& net, const std::vector<int>& matchedNodesIds,
|
||||
const std::vector<int>& targetNodesIds)
|
||||
{
|
||||
// Extract names of input nodes.
|
||||
std::vector<std::string> inputsNames(fusedNodeInputs.size());
|
||||
for (int i = 0; i < fusedNodeInputs.size(); ++i)
|
||||
{
|
||||
std::string inpName;
|
||||
// Find input node name looking at inputs of fused nodes.
|
||||
for (int j = 0; j < matchedNodesIds.size() && inpName.empty(); ++j)
|
||||
{
|
||||
const tensorflow::NodeDef &node = net.node(matchedNodesIds[j]);
|
||||
std::vector<int>& inpIndices = inputs[targetNodesIds[j]];
|
||||
|
||||
CV_Assert(node.input_size() == inpIndices.size());
|
||||
for (int k = 0; k < inpIndices.size(); ++k)
|
||||
{
|
||||
if (inpIndices[k] == fusedNodeInputs[i])
|
||||
{
|
||||
inpName = node.input(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CV_Assert(!inpName.empty());
|
||||
inputsNames[i] = inpName;
|
||||
}
|
||||
|
||||
// Remove matched nodes except the last one. Indices in ascending order are expected.
|
||||
tensorflow::NodeDef* node = net.mutable_node(matchedNodesIds.back());
|
||||
for (int i = matchedNodesIds.size() - 2; i >= 0; --i)
|
||||
net.mutable_node()->DeleteSubrange(matchedNodesIds[i], 1);
|
||||
|
||||
// Modify the last node to be a fused one.
|
||||
node->set_op(fusedNodeOp);
|
||||
node->clear_input();
|
||||
for (int i = 0; i < inputsNames.size(); ++i)
|
||||
{
|
||||
node->add_input(inputsNames[i]);
|
||||
}
|
||||
|
||||
std::vector<tensorflow::NodeDef*> inputNodes(inputsNames.size());
|
||||
for (int i = 0; i < inputsNames.size(); ++i)
|
||||
{
|
||||
inputNodes[i] = net.mutable_node(getInputNodeId(net, *node, i));
|
||||
}
|
||||
finalize(net, node, inputNodes);
|
||||
for (int i = 0; i < inputs.size(); ++i)
|
||||
node->add_input(inputs[i]);
|
||||
}
|
||||
|
||||
virtual void finalize(tensorflow::GraphDef&, tensorflow::NodeDef*,
|
||||
std::vector<tensorflow::NodeDef*>&) {}
|
||||
|
||||
private:
|
||||
std::vector<std::string> nodes; // Nodes to be matched in the origin graph.
|
||||
std::vector<std::vector<int> > inputs; // Connections of an every node to it's inputs.
|
||||
|
||||
std::string fusedNodeOp; // Operation name of resulting fused node.
|
||||
std::vector<int> fusedNodeInputs; // Inputs of fused node.
|
||||
tensorflow::NodeDef* node;
|
||||
};
|
||||
|
||||
class BatchNormSubgraph : public Subgraph
|
||||
class TFGraphWrapper : public ImportGraphWrapper
|
||||
{
|
||||
public:
|
||||
TFGraphWrapper(tensorflow::GraphDef& _net) : net(_net) {}
|
||||
|
||||
virtual Ptr<ImportNodeWrapper> getNode(int idx) const CV_OVERRIDE
|
||||
{
|
||||
return makePtr<TFNodeWrapper>(net.mutable_node(idx));
|
||||
}
|
||||
|
||||
virtual int getNumNodes() const CV_OVERRIDE
|
||||
{
|
||||
return net.node_size();
|
||||
}
|
||||
|
||||
virtual std::string getNodeName(int idx) const CV_OVERRIDE
|
||||
{
|
||||
return net.node(idx).name();
|
||||
}
|
||||
|
||||
virtual void removeNode(int idx) CV_OVERRIDE
|
||||
{
|
||||
net.mutable_node()->DeleteSubrange(idx, 1);
|
||||
}
|
||||
|
||||
tensorflow::GraphDef& net;
|
||||
};
|
||||
|
||||
class TFSubgraph : public Subgraph
|
||||
{
|
||||
virtual void finalize(const Ptr<ImportGraphWrapper>& netWrapper,
|
||||
const Ptr<ImportNodeWrapper>& fusedNodeWrapper,
|
||||
std::vector<Ptr<ImportNodeWrapper> >& inputs) CV_OVERRIDE
|
||||
{
|
||||
std::vector<tensorflow::NodeDef*> inputNodes(inputs.size());
|
||||
for (int i = 0; i < inputs.size(); ++i)
|
||||
inputNodes[i] = inputs[i].dynamicCast<TFNodeWrapper>()->node;
|
||||
finalize(netWrapper.dynamicCast<TFGraphWrapper>()->net,
|
||||
fusedNodeWrapper.dynamicCast<TFNodeWrapper>()->node, inputNodes);
|
||||
}
|
||||
|
||||
virtual void finalize(tensorflow::GraphDef&, tensorflow::NodeDef* fusedNode,
|
||||
std::vector<tensorflow::NodeDef*>& inputNodes) {}
|
||||
};
|
||||
|
||||
class BatchNormSubgraph : public TFSubgraph
|
||||
{
|
||||
public:
|
||||
BatchNormSubgraph()
|
||||
@@ -250,7 +135,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class BatchNormNoGammaSubgraph : public Subgraph
|
||||
class BatchNormNoGammaSubgraph : public TFSubgraph
|
||||
{
|
||||
public:
|
||||
BatchNormNoGammaSubgraph()
|
||||
@@ -366,20 +251,21 @@ public:
|
||||
setFusedNode("Relu6", input);
|
||||
}
|
||||
|
||||
virtual bool match(const tensorflow::GraphDef& net, int nodeId,
|
||||
virtual bool match(const Ptr<ImportGraphWrapper>& net, int nodeId,
|
||||
std::vector<int>& matchedNodesIds,
|
||||
std::vector<int>& targetNodesIds) CV_OVERRIDE
|
||||
{
|
||||
if (!Subgraph::match(net, nodeId, matchedNodesIds, targetNodesIds))
|
||||
return false;
|
||||
Mat maxValue = getTensorContent(net.node(matchedNodesIds.front() + 1).attr().at("value").tensor());
|
||||
tensorflow::NodeDef* node = net->getNode(matchedNodesIds.front() + 1).dynamicCast<TFNodeWrapper>()->node;
|
||||
Mat maxValue = getTensorContent(node->attr().at("value").tensor());
|
||||
return maxValue.type() == CV_32FC1 && maxValue.total() == 1 && maxValue.at<float>(0) == 6;
|
||||
}
|
||||
};
|
||||
|
||||
// Keras' reshape stores output shape in separate Const nodes by one value.
|
||||
// Need to merge them into a single Const node.
|
||||
class ReshapeKerasSubgraph : public Subgraph
|
||||
class ReshapeKerasSubgraph : public TFSubgraph
|
||||
{
|
||||
public:
|
||||
ReshapeKerasSubgraph(int _numOutDims) : numOutDims(_numOutDims)
|
||||
@@ -402,15 +288,15 @@ public:
|
||||
setFusedNode("Reshape", ids);
|
||||
}
|
||||
|
||||
virtual bool match(const tensorflow::GraphDef& net, int nodeId,
|
||||
virtual bool match(const Ptr<ImportGraphWrapper>& net, int nodeId,
|
||||
std::vector<int>& matchedNodesIds,
|
||||
std::vector<int>& targetNodesIds) CV_OVERRIDE
|
||||
{
|
||||
const tensorflow::NodeDef& node = net.node(nodeId);
|
||||
if (node.input_size() == 0)
|
||||
Ptr<ImportNodeWrapper> node = net->getNode(nodeId);
|
||||
if (node->getNumInputs() == 0)
|
||||
return false;
|
||||
|
||||
inpName = node.input(0);
|
||||
inpName = node->getInputName(0);
|
||||
return Subgraph::match(net, nodeId, matchedNodesIds, targetNodesIds);
|
||||
}
|
||||
|
||||
@@ -457,7 +343,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class DeconvolutionValidKerasSubgraph : public Subgraph
|
||||
class DeconvolutionValidKerasSubgraph : public TFSubgraph
|
||||
{
|
||||
public:
|
||||
DeconvolutionValidKerasSubgraph()
|
||||
@@ -518,7 +404,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class DeconvolutionSameKerasSubgraph : public Subgraph
|
||||
class DeconvolutionSameKerasSubgraph : public TFSubgraph
|
||||
{
|
||||
public:
|
||||
DeconvolutionSameKerasSubgraph()
|
||||
@@ -608,7 +494,7 @@ public:
|
||||
};
|
||||
|
||||
// In case of resizing by factor.
|
||||
class UpsamplingKerasSubgraph : public Subgraph
|
||||
class UpsamplingKerasSubgraph : public TFSubgraph
|
||||
{
|
||||
public:
|
||||
UpsamplingKerasSubgraph(const std::string& type)
|
||||
@@ -703,7 +589,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class KerasMVNSubgraph : public Subgraph
|
||||
class KerasMVNSubgraph : public TFSubgraph
|
||||
{
|
||||
public:
|
||||
KerasMVNSubgraph()
|
||||
@@ -758,20 +644,7 @@ void simplifySubgraphs(tensorflow::GraphDef& net)
|
||||
subgraphs.push_back(Ptr<Subgraph>(new ReshapeAsShapeSubgraph()));
|
||||
subgraphs.push_back(Ptr<Subgraph>(new KerasMVNSubgraph()));
|
||||
|
||||
int numNodes = net.node_size();
|
||||
std::vector<int> matchedNodesIds, targetNodesIds;
|
||||
for (int i = 0; i < numNodes; ++i)
|
||||
{
|
||||
for (int j = 0; j < subgraphs.size(); ++j)
|
||||
{
|
||||
if (subgraphs[j]->match(net, i, matchedNodesIds, targetNodesIds))
|
||||
{
|
||||
subgraphs[j]->replace(net, matchedNodesIds, targetNodesIds);
|
||||
numNodes -= matchedNodesIds.size() - 1; // #matchedNodes removed and one added.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
simplifySubgraphs(Ptr<ImportGraphWrapper>(new TFGraphWrapper(net)), subgraphs);
|
||||
}
|
||||
|
||||
void RemoveIdentityOps(tensorflow::GraphDef& net)
|
||||
@@ -950,6 +823,7 @@ void sortByExecutionOrder(tensorflow::GraphDef& net)
|
||||
for (int i = 0; i < net.node_size(); ++i)
|
||||
{
|
||||
const tensorflow::NodeDef& node = net.node(i);
|
||||
int numInputsInGraph = 0;
|
||||
for (int j = 0; j < node.input_size(); ++j)
|
||||
{
|
||||
std::string inpName = node.input(j);
|
||||
@@ -957,22 +831,25 @@ void sortByExecutionOrder(tensorflow::GraphDef& net)
|
||||
inpName = inpName.substr(inpName.find('^') + 1);
|
||||
|
||||
nodesMapIt = nodesMap.find(inpName);
|
||||
CV_Assert(nodesMapIt != nodesMap.end());
|
||||
edges[nodesMapIt->second].push_back(i);
|
||||
if (nodesMapIt != nodesMap.end())
|
||||
{
|
||||
edges[nodesMapIt->second].push_back(i);
|
||||
numInputsInGraph += 1;
|
||||
}
|
||||
}
|
||||
if (node.input_size() == 0)
|
||||
if (numInputsInGraph == 0)
|
||||
nodesToAdd.push_back(i);
|
||||
else
|
||||
{
|
||||
if (node.op() == "Merge" || node.op() == "RefMerge")
|
||||
{
|
||||
int numControlEdges = 0;
|
||||
for (int j = 0; j < node.input_size(); ++j)
|
||||
for (int j = 0; j < numInputsInGraph; ++j)
|
||||
numControlEdges += node.input(j)[0] == '^';
|
||||
numRefsToAdd[i] = numControlEdges + 1;
|
||||
}
|
||||
else
|
||||
numRefsToAdd[i] = node.input_size();
|
||||
numRefsToAdd[i] = numInputsInGraph;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -715,6 +715,10 @@ void TFImporter::populateNet(Net dstNet)
|
||||
simplifySubgraphs(netBin);
|
||||
sortByExecutionOrder(netBin);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortByExecutionOrder(netTxt);
|
||||
}
|
||||
|
||||
std::set<String> layers_to_ignore;
|
||||
|
||||
@@ -996,7 +1000,7 @@ void TFImporter::populateNet(Net dstNet)
|
||||
if (getDataLayout(name, data_layouts) == DATA_LAYOUT_UNKNOWN)
|
||||
data_layouts[name] = DATA_LAYOUT_NHWC;
|
||||
}
|
||||
else if (type == "BiasAdd" || type == "Add" || type == "Sub" || type=="AddN")
|
||||
else if (type == "BiasAdd" || type == "Add" || type == "AddV2" || type == "Sub" || type=="AddN")
|
||||
{
|
||||
bool haveConst = false;
|
||||
for(int ii = 0; !haveConst && ii < layer.input_size(); ++ii)
|
||||
|
||||
@@ -197,8 +197,8 @@ TEST_P(DNNTestNetwork, MobileNet_SSD_Caffe_Different_Width_Height)
|
||||
if (backend == DNN_BACKEND_HALIDE)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) &&
|
||||
target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X);
|
||||
#endif
|
||||
Mat sample = imread(findDataFile("dnn/street.png"));
|
||||
@@ -249,8 +249,8 @@ TEST_P(DNNTestNetwork, MobileNet_SSD_v1_TensorFlow_Different_Width_Height)
|
||||
if (backend == DNN_BACKEND_HALIDE)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) &&
|
||||
target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X);
|
||||
#endif
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000)
|
||||
|
||||
@@ -691,9 +691,11 @@ TEST_P(Test_Caffe_nets, FasterRCNN_zf)
|
||||
(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB),
|
||||
CV_TEST_TAG_DEBUG_LONG
|
||||
);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL_FP16)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
|
||||
if (target == DNN_TARGET_CUDA_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
|
||||
@@ -710,9 +712,11 @@ TEST_P(Test_Caffe_nets, RFCN)
|
||||
CV_TEST_TAG_LONG,
|
||||
CV_TEST_TAG_DEBUG_VERYLONG
|
||||
);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL_FP16)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_OPENCL_FP16)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
|
||||
float scoreDiff = default_l1, iouDiff = default_lInf;
|
||||
if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
|
||||
|
||||
@@ -307,8 +307,8 @@ TEST_P(Test_Darknet_nets, YoloVoc)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16);
|
||||
#endif
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) &&
|
||||
target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X); // need to update check function
|
||||
#endif
|
||||
|
||||
@@ -352,8 +352,8 @@ TEST_P(Test_Darknet_nets, TinyYoloVoc)
|
||||
applyTestTag(CV_TEST_TAG_MEMORY_512MB);
|
||||
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) &&
|
||||
target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X); // need to update check function
|
||||
#endif
|
||||
// batchId, classId, confidence, left, top, right, bottom
|
||||
@@ -486,7 +486,8 @@ TEST_P(Test_Darknet_nets, YOLOv3)
|
||||
std::string weights_file = "yolov3.weights";
|
||||
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD &&
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_MYRIAD &&
|
||||
getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
{
|
||||
scoreDiff = 0.04;
|
||||
|
||||
@@ -357,11 +357,6 @@ TEST_P(MaxPooling, Accuracy)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
#endif
|
||||
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && stride != Size(1, 1) && pad != Size(0, 0))
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
|
||||
LayerParams lp;
|
||||
lp.set("pool", "max");
|
||||
lp.set("kernel_w", kernel.width);
|
||||
@@ -399,7 +394,8 @@ TEST_P(FullyConnected, Accuracy)
|
||||
bool hasBias = get<3>(GetParam());
|
||||
Backend backendId = get<0>(get<4>(GetParam()));
|
||||
Target targetId = get<1>(get<4>(GetParam()));
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (targetId == DNN_TARGET_OPENCL_FP16 ||
|
||||
if ((backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
|
||||
backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && (targetId == DNN_TARGET_OPENCL_FP16 ||
|
||||
(targetId == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X))) {
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16);
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X);
|
||||
|
||||
@@ -134,12 +134,13 @@ static const std::vector<std::string> getOpenVINOTestModelsList()
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void genData(const std::vector<size_t>& dims, Mat& m, Blob::Ptr& dataPtr)
|
||||
static inline void genData(const InferenceEngine::TensorDesc& desc, Mat& m, Blob::Ptr& dataPtr)
|
||||
{
|
||||
const std::vector<size_t>& dims = desc.getDims();
|
||||
m.create(std::vector<int>(dims.begin(), dims.end()), CV_32F);
|
||||
randu(m, -1, 1);
|
||||
|
||||
dataPtr = make_shared_blob<float>({Precision::FP32, dims, Layout::ANY}, (float*)m.data);
|
||||
dataPtr = make_shared_blob<float>(desc, (float*)m.data);
|
||||
}
|
||||
|
||||
void runIE(Target target, const std::string& xmlPath, const std::string& binPath,
|
||||
@@ -238,7 +239,7 @@ void runIE(Target target, const std::string& xmlPath, const std::string& binPath
|
||||
BlobMap inputBlobs;
|
||||
for (auto& it : net.getInputsInfo())
|
||||
{
|
||||
genData(it.second->getTensorDesc().getDims(), inputsMap[it.first], inputBlobs[it.first]);
|
||||
genData(it.second->getTensorDesc(), inputsMap[it.first], inputBlobs[it.first]);
|
||||
}
|
||||
infRequest.SetInput(inputBlobs);
|
||||
|
||||
@@ -247,7 +248,7 @@ void runIE(Target target, const std::string& xmlPath, const std::string& binPath
|
||||
BlobMap outputBlobs;
|
||||
for (auto& it : net.getOutputsInfo())
|
||||
{
|
||||
genData(it.second->getTensorDesc().getDims(), outputsMap[it.first], outputBlobs[it.first]);
|
||||
genData(it.second->getTensorDesc(), outputsMap[it.first], outputBlobs[it.first]);
|
||||
}
|
||||
infRequest.SetOutput(outputBlobs);
|
||||
|
||||
|
||||
@@ -864,6 +864,8 @@ TEST_P(Test_Caffe_layers, PriorBox_squares)
|
||||
{
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
LayerParams lp;
|
||||
lp.name = "testPriorBox";
|
||||
lp.type = "PriorBox";
|
||||
@@ -1301,7 +1303,7 @@ static void test_dldt_fused_output(Backend backend, Target target)
|
||||
}
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
net.setInput(Mat({1, 1, 1, 1}, CV_32FC1, Scalar(1)));
|
||||
net.setInput(Mat({1, 1, 2, 3}, CV_32FC1, Scalar(1)));
|
||||
net.forward();
|
||||
}
|
||||
|
||||
@@ -1340,7 +1342,7 @@ TEST_P(Test_DLDT_layers, multiple_networks)
|
||||
nets[i].addLayerToPrev(lp.name, lp.type, lp);
|
||||
nets[i].setPreferableBackend(backend);
|
||||
nets[i].setPreferableTarget(target);
|
||||
nets[i].setInput(Mat({1, 1, 1, 1}, CV_32FC1, Scalar(1)));
|
||||
nets[i].setInput(Mat({1, 1, 2, 3}, CV_32FC1, Scalar(1)));
|
||||
}
|
||||
Mat out_1 = nets[0].forward();
|
||||
Mat out_2 = nets[1].forward();
|
||||
|
||||
@@ -369,9 +369,12 @@ TEST_P(Test_ONNX_layers, Div)
|
||||
net.setPreferableBackend(backend);
|
||||
net.setPreferableTarget(target);
|
||||
|
||||
Mat inp1 = blobFromNPY(_tf("data/input_div_0.npy"));
|
||||
Mat inp2 = blobFromNPY(_tf("data/input_div_1.npy"));
|
||||
// Reference output values range is -68.80928, 2.991873. So to avoid computational
|
||||
// difference for FP16 we'll perform reversed division (just swap inputs).
|
||||
Mat inp1 = blobFromNPY(_tf("data/input_div_1.npy"));
|
||||
Mat inp2 = blobFromNPY(_tf("data/input_div_0.npy"));
|
||||
Mat ref = blobFromNPY(_tf("data/output_div.npy"));
|
||||
cv::divide(1.0, ref, ref);
|
||||
checkBackend(&inp1, &ref);
|
||||
|
||||
net.setInput(inp1, "0");
|
||||
@@ -421,6 +424,7 @@ TEST_P(Test_ONNX_layers, Softmax)
|
||||
{
|
||||
testONNXModels("softmax");
|
||||
testONNXModels("log_softmax", npy, 0, 0, false, false);
|
||||
testONNXModels("softmax_unfused");
|
||||
}
|
||||
|
||||
TEST_P(Test_ONNX_layers, Split_EltwiseMax)
|
||||
@@ -473,6 +477,9 @@ TEST_P(Test_ONNX_nets, Googlenet)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
|
||||
const String model = _tf("models/googlenet.onnx", false);
|
||||
|
||||
Net net = readNetFromONNX(model);
|
||||
@@ -516,7 +523,7 @@ TEST_P(Test_ONNX_nets, RCNN_ILSVRC13)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
#endif
|
||||
// Reference output values are in range [-4.992, -1.161]
|
||||
testONNXModels("rcnn_ilsvrc13", pb, 0.0045);
|
||||
testONNXModels("rcnn_ilsvrc13", pb, 0.0046);
|
||||
}
|
||||
|
||||
TEST_P(Test_ONNX_nets, VGG16_bn)
|
||||
@@ -583,10 +590,12 @@ TEST_P(Test_ONNX_nets, TinyYolov2)
|
||||
)
|
||||
applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
|
||||
if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
|
||||
)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X,
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
|
||||
// output range: [-11; 8]
|
||||
@@ -628,6 +637,12 @@ TEST_P(Test_ONNX_nets, LResNet100E_IR)
|
||||
if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
}
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
{
|
||||
if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
}
|
||||
|
||||
double l1 = default_l1, lInf = default_lInf;
|
||||
// output range: [-3; 3]
|
||||
@@ -652,10 +667,11 @@ TEST_P(Test_ONNX_nets, LResNet100E_IR)
|
||||
TEST_P(Test_ONNX_nets, Emotion_ferplus)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
|
||||
)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X,
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
|
||||
double l1 = default_l1;
|
||||
@@ -692,7 +708,8 @@ TEST_P(Test_ONNX_nets, DenseNet121)
|
||||
TEST_P(Test_ONNX_nets, Inception_v1)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
|
||||
#endif
|
||||
testONNXModels("inception_v1", pb);
|
||||
|
||||
@@ -261,10 +261,13 @@ TEST_P(Test_TensorFlow_layers, ave_pool_same)
|
||||
{
|
||||
// Reference output values are in range [-0.519531, 0.112976]
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
|
||||
)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
{
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
}
|
||||
#endif
|
||||
runTensorFlowNet("ave_pool_same");
|
||||
}
|
||||
@@ -399,6 +402,8 @@ TEST_P(Test_TensorFlow_layers, l2_normalize_3d)
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
|
||||
runTensorFlowNet("l2_normalize_3d");
|
||||
@@ -409,11 +414,15 @@ class Test_TensorFlow_nets : public DNNTestLayer {};
|
||||
TEST_P(Test_TensorFlow_nets, MobileNet_SSD)
|
||||
{
|
||||
#if defined(INF_ENGINE_RELEASE)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
if (target == DNN_TARGET_MYRIAD)
|
||||
{
|
||||
#if INF_ENGINE_VER_MAJOR_GE(2019020000)
|
||||
if (getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X,
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
|
||||
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH,
|
||||
CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -554,6 +563,10 @@ TEST_P(Test_TensorFlow_nets, Faster_RCNN)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 &&
|
||||
(INF_ENGINE_VER_MAJOR_LT(2019020000) || target != DNN_TARGET_CPU))
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
|
||||
if (INF_ENGINE_VER_MAJOR_GT(2019030000) &&
|
||||
backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
// segfault: inference-engine/thirdparty/clDNN/src/gpu/detection_output_cpu.cpp:111:
|
||||
// Assertion `prior_height > 0' failed.
|
||||
|
||||
@@ -239,6 +239,8 @@ TEST_P(Test_Torch_layers, net_conv_gemm_lrn)
|
||||
{
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
double l1 = 0.0, lInf = 0.0;
|
||||
if (target == DNN_TARGET_OPENCL_FP16)
|
||||
{
|
||||
@@ -398,6 +400,13 @@ TEST_P(Test_Torch_nets, ENet_accuracy)
|
||||
if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
throw SkipTestException("");
|
||||
}
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
|
||||
{
|
||||
if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
throw SkipTestException("");
|
||||
}
|
||||
|
||||
Net net;
|
||||
{
|
||||
@@ -450,6 +459,9 @@ TEST_P(Test_Torch_nets, FastNeuralStyle_accuracy)
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD
|
||||
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||
#endif
|
||||
|
||||
checkBackend();
|
||||
|
||||
@@ -62,7 +62,7 @@ class MultiscaleAnchorGenerator:
|
||||
|
||||
def createSSDGraph(modelPath, configPath, outputPath):
|
||||
# Nodes that should be kept.
|
||||
keepOps = ['Conv2D', 'BiasAdd', 'Add', 'Relu', 'Relu6', 'Placeholder', 'FusedBatchNorm',
|
||||
keepOps = ['Conv2D', 'BiasAdd', 'Add', 'AddV2', 'Relu', 'Relu6', 'Placeholder', 'FusedBatchNorm',
|
||||
'DepthwiseConv2dNative', 'ConcatV2', 'Mul', 'MaxPool', 'AvgPool', 'Identity',
|
||||
'Sub', 'ResizeNearestNeighbor', 'Pad', 'FusedBatchNormV3']
|
||||
|
||||
@@ -151,6 +151,9 @@ def createSSDGraph(modelPath, configPath, outputPath):
|
||||
subgraphBatchNorm = ['Add',
|
||||
['Mul', 'input', ['Mul', ['Rsqrt', ['Add', 'moving_variance', 'add_y']], 'gamma']],
|
||||
['Sub', 'beta', ['Mul', 'moving_mean', 'Mul_0']]]
|
||||
subgraphBatchNormV2 = ['AddV2',
|
||||
['Mul', 'input', ['Mul', ['Rsqrt', ['AddV2', 'moving_variance', 'add_y']], 'gamma']],
|
||||
['Sub', 'beta', ['Mul', 'moving_mean', 'Mul_0']]]
|
||||
# Detect unfused nearest neighbor resize.
|
||||
subgraphResizeNN = ['Reshape',
|
||||
['Mul', ['Reshape', 'input', ['Pack', 'shape_1', 'shape_2', 'shape_3', 'shape_4', 'shape_5']],
|
||||
@@ -177,7 +180,8 @@ def createSSDGraph(modelPath, configPath, outputPath):
|
||||
for node in graph_def.node:
|
||||
inputs = {}
|
||||
fusedNodes = []
|
||||
if checkSubgraph(node, subgraphBatchNorm, inputs, fusedNodes):
|
||||
if checkSubgraph(node, subgraphBatchNorm, inputs, fusedNodes) or \
|
||||
checkSubgraph(node, subgraphBatchNormV2, inputs, fusedNodes):
|
||||
name = node.name
|
||||
node.Clear()
|
||||
node.name = name
|
||||
|
||||
Reference in New Issue
Block a user