[GNA] Set input scale factors for imported model (#7139)
This commit is contained in:
parent
b73788d08c
commit
0f1fc504b4
@ -627,24 +627,21 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
if (FLAGS_q.compare("user") == 0) {
|
if (FLAGS_q.compare("user") == 0) {
|
||||||
if (!FLAGS_rg.empty()) {
|
if (!FLAGS_rg.empty()) {
|
||||||
slog::warn
|
slog::warn << "Custom scale factor will be used for imported gna model: " << FLAGS_rg << slog::endl;
|
||||||
<< "Custom scale factor will be ignored - using scale factor from provided imported gna model: "
|
}
|
||||||
<< FLAGS_rg << slog::endl;
|
|
||||||
} else {
|
|
||||||
auto scaleFactorInput = ParseScaleFactors(FLAGS_sf);
|
|
||||||
if (numInputFiles != scaleFactorInput.size()) {
|
|
||||||
std::string errMessage(
|
|
||||||
"Incorrect command line for multiple inputs: " + std::to_string(scaleFactorInput.size()) +
|
|
||||||
" scale factors provided for " + std::to_string(numInputFiles) + " input files.");
|
|
||||||
throw std::logic_error(errMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < scaleFactorInput.size(); ++i) {
|
auto scaleFactorInput = ParseScaleFactors(FLAGS_sf);
|
||||||
slog::info << "For input " << i << " using scale factor of " << scaleFactorInput[i] << slog::endl;
|
if (numInputFiles != scaleFactorInput.size()) {
|
||||||
std::string scaleFactorConfigKey =
|
std::string errMessage(
|
||||||
GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_") + std::to_string(i);
|
"Incorrect command line for multiple inputs: " + std::to_string(scaleFactorInput.size()) +
|
||||||
gnaPluginConfig[scaleFactorConfigKey] = scaleFactorInput[i];
|
" scale factors provided for " + std::to_string(numInputFiles) + " input files.");
|
||||||
}
|
throw std::logic_error(errMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < scaleFactorInput.size(); ++i) {
|
||||||
|
slog::info << "For input " << i << " using scale factor of " << scaleFactorInput[i] << slog::endl;
|
||||||
|
std::string scaleFactorConfigKey = GNA_CONFIG_KEY(SCALE_FACTOR) + std::string("_") + std::to_string(i);
|
||||||
|
gnaPluginConfig[scaleFactorConfigKey] = scaleFactorInput[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// "static" quantization with calculated scale factor
|
// "static" quantization with calculated scale factor
|
||||||
|
@ -1579,6 +1579,18 @@ InferenceEngine::IExecutableNetworkInternal::Ptr GNAPlugin::ImportNetwork(std::i
|
|||||||
transpose_inputs_info,
|
transpose_inputs_info,
|
||||||
transpose_outputs_info);
|
transpose_outputs_info);
|
||||||
|
|
||||||
|
// If scale factors are defined in configuration we still need to use them instead of imported values,
|
||||||
|
// for example to change the scale factors for the old models.
|
||||||
|
if (!config.inputScaleFactors.empty()) {
|
||||||
|
IE_ASSERT(config.inputScaleFactors.size() == inputsDesc->inputScaleFactors.size());
|
||||||
|
for (size_t i = 0; i < config.inputScaleFactors.size(); ++i) {
|
||||||
|
if (config.inputScaleFactors[i] != GNAPluginNS::kScaleFactorDefault) {
|
||||||
|
gnalog() << "[Import Network] Using input scale factor defined in configuration for input " << i << std::endl;
|
||||||
|
inputsDesc->inputScaleFactors[i] = config.inputScaleFactors[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if GNA_LIB_VER == 2
|
#if GNA_LIB_VER == 2
|
||||||
auto getOrientation = [](Gna2Operation & gnaOperation) {
|
auto getOrientation = [](Gna2Operation & gnaOperation) {
|
||||||
return gnaOperation.Type == Gna2OperationTypeConvolution ?
|
return gnaOperation.Type == Gna2OperationTypeConvolution ?
|
||||||
|
@ -95,7 +95,7 @@ void Config::UpdateFromMap(const std::map<std::string, std::string>& config) {
|
|||||||
}
|
}
|
||||||
// missing scale factors are set to be 1.0f
|
// missing scale factors are set to be 1.0f
|
||||||
if (inputScaleFactors.size() <= input_index) {
|
if (inputScaleFactors.size() <= input_index) {
|
||||||
inputScaleFactors.resize(input_index + 1, 1.f);
|
inputScaleFactors.resize(input_index + 1, GNAPluginNS::kScaleFactorDefault);
|
||||||
}
|
}
|
||||||
inputScaleFactors[input_index] = InferenceEngine::CNNLayer::ie_parse_float(value);
|
inputScaleFactors[input_index] = InferenceEngine::CNNLayer::ie_parse_float(value);
|
||||||
} else if (key == GNA_CONFIG_KEY(FIRMWARE_MODEL_IMAGE)) {
|
} else if (key == GNA_CONFIG_KEY(FIRMWARE_MODEL_IMAGE)) {
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
namespace GNAPluginNS {
|
namespace GNAPluginNS {
|
||||||
|
|
||||||
|
static const float kScaleFactorDefault = 1.f;
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
Config() {
|
Config() {
|
||||||
AdjustKeyMapValues();
|
AdjustKeyMapValues();
|
||||||
|
@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class ImportReshapePermuteConvGNA : public ImportReshapePermuteConv {
|
class ImportExportGNAModelUnchanged : public ImportReshapePermuteConv {
|
||||||
private:
|
private:
|
||||||
void exportImportNetwork() override {
|
void exportImportNetwork() override {
|
||||||
{
|
{
|
||||||
@ -42,8 +42,14 @@ private:
|
|||||||
std::string fileName = "exported_model.blob";
|
std::string fileName = "exported_model.blob";
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(ImportReshapePermuteConvGNA, CompareWithRefImpl) {
|
class ImportExportGNAModelChanged : public ImportExportGNAModelUnchanged {};
|
||||||
Run();
|
|
||||||
|
TEST_P(ImportExportGNAModelUnchanged, ReshapePermuteConv) {
|
||||||
|
TestRun(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_P(ImportExportGNAModelChanged, ReshapePermuteConv) {
|
||||||
|
TestRun(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<InferenceEngine::Precision> netPrecisions = {
|
const std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||||
@ -58,15 +64,25 @@ const std::vector<std::map<std::string, std::string>> exportConfigs = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<std::map<std::string, std::string>> importConfigs = {
|
const std::vector<std::map<std::string, std::string>> importConfigsChanged = {
|
||||||
{
|
{
|
||||||
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
|
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
|
||||||
{"GNA_SCALE_FACTOR_0", "32767"}
|
{"GNA_SCALE_FACTOR_0", "32767"}
|
||||||
},
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::vector<std::map<std::string, std::string>> importConfigsUnchanged = {
|
||||||
{
|
{
|
||||||
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
|
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
|
||||||
{"GNA_SCALE_FACTOR_0", "327.67"}
|
{"GNA_SCALE_FACTOR_0", "327.67"}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
|
||||||
|
{"GNA_SCALE_FACTOR_0", "1"}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<std::string> appHeaders = {
|
const std::vector<std::string> appHeaders = {
|
||||||
@ -74,13 +90,22 @@ const std::vector<std::string> appHeaders = {
|
|||||||
"APPLICATION_HEADER"
|
"APPLICATION_HEADER"
|
||||||
};
|
};
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkCase, ImportReshapePermuteConvGNA,
|
INSTANTIATE_TEST_CASE_P(smoke_ImportNetworkGNA, ImportExportGNAModelUnchanged,
|
||||||
::testing::Combine(
|
::testing::Combine(
|
||||||
::testing::ValuesIn(netPrecisions),
|
::testing::ValuesIn(netPrecisions),
|
||||||
::testing::Values(CommonTestUtils::DEVICE_GNA),
|
::testing::Values(CommonTestUtils::DEVICE_GNA),
|
||||||
::testing::ValuesIn(exportConfigs),
|
::testing::ValuesIn(exportConfigs),
|
||||||
::testing::ValuesIn(importConfigs),
|
::testing::ValuesIn(importConfigsUnchanged),
|
||||||
::testing::ValuesIn(appHeaders)),
|
::testing::ValuesIn(appHeaders)),
|
||||||
ImportReshapePermuteConvGNA::getTestCaseName);
|
ImportExportGNAModelUnchanged::getTestCaseName);
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(smoke_ImportNetworkGNA, ImportExportGNAModelChanged,
|
||||||
|
::testing::Combine(
|
||||||
|
::testing::ValuesIn(netPrecisions),
|
||||||
|
::testing::Values(CommonTestUtils::DEVICE_GNA),
|
||||||
|
::testing::ValuesIn(exportConfigs),
|
||||||
|
::testing::ValuesIn(importConfigsChanged),
|
||||||
|
::testing::ValuesIn(appHeaders)),
|
||||||
|
ImportExportGNAModelChanged::getTestCaseName);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -23,6 +23,7 @@ class ImportNetworkTestBase : public testing::WithParamInterface<exportImportNet
|
|||||||
public:
|
public:
|
||||||
static std::string getTestCaseName(testing::TestParamInfo<exportImportNetworkParams> obj);
|
static std::string getTestCaseName(testing::TestParamInfo<exportImportNetworkParams> obj);
|
||||||
void Run() override;
|
void Run() override;
|
||||||
|
void TestRun(bool isModelChanged);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<std::string, std::string> exportConfiguration;
|
std::map<std::string, std::string> exportConfiguration;
|
||||||
|
@ -42,14 +42,18 @@ void ImportNetworkTestBase::exportImportNetwork() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ImportNetworkTestBase::Run() {
|
void ImportNetworkTestBase::Run() {
|
||||||
SKIP_IF_CURRENT_TEST_IS_DISABLED()
|
TestRun(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportNetworkTestBase::TestRun(bool isModelChanged) {
|
||||||
|
SKIP_IF_CURRENT_TEST_IS_DISABLED()
|
||||||
|
// load export configuration and save outputs
|
||||||
configuration.insert(exportConfiguration.begin(), exportConfiguration.end());
|
configuration.insert(exportConfiguration.begin(), exportConfiguration.end());
|
||||||
LoadNetwork();
|
LoadNetwork();
|
||||||
GenerateInputs();
|
GenerateInputs();
|
||||||
Infer();
|
Infer();
|
||||||
|
auto actualOutputs = GetOutputs();
|
||||||
|
|
||||||
const auto& actualOutputs = GetOutputs();
|
|
||||||
auto referenceOutputs = CalculateRefs();
|
auto referenceOutputs = CalculateRefs();
|
||||||
Compare(referenceOutputs, actualOutputs);
|
Compare(referenceOutputs, actualOutputs);
|
||||||
|
|
||||||
@ -57,6 +61,14 @@ void ImportNetworkTestBase::Run() {
|
|||||||
configuration[configItem.first] = configItem.second;
|
configuration[configItem.first] = configItem.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for import with different scale factor need to use import configuration to get refference outputs.
|
||||||
|
if (isModelChanged) {
|
||||||
|
LoadNetwork();
|
||||||
|
GenerateInputs();
|
||||||
|
Infer();
|
||||||
|
actualOutputs = GetOutputs();
|
||||||
|
}
|
||||||
|
|
||||||
const auto compiledExecNetwork = executableNetwork;
|
const auto compiledExecNetwork = executableNetwork;
|
||||||
exportImportNetwork();
|
exportImportNetwork();
|
||||||
const auto importedExecNetwork = executableNetwork;
|
const auto importedExecNetwork = executableNetwork;
|
||||||
@ -75,6 +87,7 @@ void ImportNetworkTestBase::Run() {
|
|||||||
ASSERT_NO_THROW(compiledExecNetwork.GetOutputsInfo()[next_output.first]);
|
ASSERT_NO_THROW(compiledExecNetwork.GetOutputsInfo()[next_output.first]);
|
||||||
}
|
}
|
||||||
auto importedOutputs = GetOutputs();
|
auto importedOutputs = GetOutputs();
|
||||||
|
|
||||||
ASSERT_EQ(actualOutputs.size(), importedOutputs.size());
|
ASSERT_EQ(actualOutputs.size(), importedOutputs.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < actualOutputs.size(); i++) {
|
for (size_t i = 0; i < actualOutputs.size(); i++) {
|
||||||
|
@ -313,6 +313,7 @@ void LayerTestsCommon::LoadNetwork() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LayerTestsCommon::GenerateInputs() {
|
void LayerTestsCommon::GenerateInputs() {
|
||||||
|
inputs.clear();
|
||||||
const auto& inputsInfo = executableNetwork.GetInputsInfo();
|
const auto& inputsInfo = executableNetwork.GetInputsInfo();
|
||||||
const auto& functionParams = function->get_parameters();
|
const auto& functionParams = function->get_parameters();
|
||||||
for (int i = 0; i < functionParams.size(); ++i) {
|
for (int i = 0; i < functionParams.size(); ++i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user