[GNA] Fix Activation output size not matching convolution if padded. (#1980)
* Fix Activation output size not matching convolution if padded. * Fix input padding handling in Convolution * fix static bug * Use correct value for feature rotation. * [GNA] Fix regression * Added tests * Added tests
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include "functional_test_utils/layer_test_utils.hpp"
|
||||
#include "ngraph_functions/utils/ngraph_helpers.hpp"
|
||||
#include "ngraph_functions/builders.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
typedef std::tuple<
|
||||
InferenceEngine::Precision, // Network Precision
|
||||
std::string, // Target Device
|
||||
std::array<size_t, 4>, // Input shape
|
||||
std::array<size_t, 2>, // Kernel shape
|
||||
size_t, // Output channels
|
||||
std::map<std::string, std::string> // Configuration
|
||||
> ConvReshapeActParams;
|
||||
|
||||
class ConvReshapeAct : public testing::WithParamInterface<ConvReshapeActParams>,
|
||||
virtual public LayerTestsUtils::LayerTestsCommon {
|
||||
public:
|
||||
static std::string getTestCaseName(testing::TestParamInfo<ConvReshapeActParams> obj);
|
||||
|
||||
protected:
|
||||
void SetUp() override;
|
||||
void Run() override;
|
||||
};
|
||||
|
||||
} // namespace LayerTestsDefinitions
|
||||
@@ -0,0 +1,120 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <debug.h>
|
||||
#include "common_test_utils/common_utils.hpp"
|
||||
#include "functional_test_utils/precision_utils.hpp"
|
||||
#include "functional_test_utils/skip_tests_config.hpp"
|
||||
#include "subgraph_tests/reshape_permute_conv_permute_reshape_act.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
std::string ConvReshapeAct::getTestCaseName(testing::TestParamInfo<ConvReshapeActParams> obj) {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
std::string targetName;
|
||||
std::array<size_t, 4> input_shape;
|
||||
std::array<size_t, 2> kernel_shape;
|
||||
size_t output_channels;
|
||||
std::map<std::string, std::string> configuration;
|
||||
|
||||
|
||||
std::tie(netPrecision, targetName, input_shape, kernel_shape, output_channels, configuration) = obj.param;
|
||||
std::ostringstream results;
|
||||
|
||||
results << "IS=" << CommonTestUtils::vec2str(std::vector<size_t>(input_shape.begin(), input_shape.end())) << "_";
|
||||
results << "KS=" << CommonTestUtils::vec2str(std::vector<size_t>(kernel_shape.begin(), kernel_shape.end())) << "_";
|
||||
results << "OC=" << output_channels << "_";
|
||||
results << "netPRC=" << netPrecision.name() << "_";
|
||||
results << "targetDevice=" << targetName;
|
||||
return results.str();
|
||||
}
|
||||
|
||||
void ConvReshapeAct::SetUp() {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
std::array<size_t, 4> input_shape;
|
||||
std::array<size_t, 2> kernel_shape;
|
||||
size_t output_channels;
|
||||
std::map<std::string, std::string> additional_config;
|
||||
|
||||
std::tie(netPrecision, targetDevice, input_shape, kernel_shape, output_channels, additional_config) = this->GetParam();
|
||||
|
||||
configuration.insert(additional_config.begin(), additional_config.end());
|
||||
|
||||
const std::size_t input_dim = std::accumulate(input_shape.begin(), input_shape.end(), 1, std::multiplies<size_t>());
|
||||
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
|
||||
|
||||
std::vector<size_t> input_dims { 1, input_dim };
|
||||
std::vector<size_t> reshape_in_dims = std::vector<size_t>(input_shape.begin(), input_shape.end());
|
||||
std::vector<size_t> permute_in_order = { 0, 3, 1, 2 };
|
||||
std::vector<size_t> permute_out_order = { 0, 2, 3, 1 };
|
||||
std::vector<size_t> reshape_out_dims = { 1, input_shape[0] * input_shape[1] * (input_shape[2] - kernel_shape[1] + 1) * output_channels };
|
||||
|
||||
auto input_parameter = ngraph::builder::makeParams(ngPrc, {input_dims});
|
||||
|
||||
auto reshape_in_pattern = std::make_shared<ngraph::op::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{4},
|
||||
reshape_in_dims);
|
||||
auto reshape_in = std::make_shared<ngraph::op::v1::Reshape>(input_parameter[0], reshape_in_pattern, false);
|
||||
|
||||
auto permute_in_params = std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{4},
|
||||
ngraph::Shape{permute_in_order});
|
||||
auto permute_in = std::make_shared<ngraph::opset1::Transpose>(reshape_in, permute_in_params);
|
||||
|
||||
auto conv = ngraph::builder::makeConvolution(permute_in, ngPrc, {kernel_shape[0], kernel_shape[1]}, {1, 1}, {0, 0}, {0, 0}, {1, 1},
|
||||
ngraph::op::PadType::VALID, output_channels);
|
||||
|
||||
auto permute_out_params = std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{4},
|
||||
permute_out_order);
|
||||
auto permute_out = std::make_shared<ngraph::opset1::Transpose>(conv, permute_out_params);
|
||||
|
||||
auto reshape_out_pattern = std::make_shared<ngraph::op::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{2},
|
||||
std::vector<size_t>{reshape_out_dims});
|
||||
|
||||
auto reshape_out = std::make_shared<ngraph::op::v1::Reshape>(permute_out, reshape_out_pattern, false);
|
||||
|
||||
auto tanh = std::make_shared<ngraph::op::Tanh>(reshape_out);
|
||||
|
||||
function = std::make_shared<ngraph::Function>(tanh, input_parameter, "conv_reshape_act");
|
||||
}
|
||||
|
||||
void ConvReshapeAct::Run() {
|
||||
SKIP_IF_CURRENT_TEST_IS_DISABLED()
|
||||
|
||||
ConfigurePlugin();
|
||||
LoadNetwork();
|
||||
|
||||
inferRequest = executableNetwork.CreateInferRequest();
|
||||
inputs.clear();
|
||||
|
||||
for (const auto &input : cnnNetwork.getInputsInfo()) {
|
||||
const auto &info = input.second;
|
||||
auto tensorDesc = info->getTensorDesc();
|
||||
|
||||
auto blob = FuncTestUtils::createAndFillBlobFloat(tensorDesc, 2, -1, 100, 111);
|
||||
|
||||
FuncTestUtils::fillInputsBySinValues(blob);
|
||||
inferRequest.SetBlob(info->name(), blob);
|
||||
inputs.push_back(blob);
|
||||
}
|
||||
if (configuration.count(InferenceEngine::PluginConfigParams::KEY_DYN_BATCH_ENABLED) &&
|
||||
configuration.count(InferenceEngine::PluginConfigParams::YES)) {
|
||||
auto batchSize = cnnNetwork.getInputsInfo().begin()->second->getTensorDesc().getDims()[0] / 2;
|
||||
inferRequest.SetBatch(batchSize);
|
||||
}
|
||||
inferRequest.Infer();
|
||||
|
||||
threshold = 0.1;
|
||||
Validate();
|
||||
}
|
||||
|
||||
TEST_P(ConvReshapeAct, CompareWithRefs) {
|
||||
Run();
|
||||
}
|
||||
} // namespace LayerTestsDefinitions
|
||||
Reference in New Issue
Block a user