Remove dynamism from time_tests (API 1.0) (#10193)

This commit is contained in:
Victor Kuznetsov authored and GitHub committed 2022-02-09 19:15:16 +08:00
1 parent 051724f0d5
commit 21601398d6
4 files changed
+22 -67

No files matched your search

-20
View File
@@ -90,26 +90,6 @@ std::vector<std::string> split(const std::string &s, char delim) {
}
/**
* @brief Reshape blobs with dynamic shapes with static information from data shape
*/
void setBlobsStaticShapes(InferenceEngine::InferRequest inferRequest,
const InferenceEngine::ConstInputsDataMap &inputsInfo,
std::map<std::string, std::vector<size_t>> dataShape) {
for (const InferenceEngine::ConstInputsDataMap::value_type &item : inputsInfo) {
InferenceEngine::Blob::Ptr inputBlob = inferRequest.GetBlob(item.first);
if (dataShape.count(item.first)) {
InferenceEngine::SizeVector newInputShape;
for (size_t i = 0; i < dataShape[item.first].size(); i++) {
newInputShape.emplace_back(dataShape[item.first][i]);
}
inputBlob->setShape(newInputShape);
}
}
}
/**
* @brief Getting tensor shapes. If tensor is dynamic, static shape from data info will be returned.
*/
+18 -26
View File
@@ -8,23 +8,6 @@
#include <openvino/openvino.hpp>
/**
* @brief Fill InferenceEngine tensor with random values. The model shape is set separately.
*/
template<typename T>
ov::Tensor fillTensorRandomDynamic(ov::Output<const ov::Node> &input, ov::Shape shape) {
ov::Tensor tensor {input.get_element_type(), shape};
std::vector<T>values(ov::shape_size(shape));
for (size_t i = 0; i < values.size(); ++i) {
values[i] = 1 + static_cast<T>(rand()) / (static_cast<T>(RAND_MAX / (std::numeric_limits<T>::max() - 1)));
}
std::memcpy(tensor.data(), values.data(), sizeof(T) * values.size());
return tensor;
}
/**
* @brief Split input string using specified delimiter.
Return vector with input tensor information
@@ -57,16 +40,25 @@ ov::Shape getTensorStaticShape(ov::Output<const ov::Node> &input,
std::map<std::string, std::vector<size_t>> dataShape);
/**
* @brief Reshape blobs with dynamic shapes with static information from data shape
*/
void setBlobsStaticShapes(InferenceEngine::InferRequest inferRequest,
const InferenceEngine::ConstInputsDataMap &inputsInfo,
std::map<std::string, std::vector<size_t>> dataShape);
/**
* @brief Fill infer_request tensors with random values. The model shape is set separately. (OV API 2)
*/
void fillTensorsWithSpecifiedShape(ov::InferRequest& infer_request, std::vector<ov::Output<const ov::Node>> &inputs,
std::map<std::string, std::vector<size_t>> dataShape);
std::map<std::string, std::vector<size_t>> dataShape);
/**
* @brief Fill InferenceEngine tensor with random values. The model shape is set separately.
*/
template<typename T>
ov::Tensor fillTensorRandomDynamic(ov::Output<const ov::Node> &input, ov::Shape shape) {
ov::Tensor tensor {input.get_element_type(), shape};
std::vector<T>values(ov::shape_size(shape));
for (size_t i = 0; i < values.size(); ++i) {
values[i] = 1 + static_cast<T>(rand()) / (static_cast<T>(RAND_MAX / (std::numeric_limits<T>::max() - 1)));
}
std::memcpy(tensor.data(), values.data(), sizeof(T) * values.size());
return tensor;
}
@@ -5,7 +5,6 @@
#include <iostream>
#include "common_utils.h"
#include "reshape_utils.h"
#include "timetests_helper/timer.h"
#include "timetests_helper/utils.h"
@@ -27,11 +26,6 @@ int runPipeline(const std::string &model, const std::string &device, const bool
InferenceEngine::InferRequest inferRequest;
size_t batchSize = 0;
bool reshape = false;
if (!reshapeShapes.empty()) {
reshape = true;
}
// first_inference_latency = time_to_inference + first_inference
{
SCOPED_TIMER(time_to_inference);
@@ -56,12 +50,6 @@ int runPipeline(const std::string &model, const std::string &device, const bool
cnnNetwork = ie.ReadNetwork(model);
batchSize = cnnNetwork.getBatchSize();
}
if (reshape) {
{
SCOPED_TIMER(reshape);
cnnNetwork.reshape(reshapeShapes);
}
}
{
SCOPED_TIMER(load_network);
exeNetwork = ie.LoadNetwork(cnnNetwork, device);
@@ -81,12 +69,7 @@ int runPipeline(const std::string &model, const std::string &device, const bool
SCOPED_TIMER(fill_inputs);
const InferenceEngine::ConstInputsDataMap inputsInfo(exeNetwork.GetInputsInfo());
batchSize = batchSize != 0 ? batchSize : 1;
if (reshape) {
setBlobsStaticShapes(inferRequest, inputsInfo, dataShapes);
fillBlobs(inferRequest, inputsInfo, batchSize);
} else {
fillBlobs(inferRequest, inputsInfo, batchSize);
}
fillBlobs(inferRequest, inputsInfo, batchSize);
}
inferRequest.Infer();
}
@@ -27,7 +27,7 @@ int runPipeline(const std::string &model, const std::string &device, const bool
ov::CompiledModel exeNetwork;
ov::InferRequest inferRequest;
std::vector<ov::Output<ov::Node>> default_inputs;
std::vector<ov::Output<ov::Node>> defaultInputs;
bool reshape = false;
if (!reshapeShapes.empty()) {
@@ -61,7 +61,7 @@ int runPipeline(const std::string &model, const std::string &device, const bool
if (reshape) {
{
SCOPED_TIMER(reshape);
default_inputs = getCopyOfDefaultInputs(cnnNetwork->inputs());
defaultInputs = getCopyOfDefaultInputs(cnnNetwork->inputs());
cnnNetwork->reshape(reshapeShapes);
}
}
@@ -84,7 +84,7 @@ int runPipeline(const std::string &model, const std::string &device, const bool
SCOPED_TIMER(fill_inputs);
std::vector<ov::Output<const ov::Node>> inputs = exeNetwork.inputs();
if (reshape && dataShapes.empty()) {
fillTensors(inferRequest, default_inputs);
fillTensors(inferRequest, defaultInputs);
} else if (reshape && !dataShapes.empty()) {
fillTensorsWithSpecifiedShape(inferRequest, inputs, dataShapes);
} else {