[IE Samples] Export and Import of model, fixed (#9776)
* [IE Samples] Export and Import of model, fixed https://jira.devtools.intel.com/browse/CVS-76225 * Added IE_SUPPRESS_DEPRECATED * [IE Samples] Export and Import of model, fixed 76225 * Added IE_SUPPRESS_DEPRECATED * fixed notes * Update samples/cpp/speech_sample/main.cpp Co-authored-by: Mikhail Ryzhov <mikhail.ryzhov@intel.com> * Update samples/cpp/speech_sample/main.cpp Co-authored-by: Mikhail Ryzhov <mikhail.ryzhov@intel.com> * fixed formatting * changed processing of inputs * working export Co-authored-by: Mikhail Ryzhov <mikhail.ryzhov@intel.com>
This commit is contained in:
parent
cf80eda8e0
commit
0627fe857e
@ -83,17 +83,25 @@ int main(int argc, char* argv[]) {
|
||||
// -------------------------------------
|
||||
ov::Core core;
|
||||
slog::info << "Loading model files:" << slog::endl << FLAGS_m << slog::endl;
|
||||
std::shared_ptr<ov::Model> model = core.read_model(FLAGS_m);
|
||||
check_number_of_inputs(model->inputs().size(), numInputFiles);
|
||||
const ov::Layout tensor_layout{"NC"};
|
||||
ov::preprocess::PrePostProcessor proc(model);
|
||||
for (int i = 0; i < model->inputs().size(); i++) {
|
||||
proc.input(i).tensor().set_element_type(ov::element::f32).set_layout(tensor_layout);
|
||||
uint32_t batchSize = (FLAGS_cw_r > 0 || FLAGS_cw_l > 0) ? 1 : (uint32_t)FLAGS_bs;
|
||||
std::shared_ptr<ov::Model> model;
|
||||
// ------------------------------ Preprocessing ------------------------------------------------------
|
||||
// the preprocessing steps can be done only for loaded network and are not applicable for the imported network
|
||||
// (already compiled)
|
||||
if (!FLAGS_m.empty()) {
|
||||
model = core.read_model(FLAGS_m);
|
||||
check_number_of_inputs(model->inputs().size(), numInputFiles);
|
||||
const ov::Layout tensor_layout{"NC"};
|
||||
ov::preprocess::PrePostProcessor proc(model);
|
||||
for (int i = 0; i < model->inputs().size(); i++) {
|
||||
proc.input(i).tensor().set_element_type(ov::element::f32).set_layout(tensor_layout);
|
||||
}
|
||||
for (int i = 0; i < model->outputs().size(); i++) {
|
||||
proc.output(i).tensor().set_element_type(ov::element::f32);
|
||||
}
|
||||
model = proc.build();
|
||||
ov::set_batch(model, batchSize);
|
||||
}
|
||||
for (int i = 0; i < model->outputs().size(); i++) {
|
||||
proc.output(i).tensor().set_element_type(ov::element::f32);
|
||||
}
|
||||
model = proc.build();
|
||||
// ------------------------------ Get Available Devices ------------------------------------------------------
|
||||
auto isFeature = [&](const std::string xFeature) {
|
||||
return FLAGS_d.find(xFeature) != std::string::npos;
|
||||
@ -101,8 +109,6 @@ int main(int argc, char* argv[]) {
|
||||
bool useGna = isFeature("GNA");
|
||||
bool useHetero = isFeature("HETERO");
|
||||
std::string deviceStr = useHetero && useGna ? "HETERO:GNA,CPU" : FLAGS_d.substr(0, (FLAGS_d.find("_")));
|
||||
uint32_t batchSize = (FLAGS_cw_r > 0 || FLAGS_cw_l > 0) ? 1 : (uint32_t)FLAGS_bs;
|
||||
ov::set_batch(model, batchSize);
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// --------------------------- Set parameters and scale factors -------------------------------------
|
||||
/** Setting parameter for per layer metrics **/
|
||||
@ -221,14 +227,17 @@ int main(int argc, char* argv[]) {
|
||||
executableNet = core.compile_model(model, deviceStr, genericPluginConfig);
|
||||
} else {
|
||||
slog::info << "Importing model to the device" << slog::endl;
|
||||
std::istringstream streamrq(FLAGS_rg);
|
||||
std::ifstream streamrq(FLAGS_rg, std::ios_base::binary | std::ios_base::in);
|
||||
if (!streamrq.is_open()) {
|
||||
throw std::runtime_error("Cannot open model file " + FLAGS_rg);
|
||||
}
|
||||
executableNet = core.import_model(streamrq, deviceStr, genericPluginConfig);
|
||||
}
|
||||
// --------------------------- Exporting gna model using InferenceEngine AOT API---------------------
|
||||
if (!FLAGS_wg.empty()) {
|
||||
slog::info << "Writing GNA Model to file " << FLAGS_wg << slog::endl;
|
||||
t0 = Time::now();
|
||||
std::ostringstream streamwq(FLAGS_wg);
|
||||
std::ofstream streamwq(FLAGS_wg, std::ios_base::binary | std::ios::out);
|
||||
executableNet.export_model(streamwq);
|
||||
ms exportTime = std::chrono::duration_cast<ms>(Time::now() - t0);
|
||||
slog::info << "Exporting time " << exportTime.count() << " ms" << slog::endl;
|
||||
@ -455,10 +464,10 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
int index = static_cast<int>(frameIndex) - (FLAGS_cw_l + FLAGS_cw_r);
|
||||
for (int i = 0; i < model->inputs().size(); i++) {
|
||||
for (int i = 0; i < executableNet.inputs().size(); i++) {
|
||||
inferRequest.inferRequest.set_input_tensor(
|
||||
i,
|
||||
ov::Tensor(ov::element::f32, model->inputs()[i].get_shape(), inputFrame[0]));
|
||||
ov::Tensor(ov::element::f32, executableNet.inputs()[i].get_shape(), inputFrame[0]));
|
||||
}
|
||||
/* Starting inference in asynchronous mode*/
|
||||
inferRequest.inferRequest.start_async();
|
||||
|
Loading…
Reference in New Issue
Block a user