mirror of
https://github.com/opencv/opencv.git
synced 2026-09-12 13:23:03 -05:00
dnn(onnx): eliminate consecutive Transpose pairs with identity composition
Port of the 4.x patch to 5.x. Registers a new ConsecutiveTransposePairsSubgraph in onnx_graph_simplifier.cpp's simplifySubgraphs() so that consecutive Transpose nodes whose composed permutation is identity are eliminated at the ONNX proto level. This runs before either engine takes over, so both ENGINE_CLASSIC and ENGINE_NEW benefit. Equivalent optimizations exist in tf2onnx (TransposeOptimizer._transpose_handler) and ONNX Runtime (HandleTransposeImpl, 'Permutations cancel' branch).
This commit is contained in:
@@ -2999,6 +2999,20 @@ void Net::Impl::getLayerTypes(std::vector<String>& layersTypes) const
|
||||
// TODO drop?
|
||||
int Net::Impl::getLayersCount(const String& layerType) const
|
||||
{
|
||||
if (mainGraph) {
|
||||
int count = 0;
|
||||
for (const Ptr<Graph>& g: allgraphs) {
|
||||
const std::vector<Ptr<Layer> >& prog = g->prog();
|
||||
for (const Ptr<Layer>& layer: prog) {
|
||||
if (!layer)
|
||||
continue;
|
||||
if (layer->type == layerType)
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (Impl::MapIdToLayerData::const_iterator it = layers.begin();
|
||||
it != layers.end(); it++)
|
||||
|
||||
Reference in New Issue
Block a user