diff --git a/inference-engine/src/gna_plugin/frontend/scale_factor_calc.hpp b/inference-engine/src/gna_plugin/frontend/scale_factor_calc.hpp index a986a4b60e2b62..20ee010741e10e 100644 --- a/inference-engine/src/gna_plugin/frontend/scale_factor_calc.hpp +++ b/inference-engine/src/gna_plugin/frontend/scale_factor_calc.hpp @@ -1300,6 +1300,7 @@ class ScaleFactorCalculator { if (!frontend::ScaleFactorPerLayer()(ptr, weightsBytesSize, inputsBytesSize, result, isFakeQuantize, infiniteLoopCount)) { return false; } + if (result) { idx++; return true; @@ -1309,7 +1310,6 @@ class ScaleFactorCalculator { if (!result) { return result.restartLayer == cnnLayer.get(); } - return ptr == cnnLayer.get(); }); if (idx != net.end()) { idx++; diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index b0e1666d9cdb7b..098b0be075c2bc 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -724,6 +724,7 @@ void GNAPlugin::LoadNetwork(CNNNetwork & _network) { manager.register_pass(); manager.register_pass(); manager.register_pass(); + manager.register_pass(); manager.register_pass(); if (config.gnaCompileTarget == InferenceEngine::GNAConfigParams::GNA_TARGET_2_0) { manager.register_pass(); diff --git a/inference-engine/src/gna_plugin/transformations/convert_dwsc_to_scaleshifts.cpp b/inference-engine/src/gna_plugin/transformations/convert_dwsc_to_scaleshifts.cpp index 9990157b32506c..6545c1b9f05d2c 100644 --- a/inference-engine/src/gna_plugin/transformations/convert_dwsc_to_scaleshifts.cpp +++ b/inference-engine/src/gna_plugin/transformations/convert_dwsc_to_scaleshifts.cpp @@ -12,13 +12,13 @@ #include #include #include "utils/transformation_helper.hpp" -//#include "backend/gna_limitations.hpp" using namespace GNAPluginNS; NGRAPH_RTTI_DEFINITION(ConvertDWSCToScaleShifts, "ConvertDWSCToScaleShifts", 0); NGRAPH_RTTI_DEFINITION(ConvertDWSCBiasToScaleShifts, "ConvertDWSCBiasToScaleShifts", 0); +NGRAPH_RTTI_DEFINITION(ConvertDWSCWithFqToScaleShifts, "ConvertDWSCWithFqToScaleShifts", 0); static bool VerifyDWSC(std::shared_ptr dwsc) { // Verify it's a 1D convolution @@ -32,7 +32,8 @@ static bool VerifyDWSC(std::shared_ptr dwsc) { return true; } -static std::shared_ptr DecomposeDWSC(std::shared_ptr dwsc, std::shared_ptr bias_const, +static std::shared_ptr DecomposeDWSC(std::shared_ptr dwsc, + std::shared_ptr bias_const, std::shared_ptr fq_bias, std::shared_ptr flat_input_plane, std::shared_ptr flat_filters_plane) { std::shared_ptr const_zero_padding; std::shared_ptr reshaped_bias; @@ -78,6 +79,7 @@ static std::shared_ptr DecomposeDWSC(std::shared_ptr(previous_layer_output, reshaped_bias); copy_runtime_info(dwsc, previous_layer_output); + previous_layer_output = InsertFQLayer(fq_bias, previous_layer_output); } last_layer_output = previous_layer_output; } else { @@ -111,11 +113,15 @@ static std::shared_ptr DecomposeDWSC(std::shared_ptr dwsc_node, + std::shared_ptr reshape_filters_const_node, std::shared_ptr bias_node, - std::shared_ptr bias_const_node) { + std::shared_ptr bias_const_node, + std::shared_ptr fq_bias_node) { auto dwsc = std::dynamic_pointer_cast(dwsc_node); + auto reshape_filters_const = std::dynamic_pointer_cast(reshape_filters_const_node); auto bias = std::dynamic_pointer_cast(bias_node); auto bias_const = std::dynamic_pointer_cast(bias_const_node); + auto fq_bias = std::dynamic_pointer_cast(fq_bias_node); if (!VerifyDWSC(dwsc)) return false; @@ -124,7 +130,7 @@ static bool Convert(std::shared_ptr dwsc_node, auto input_width = dwsc->get_input_shape(0)[3]; auto output_channel_count = dwsc->get_output_shape(0)[1]; auto output_width = dwsc->get_output_shape(0)[3]; - auto original_last_node = (bias_const ? bias_node : dwsc_node); + auto original_last_node = (fq_bias ? fq_bias_node : (bias_const ? bias_node : dwsc_node)); // Prepare flat input data auto reshaped_input_plane = std::make_shared(dwsc->input_value(0), @@ -139,7 +145,7 @@ static bool Convert(std::shared_ptr dwsc_node, ngraph::Shape{1, shape_size(dwsc->input_value(0).get_shape())}), false); // Prepare flat filter data - auto filters_const = std::dynamic_pointer_cast(dwsc->input_value(1).get_node_shared_ptr()); + auto filters_const = std::dynamic_pointer_cast(dwsc->get_input_node_shared_ptr(1)); auto filters_size = shape_size(filters_const->get_shape()); auto transposed_filters_const = ngraph::op::util::make_try_fold(filters_const, @@ -151,7 +157,7 @@ static bool Convert(std::shared_ptr dwsc_node, copy_runtime_info(dwsc, {reshaped_input_plane, transposed_input_plane, flat_input_plane, transposed_filters_const, flat_filters_plane}); // Convert DWSC to a set of diagonal layers - auto output_plane = DecomposeDWSC(dwsc, bias_const, flat_input_plane, flat_filters_plane); + auto output_plane = DecomposeDWSC(dwsc, bias_const, fq_bias, flat_input_plane, flat_filters_plane); // Restore the original output shape auto result = std::make_shared(output_plane, @@ -176,7 +182,7 @@ ConvertDWSCToScaleShifts::ConvertDWSCToScaleShifts() { ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { const auto& pattern_map = m.get_pattern_value_map(); - return Convert(pattern_map.at(dwsc).get_node_shared_ptr(), nullptr, nullptr); + return Convert(pattern_map.at(dwsc).get_node_shared_ptr(), nullptr, nullptr, nullptr, nullptr); }; auto m = std::make_shared(dwsc, matcher_name); @@ -201,9 +207,40 @@ ConvertDWSCBiasToScaleShifts::ConvertDWSCBiasToScaleShifts() { if (bias_node && (bias_const = VerifyBiasGetConst(pattern_map.at(dwsc).get_node_shared_ptr(), bias_node)) == nullptr) return false; - return Convert(pattern_map.at(dwsc).get_node_shared_ptr(), bias_node, bias_const); + return Convert(pattern_map.at(dwsc).get_node_shared_ptr(), nullptr, bias_node, bias_const, nullptr); }; auto m = std::make_shared(bias, matcher_name); this->register_matcher(m, callback); } + +ConvertDWSCWithFqToScaleShifts::ConvertDWSCWithFqToScaleShifts() { + MATCHER_SCOPE(ConvertDWSCWithFqToScaleShifts); + + auto const_input = ngraph::pattern::wrap_type(); + auto filters_const_fq = ngraph::pattern::wrap_type(ngraph::pattern::rank_equals(4)); + auto fq_filters_const = ngraph::pattern::wrap_type({filters_const_fq, const_input, const_input, const_input, const_input}, + consumers_and_rank(1, 4)); + auto reshape_filters_const = ngraph::pattern::wrap_type({fq_filters_const, const_input}); + auto dwsc = ngraph::pattern::wrap_type( + {ngraph::pattern::any_input(), reshape_filters_const}, consumers_and_rank(1, 4)); + auto bias = ngraph::pattern::wrap_type({dwsc, const_input}); + auto fq_bias = ngraph::pattern::wrap_type({bias, const_input, const_input, const_input, const_input}, + consumers_and_rank(1, 4)); + + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_map = m.get_pattern_value_map(); + auto bias_it = pattern_map.find(bias); + auto bias_node = (bias_it == std::end(pattern_map) ? nullptr : bias_it->second.get_node_shared_ptr()); + std::shared_ptr bias_const = nullptr; + + if (bias_node && (bias_const = VerifyBiasGetConst(pattern_map.at(dwsc).get_node_shared_ptr(), bias_node)) == nullptr) + return false; + + return Convert(pattern_map.at(dwsc).get_node_shared_ptr(), pattern_map.at(reshape_filters_const).get_node_shared_ptr(), + bias_node, bias_const, pattern_map.at(fq_bias).get_node_shared_ptr()); + }; + + auto m = std::make_shared(fq_bias, matcher_name); + this->register_matcher(m, callback); +} diff --git a/inference-engine/src/gna_plugin/transformations/convert_dwsc_to_scaleshifts.hpp b/inference-engine/src/gna_plugin/transformations/convert_dwsc_to_scaleshifts.hpp index 423784200b43b5..337efc063c0c30 100644 --- a/inference-engine/src/gna_plugin/transformations/convert_dwsc_to_scaleshifts.hpp +++ b/inference-engine/src/gna_plugin/transformations/convert_dwsc_to_scaleshifts.hpp @@ -26,4 +26,14 @@ class ConvertDWSCBiasToScaleShifts : public ngraph::pass::MatcherPass { ConvertDWSCBiasToScaleShifts(); }; +/** + * @brief Convert a depthwise separable convolution + potential bias (represented by a GroupConvolution + Add), processed by POT, + * to a set of ScaleShift layers (MatMul + Add) + */ +class ConvertDWSCWithFqToScaleShifts : public ngraph::pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + ConvertDWSCWithFqToScaleShifts(); +}; + } // namespace GNAPluginNS diff --git a/inference-engine/src/gna_plugin/transformations/decompose_2d_convolution.cpp b/inference-engine/src/gna_plugin/transformations/decompose_2d_convolution.cpp index f3ed07c27127b5..2aaec0604a811c 100644 --- a/inference-engine/src/gna_plugin/transformations/decompose_2d_convolution.cpp +++ b/inference-engine/src/gna_plugin/transformations/decompose_2d_convolution.cpp @@ -262,16 +262,6 @@ static void TransformInput(const GraphData& graph_data, const ConvData& conv_dat split_input_plane = flattened_dilated_transposed_input; } -static void InsertFQLayer(const std::shared_ptr fqLayer, - std::shared_ptr lastNode) { - if (fqLayer != nullptr) { - lastNode = fqLayer->clone_with_new_inputs({lastNode, - fqLayer->input_value(1), fqLayer->input_value(2), - fqLayer->input_value(3), fqLayer->input_value(4)}); - ngraph::copy_runtime_info(fqLayer, lastNode); - } -} - // Valid 1D (decomposed 2D) convolution wrapped with transposes NHWC => NCHW => conv => NCHW => NHWC static std::shared_ptr Create1DConv(const GraphData& graph_data, const ConvData& conv_data, const ngraph::Output& input, std::shared_ptr filters, const size_t conv_index, const size_t h_index) { @@ -280,7 +270,7 @@ static std::shared_ptr Create1DConv(const GraphData& graph_data, c ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{4}, {0, 3, 1, 2})->output(0)); // Fake quantize - InsertFQLayer(graph_data.fq_conv, filters); + filters = InsertFQLayer(graph_data.fq_conv, filters); // 1D Convolution auto conv = std::make_shared(nchw_input, filters, @@ -297,7 +287,7 @@ static std::shared_ptr Create1DConv(const GraphData& graph_data, c ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{4}, ngraph::Shape{1, bias_size, 1, 1}), false); last_conv_block_op = std::make_shared(conv, reshaped_bias_const); copy_runtime_info(graph_data.conv, last_conv_block_op); - InsertFQLayer(graph_data.fq_bias, last_conv_block_op); + last_conv_block_op = InsertFQLayer(graph_data.fq_bias, last_conv_block_op); } // Max pooling @@ -311,7 +301,7 @@ static std::shared_ptr Create1DConv(const GraphData& graph_data, c if (graph_data.af && graph_data.conv_count == 1) { last_conv_block_op = graph_data.af->copy_with_new_inputs({last_conv_block_op}); copy_runtime_info(conv, last_conv_block_op); - InsertFQLayer(graph_data.fq_af, last_conv_block_op); + last_conv_block_op = InsertFQLayer(graph_data.fq_af, last_conv_block_op); } // Transpose NCHW => NHWC diff --git a/inference-engine/src/gna_plugin/transformations/utils/transformation_helper.cpp b/inference-engine/src/gna_plugin/transformations/utils/transformation_helper.cpp index 040ef6794cfe17..6dc197bf406a02 100644 --- a/inference-engine/src/gna_plugin/transformations/utils/transformation_helper.cpp +++ b/inference-engine/src/gna_plugin/transformations/utils/transformation_helper.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "transformation_helper.hpp" @@ -90,4 +91,16 @@ std::shared_ptr VerifyBiasGetConst(std::shared_ptr c return nullptr; } +std::shared_ptr InsertFQLayer(const std::shared_ptr fq_layer, + std::shared_ptr last_node) { + if (fq_layer != nullptr) { + auto new_fq = fq_layer->clone_with_new_inputs({last_node, + fq_layer->input_value(1), fq_layer->input_value(2), + fq_layer->input_value(3), fq_layer->input_value(4)}); + ngraph::copy_runtime_info(new_fq, fq_layer); + return new_fq; + } + return last_node; +} + } // namespace GNAPluginNS diff --git a/inference-engine/src/gna_plugin/transformations/utils/transformation_helper.hpp b/inference-engine/src/gna_plugin/transformations/utils/transformation_helper.hpp index f8a0ba41bd3955..d09f09fa18db37 100644 --- a/inference-engine/src/gna_plugin/transformations/utils/transformation_helper.hpp +++ b/inference-engine/src/gna_plugin/transformations/utils/transformation_helper.hpp @@ -70,4 +70,12 @@ std::shared_ptr FlatCrop(ngraph::Output VerifyBiasGetConst(std::shared_ptr conv, std::shared_ptr bias); +/** + * @brief inserts a new fake quantize layer (if it exists) copied from an existing fake quantize layer and conncts it to the output of a given layer + * @param fq_layer existing fake quantize layer to be copied + * @param last_node the node to which output the new fake quantize layer will be connected + * @return new fake quantize layer or the last node + */ +std::shared_ptr InsertFQLayer(const std::shared_ptr fq_layer, std::shared_ptr last_node); + } // namespace GNAPluginNS diff --git a/inference-engine/tests/unit/gna/ngraph/transformations/gna_convert_dwsc_to_scaleshifts.cpp b/inference-engine/tests/unit/gna/ngraph/transformations/gna_convert_dwsc_to_scaleshifts.cpp index 9b7c51a9738a23..4423c5972adab3 100644 --- a/inference-engine/tests/unit/gna/ngraph/transformations/gna_convert_dwsc_to_scaleshifts.cpp +++ b/inference-engine/tests/unit/gna/ngraph/transformations/gna_convert_dwsc_to_scaleshifts.cpp @@ -25,7 +25,7 @@ enum class modelType { typedef std::tuple< modelType, // Test model - ngraph::Shape, // Input shape + ngraph::Shape, // Input shape ngraph::Shape, // Convolution filter shape ngraph::Strides, // Convolution stride ngraph::CoordinateDiff, // Convolution pads begin @@ -40,6 +40,27 @@ typedef std::tuple< DWSCToScaleShiftsParams // Test parameters > fqDWSCToScaleShiftsParams; +std::shared_ptr createFQ(std::shared_ptr& in_node) { + auto input_low = ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto input_high = ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {5}); + auto output_low = ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto output_high = ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {10}); + return std::make_shared(in_node, input_low, input_high, output_low, output_high, 11); +} + +std::shared_ptr createBiasFQ(const std::shared_ptr& in_node, + std::shared_ptr& bias_const, std::shared_ptr& bias, const bool& fq) { + std::shared_ptr node; + bias = std::make_shared(in_node, bias_const); + node = bias; + + if (fq) { + node = createFQ(node); + } + + return node; +} + std::shared_ptr createFunction(const bool& fq, const modelType& model, const ngraph::Output& input_node, @@ -51,15 +72,30 @@ std::shared_ptr createFunction(const bool& fq, const ngraph::Shape& bias_shape, const ngraph::op::PadType& pad_type, std::shared_ptr& dwsc, - std::shared_ptr& bias_const) { - auto filters = std::make_shared(ngraph::element::i64, - ngraph::Shape{input_node.get_shape()[1], 1, 1, filters_shape[0], filters_shape[1]}); - dwsc = std::make_shared(input_node, filters, conv_stride, pads_begin, pads_end, conv_dilation, pad_type); + std::shared_ptr& bias_const, + std::shared_ptr& fq_bias) { + std::shared_ptr fq_filters; + + if (fq) { + fq_filters = std::make_shared(ngraph::element::i64, + ngraph::Shape{input_node.get_shape()[1], 1, filters_shape[0], filters_shape[1]}); + fq_filters = createFQ(fq_filters); + fq_filters = std::make_shared(fq_filters, + ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{5}, + ngraph::Shape{input_node.get_shape()[1], 1, 1, filters_shape[0], filters_shape[1]}), false); + } else { + fq_filters = std::make_shared(ngraph::element::i64, + ngraph::Shape{input_node.get_shape()[1], 1, 1, filters_shape[0], filters_shape[1]}); + } + + dwsc = std::make_shared(input_node, fq_filters, conv_stride, pads_begin, pads_end, conv_dilation, pad_type); std::shared_ptr last_op = dwsc; - if (model == modelType::DWSCBias) { + if (model == modelType::DWSCBias || fq) { + std::shared_ptr bias = nullptr; bias_const = std::make_shared(ngraph::element::i64, bias_shape); - last_op = std::make_shared(dwsc, bias_const); + last_op = createBiasFQ(dwsc, bias_const, bias, fq); + fq_bias = std::dynamic_pointer_cast(last_op); } return std::make_shared(last_op); @@ -76,10 +112,11 @@ std::shared_ptr get_initial_function(const bool& fq, const ngraph::Shape& bias_shape, const ngraph::op::PadType& pad_type, std::shared_ptr& dwsc, - std::shared_ptr& bias_const) { + std::shared_ptr& bias_const, + std::shared_ptr& fq_bias) { auto input_params = std::make_shared(ngraph::element::i64, input_shape); auto result = createFunction(fq, model, input_params, filters_shape, conv_stride, pads_begin, pads_end, conv_dilation, - bias_shape, pad_type, dwsc, bias_const); + bias_shape, pad_type, dwsc, bias_const, fq_bias); return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{input_params}); } @@ -92,10 +129,10 @@ class ConvertDWSCToScaleShiftsTestInvalidFixture : public CommonTestUtils::Tests public: std::shared_ptr function, reference_function; modelType model; + bool fq; }; void ConvertDWSCToScaleShiftsTestInvalidFixture::SetUp() { - bool fq; DWSCToScaleShiftsParams params; ngraph::Shape input_shape; ngraph::Shape filters_shape, bias_shape; @@ -104,14 +141,15 @@ void ConvertDWSCToScaleShiftsTestInvalidFixture::SetUp() { ngraph::op::PadType pad_type; std::shared_ptr dwsc; std::shared_ptr bias_const; + std::shared_ptr fq_bias; std::tie(fq, params) = this->GetParam(); std::tie(model, input_shape, filters_shape, conv_stride, pads_begin, pads_end, conv_dilation, bias_shape, pad_type) = params; function = get_initial_function(fq, model, input_shape, filters_shape, conv_stride, pads_begin, pads_end, conv_dilation, - bias_shape, pad_type, dwsc, bias_const); + bias_shape, pad_type, dwsc, bias_const, fq_bias); reference_function = get_initial_function(fq, model, input_shape, filters_shape, conv_stride, pads_begin, pads_end, conv_dilation, - bias_shape, pad_type, dwsc, bias_const); + bias_shape, pad_type, dwsc, bias_const, fq_bias); } // --------------------------------------------------------------------------------------------------------------------- @@ -131,14 +169,15 @@ class ConvertDWSCToScaleShiftsTestFixture: public CommonTestUtils::TestsCommon, const ngraph::Shape& bias_shape, const ngraph::op::PadType& pad_type, const std::shared_ptr& dwsc, - const std::shared_ptr& bias_const); + const std::shared_ptr& bias_const, + const std::shared_ptr& fq_bias); public: std::shared_ptr function, reference_function; modelType model; + bool fq; }; void ConvertDWSCToScaleShiftsTestFixture::SetUp() { - bool fq; DWSCToScaleShiftsParams params; ngraph::Shape input_shape; ngraph::Shape filters_shape, bias_shape; @@ -147,14 +186,15 @@ void ConvertDWSCToScaleShiftsTestFixture::SetUp() { ngraph::op::PadType pad_type; std::shared_ptr dwsc; std::shared_ptr bias_const; + std::shared_ptr fq_bias; std::tie(fq, params) = this->GetParam(); std::tie(model, input_shape, filters_shape, conv_stride, pads_begin, pads_end, conv_dilation, bias_shape, pad_type) = params; function = get_initial_function(fq, model, input_shape, filters_shape, conv_stride, pads_begin, pads_end, conv_dilation, - bias_shape, pad_type, dwsc, bias_const); + bias_shape, pad_type, dwsc, bias_const, fq_bias); reference_function = get_reference(fq, model, input_shape, filters_shape, conv_stride, pads_begin, pads_end, conv_dilation, - bias_shape, pad_type, dwsc, bias_const); + bias_shape, pad_type, dwsc, bias_const, fq_bias); } std::shared_ptr FlatCrop(ngraph::Output input, size_t offset, size_t size) { @@ -167,7 +207,18 @@ std::shared_ptr FlatCrop(ngraph::Output{1, 0}); // end mask } -std::shared_ptr DecomposeDWSC(std::shared_ptr dwsc, std::shared_ptr bias_const, +std::shared_ptr InsertFQLayer(const std::shared_ptr fq_layer, + std::shared_ptr last_node) { + if (fq_layer != nullptr) { + return fq_layer->clone_with_new_inputs({last_node, + fq_layer->input_value(1), fq_layer->input_value(2), + fq_layer->input_value(3), fq_layer->input_value(4)}); + } + return last_node; +} + +std::shared_ptr DecomposeDWSC(std::shared_ptr dwsc, + std::shared_ptr bias_const, std::shared_ptr fq_bias, std::shared_ptr flat_input_plane, std::shared_ptr flat_filters_plane) { std::shared_ptr const_zero_padding; std::shared_ptr reshaped_bias; @@ -210,6 +261,7 @@ std::shared_ptr DecomposeDWSC(std::shared_ptr(conv_input_slice, conv_filter_slice); if (bias_const) { previous_layer_output = std::make_shared(previous_layer_output, reshaped_bias); + previous_layer_output = InsertFQLayer(fq_bias, previous_layer_output); } last_layer_output = previous_layer_output; } else { @@ -249,7 +301,8 @@ std::shared_ptr ConvertDWSCToScaleShiftsTestFixture::get_refer const ngraph::Shape& bias_shape, const ngraph::op::PadType& pad_type, const std::shared_ptr& dwsc, - const std::shared_ptr& bias_const) { + const std::shared_ptr& bias_const, + const std::shared_ptr& fq_bias) { auto input_params = std::make_shared(ngraph::element::i64, input_shape); auto input_channel_count = input_shape[1]; auto input_width = input_shape[3]; @@ -269,7 +322,7 @@ std::shared_ptr ConvertDWSCToScaleShiftsTestFixture::get_refer ngraph::Shape{1, ngraph::shape_size(input_shape)}), false); // Prepare flat filter data - auto filters_const = std::dynamic_pointer_cast(dwsc->input_value(1).get_node_shared_ptr()); + auto filters_const = std::dynamic_pointer_cast(dwsc->get_input_node_shared_ptr(1)); auto filters_size = ngraph::shape_size(filters_const->get_shape()); auto transposed_filters_const = ngraph::op::util::make_try_fold(filters_const, @@ -279,7 +332,7 @@ std::shared_ptr ConvertDWSCToScaleShiftsTestFixture::get_refer ngraph::opset7::Constant::create(ngraph::element::i64, ngraph::Shape{2}, ngraph::Shape{1, filters_size}), false); // Convert DWSC to a set of diagonal layers - auto output_plane = DecomposeDWSC(dwsc, bias_const, flat_input_plane, flat_filters_plane); + auto output_plane = DecomposeDWSC(dwsc, bias_const, fq_bias, flat_input_plane, flat_filters_plane); // Restore the original output shape auto result = std::make_shared(output_plane, @@ -291,18 +344,16 @@ std::shared_ptr ConvertDWSCToScaleShiftsTestFixture::get_refer // --------------------------------------------------------------------------------------------------------------------- -void execute_test(modelType model, std::shared_ptr function, std::shared_ptr reference_function) { +void execute_test(modelType model, bool fq, std::shared_ptr function, std::shared_ptr reference_function) { ngraph::pass::Manager manager; manager.register_pass(); - switch (model) { - default: - case modelType::DWSC: - manager.register_pass(); - break; - case modelType::DWSCBias: + if (fq) { + manager.register_pass(); + } else if (model == modelType::DWSCBias) { manager.register_pass(); - break; + } else { + manager.register_pass(); } manager.run_passes(function); @@ -312,13 +363,13 @@ void execute_test(modelType model, std::shared_ptr function, s } TEST_P(ConvertDWSCToScaleShiftsTestFixture, CompareFunctions) { - execute_test(model, function, reference_function); + execute_test(model, fq, function, reference_function); } INSTANTIATE_TEST_SUITE_P(ConvertDWSCToScaleShiftsTestSuite, ConvertDWSCToScaleShiftsTestFixture, ::testing::Combine( // With / without Fake Quantize layers - ::testing::Values(false), + ::testing::Values(true, false), ::testing::Values( std::make_tuple(modelType::DWSC, ngraph::Shape{1, 32, 1, 5}, ngraph::Shape{1, 3}, ngraph::Strides{1, 1}, ngraph::CoordinateDiff{0, 1}, ngraph::CoordinateDiff{0, 1}, ngraph::Strides{1, 1}, @@ -328,13 +379,13 @@ INSTANTIATE_TEST_SUITE_P(ConvertDWSCToScaleShiftsTestSuite, ConvertDWSCToScaleSh ngraph::Shape{1, 32, 1, 1}, ngraph::op::PadType::VALID)))); TEST_P(ConvertDWSCToScaleShiftsTestInvalidFixture, CompareFunctions) { - execute_test(model, function, reference_function); + execute_test(model, fq, function, reference_function); } INSTANTIATE_TEST_SUITE_P(ConvertDWSCToScaleShiftsInvalidTestSuite, ConvertDWSCToScaleShiftsTestInvalidFixture, ::testing::Combine( // With / without Fake Quantize layers - ::testing::Values(false), + ::testing::Values(true, false), ::testing::Values( std::make_tuple(modelType::DWSC, ngraph::Shape{2, 1, 16, 8}, ngraph::Shape{1, 2}, ngraph::Strides{1, 1}, ngraph::CoordinateDiff{0, 2}, ngraph::CoordinateDiff{0, 3}, ngraph::Strides{1, 1},