diff --git a/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp b/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp index a21affeae88ffe..8ab4af9f1083f9 100644 --- a/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp +++ b/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp @@ -2211,6 +2211,17 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { } }; + auto transpInfoMatchWeightsSize = [](const std::vector &transpositionInfo, size_t weightsSize, const std::string &layerName) { + size_t totalElements = 0; + for (auto && transpositionInfoPart : transpositionInfo) { + totalElements += transpositionInfoPart.num_transpose_rows * transpositionInfoPart.num_transpose_columns; + } + if (totalElements != weightsSize) { + THROW_GNA_EXCEPTION << layerName << " weights elements from transposition info (" << totalElements + << ") don't match input dimensions (" << weightsSize << ")"; + } + }; + for (auto &&l : *pLayers) { if (LayerInfo(l).isScaleShift()) { std::vector transpositionInfo; @@ -2228,15 +2239,10 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { } auto weightable = dynamic_cast(l.get()); IE_ASSERT(weightable != nullptr); - size_t totalElements = 0; - auto totalWeights = weightable->_weights->size(); - for (auto && transpositionInfoPart : transpositionInfo) { - totalElements += transpositionInfoPart.num_transpose_rows * transpositionInfoPart.num_transpose_columns; - } - if (totalElements != totalWeights) { - THROW_GNA_EXCEPTION << l->name << " weights columns from transposition info (" << totalElements - << ") don't match input dimensions (" << totalWeights << ")"; - } + + size_t totalWeights = weightable->_weights->size(); + transpInfoMatchWeightsSize(transpositionInfo, totalWeights, l->name); + ConvertTensorFromNCHWToNHWC(weightable->precision.size(), 1, weightable->_weights->size(), weightable->_weights->cbuffer().as(), true, transpositionInfo); if (weightable->_biases) { @@ -2270,14 +2276,9 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { // If we found a split it's not possible to rotate data THROW_GNA_EXCEPTION << l->name << " won't be transposed due to a split before it"; } - size_t totalColumns = 0; - for (auto && transpositionInfoPart : transpositionInfo) { - totalColumns += transpositionInfoPart.num_transpose_rows * transpositionInfoPart.num_transpose_columns; - } - if (weightsColumns != totalColumns) { - THROW_GNA_EXCEPTION << l->name << " weights columns from transposition info (" << totalColumns - << ") don't match input dimensions (" << weightsColumns << ")"; - } + + transpInfoMatchWeightsSize(transpositionInfo, weightsColumns, l->name); + ConvertTensorFromNCHWToNHWC(precision, weightsRows, weightsColumns, weightable->_weights->cbuffer().as(), true, transpositionInfo); gnalog() << l->name << " weights rows transposition info:\n"; @@ -2297,14 +2298,9 @@ void TransposeWeightsFromNCHWToNHWCPass::run() { // If we found a concat it's not possible to rotate data THROW_GNA_EXCEPTION << l->name << " won't be transposed due to a concat after it"; } - size_t totalRows = 0; - for (const auto& transpositionInfoPart : transpositionInfo) { - totalRows += transpositionInfoPart.num_transpose_rows * transpositionInfoPart.num_transpose_columns; - } - if (weightsRows != totalRows) { - THROW_GNA_EXCEPTION << l->name << " weights rows from transposition info (" << totalRows - << ") don't match output dimensions (" << weightsRows << ")"; - } + + transpInfoMatchWeightsSize(transpositionInfo, weightsRows, l->name); + ConvertTensorFromNCHWToNHWC(precision, weightsRows, weightsColumns, weightable->_weights->cbuffer().as(), false, transpositionInfo); gnalog() << l->name << " weights columns transposition info:\n";