[IE SAMPLES] activated NCC tool for c++ samples (#9600)
* [IE SAMPLES] activated NCC tool for c++ samples * exclude ov_ncc_naming_style for tests * fixed NCC hit * Added support for source files in samples * changed style of methods for benchmark * changed style for speech sample * changed code style * changed code style for shared_tensor * benchmark changes * changed remote_tensors_filling * fixed notes * rebase of branch
This commit is contained in:
@@ -25,13 +25,13 @@
|
||||
#endif
|
||||
|
||||
namespace benchmark_app {
|
||||
bool InputInfo::isImage() const {
|
||||
bool InputInfo::is_image() const {
|
||||
if ((layout != "NCHW") && (layout != "NHWC") && (layout != "CHW") && (layout != "HWC"))
|
||||
return false;
|
||||
// If tensor_shape is still empty, assume this is still an Image and tensor shape will be filled later
|
||||
return (dataShape.empty() || channels() == 3);
|
||||
}
|
||||
bool InputInfo::isImageInfo() const {
|
||||
bool InputInfo::is_image_info() const {
|
||||
if (layout != "NC")
|
||||
return false;
|
||||
return (channels() >= 2);
|
||||
@@ -53,7 +53,7 @@ size_t InputInfo::depth() const {
|
||||
}
|
||||
} // namespace benchmark_app
|
||||
|
||||
uint32_t deviceDefaultDeviceDurationInSeconds(const std::string& device) {
|
||||
uint32_t device_default_device_duration_in_seconds(const std::string& device) {
|
||||
static const std::map<std::string, uint32_t> deviceDefaultDurationInSeconds{{"CPU", 60},
|
||||
{"GPU", 60},
|
||||
{"VPU", 60},
|
||||
@@ -94,7 +94,7 @@ std::vector<std::string> split(const std::string& s, char delim) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<float> splitFloat(const std::string& s, char delim) {
|
||||
std::vector<float> split_float(const std::string& s, char delim) {
|
||||
std::vector<float> result;
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
@@ -105,7 +105,7 @@ std::vector<float> splitFloat(const std::string& s, char delim) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> parseDevices(const std::string& device_string) {
|
||||
std::vector<std::string> parse_devices(const std::string& device_string) {
|
||||
std::string comma_separated_devices = device_string;
|
||||
auto colon = comma_separated_devices.find(":");
|
||||
if (colon != std::string::npos) {
|
||||
@@ -118,8 +118,8 @@ std::vector<std::string> parseDevices(const std::string& device_string) {
|
||||
return devices;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> parseNStreamsValuePerDevice(const std::vector<std::string>& devices,
|
||||
const std::string& values_string) {
|
||||
std::map<std::string, std::string> parse_nstreams_value_per_device(const std::vector<std::string>& devices,
|
||||
const std::string& values_string) {
|
||||
// Format: <device1>:<value1>,<device2>:<value2> or just <value>
|
||||
std::map<std::string, std::string> result;
|
||||
auto device_value_strings = split(values_string, ',');
|
||||
@@ -147,7 +147,7 @@ std::map<std::string, std::string> parseNStreamsValuePerDevice(const std::vector
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t getBatchSize(const benchmark_app::InputsInfo& inputs_info) {
|
||||
size_t get_batch_size(const benchmark_app::InputsInfo& inputs_info) {
|
||||
size_t batch_size = 0;
|
||||
for (auto& info : inputs_info) {
|
||||
if (ov::layout::has_batch(info.second.layout)) {
|
||||
@@ -167,13 +167,13 @@ size_t getBatchSize(const benchmark_app::InputsInfo& inputs_info) {
|
||||
return batch_size;
|
||||
}
|
||||
|
||||
std::string getShapeString(const ov::Shape& shape) {
|
||||
std::string get_shape_string(const ov::Shape& shape) {
|
||||
std::stringstream ss;
|
||||
ss << shape;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string getShapesString(const benchmark_app::PartialShapes& shapes) {
|
||||
std::string get_shapes_string(const benchmark_app::PartialShapes& shapes) {
|
||||
std::stringstream ss;
|
||||
for (auto& shape : shapes) {
|
||||
if (!ss.str().empty())
|
||||
@@ -183,8 +183,8 @@ std::string getShapesString(const benchmark_app::PartialShapes& shapes) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::map<std::string, std::vector<float>> parseScaleOrMean(const std::string& scale_mean,
|
||||
const benchmark_app::InputsInfo& inputs_info) {
|
||||
std::map<std::string, std::vector<float>> parse_scale_or_mean(const std::string& scale_mean,
|
||||
const benchmark_app::InputsInfo& inputs_info) {
|
||||
// Format: data:[255,255,255],info[255,255,255]
|
||||
std::map<std::string, std::vector<float>> return_value;
|
||||
|
||||
@@ -196,7 +196,7 @@ std::map<std::string, std::vector<float>> parseScaleOrMean(const std::string& sc
|
||||
break;
|
||||
auto input_name = search_string.substr(0, start_pos);
|
||||
auto input_value_string = search_string.substr(start_pos + 1, end_pos - start_pos - 1);
|
||||
auto input_value = splitFloat(input_value_string, ',');
|
||||
auto input_value = split_float(input_value_string, ',');
|
||||
|
||||
if (!input_name.empty()) {
|
||||
if (inputs_info.count(input_name)) {
|
||||
@@ -205,7 +205,7 @@ std::map<std::string, std::vector<float>> parseScaleOrMean(const std::string& sc
|
||||
// ignore wrong input name
|
||||
} else {
|
||||
for (auto& item : inputs_info) {
|
||||
if (item.second.isImage())
|
||||
if (item.second.is_image())
|
||||
return_value[item.first] = input_value;
|
||||
}
|
||||
search_string.clear();
|
||||
@@ -222,7 +222,7 @@ std::map<std::string, std::vector<float>> parseScaleOrMean(const std::string& sc
|
||||
return return_value;
|
||||
}
|
||||
|
||||
std::vector<ngraph::Dimension> parsePartialShape(const std::string& partial_shape) {
|
||||
std::vector<ngraph::Dimension> parse_partial_shape(const std::string& partial_shape) {
|
||||
std::vector<ngraph::Dimension> shape;
|
||||
for (auto& dim : split(partial_shape, ',')) {
|
||||
if (dim == "?" || dim == "-1") {
|
||||
@@ -244,7 +244,7 @@ std::vector<ngraph::Dimension> parsePartialShape(const std::string& partial_shap
|
||||
return shape;
|
||||
}
|
||||
|
||||
ov::Shape parseDataShape(const std::string& dataShapeStr) {
|
||||
ov::Shape parse_data_shape(const std::string& dataShapeStr) {
|
||||
std::vector<size_t> shape;
|
||||
for (auto& dim : split(dataShapeStr, ',')) {
|
||||
shape.push_back(std::stoi(dim));
|
||||
@@ -252,7 +252,7 @@ ov::Shape parseDataShape(const std::string& dataShapeStr) {
|
||||
return shape;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::vector<std::string>> parseInputFiles(const std::string& file_paths_string) {
|
||||
std::pair<std::string, std::vector<std::string>> parse_input_files(const std::string& file_paths_string) {
|
||||
auto search_string = file_paths_string;
|
||||
std::string input_name = "";
|
||||
std::vector<std::string> file_paths;
|
||||
@@ -293,7 +293,7 @@ std::pair<std::string, std::vector<std::string>> parseInputFiles(const std::stri
|
||||
return {input_name, file_paths};
|
||||
}
|
||||
|
||||
std::map<std::string, std::vector<std::string>> parseInputArguments(const std::vector<std::string>& args) {
|
||||
std::map<std::string, std::vector<std::string>> parse_input_arguments(const std::vector<std::string>& args) {
|
||||
std::map<std::string, std::vector<std::string>> mapped_files = {};
|
||||
auto args_it = begin(args);
|
||||
const auto is_image_arg = [](const std::string& s) {
|
||||
@@ -310,7 +310,7 @@ std::map<std::string, std::vector<std::string>> parseInputArguments(const std::v
|
||||
const auto files_begin = std::next(files_start);
|
||||
const auto files_end = std::find_if(files_begin, end(args), is_arg);
|
||||
for (auto f = files_begin; f != files_end; ++f) {
|
||||
auto files = parseInputFiles(*f);
|
||||
auto files = parse_input_files(*f);
|
||||
if (mapped_files.find(files.first) == mapped_files.end()) {
|
||||
mapped_files[files.first] = {};
|
||||
}
|
||||
@@ -336,7 +336,7 @@ std::map<std::string, std::vector<std::string>> parseInputArguments(const std::v
|
||||
return mapped_files;
|
||||
}
|
||||
|
||||
std::map<std::string, std::vector<std::string>> parseInputParameters(
|
||||
std::map<std::string, std::vector<std::string>> parse_input_parameters(
|
||||
const std::string& parameter_string,
|
||||
const std::vector<ov::Output<const ov::Node>>& input_info) {
|
||||
// Parse parameter string like "input0[value0],input1[value1]" or "[value]" (applied to all
|
||||
@@ -371,19 +371,19 @@ std::map<std::string, std::vector<std::string>> parseInputParameters(
|
||||
return return_value;
|
||||
}
|
||||
|
||||
std::vector<benchmark_app::InputsInfo> getInputsInfo(const std::string& shape_string,
|
||||
const std::string& layout_string,
|
||||
const size_t batch_size,
|
||||
const std::string& data_shapes_string,
|
||||
const std::map<std::string, std::vector<std::string>>& fileNames,
|
||||
const std::string& scale_string,
|
||||
const std::string& mean_string,
|
||||
const std::vector<ov::Output<const ov::Node>>& input_info,
|
||||
bool& reshape_required) {
|
||||
std::map<std::string, std::vector<std::string>> shape_map = parseInputParameters(shape_string, input_info);
|
||||
std::vector<benchmark_app::InputsInfo> get_inputs_info(const std::string& shape_string,
|
||||
const std::string& layout_string,
|
||||
const size_t batch_size,
|
||||
const std::string& data_shapes_string,
|
||||
const std::map<std::string, std::vector<std::string>>& fileNames,
|
||||
const std::string& scale_string,
|
||||
const std::string& mean_string,
|
||||
const std::vector<ov::Output<const ov::Node>>& input_info,
|
||||
bool& reshape_required) {
|
||||
std::map<std::string, std::vector<std::string>> shape_map = parse_input_parameters(shape_string, input_info);
|
||||
std::map<std::string, std::vector<std::string>> data_shapes_map =
|
||||
parseInputParameters(data_shapes_string, input_info);
|
||||
std::map<std::string, std::vector<std::string>> layout_map = parseInputParameters(layout_string, input_info);
|
||||
parse_input_parameters(data_shapes_string, input_info);
|
||||
std::map<std::string, std::vector<std::string>> layout_map = parse_input_parameters(layout_string, input_info);
|
||||
|
||||
size_t min_size = 1, max_size = 1;
|
||||
if (!data_shapes_map.empty()) {
|
||||
@@ -492,7 +492,7 @@ std::vector<benchmark_app::InputsInfo> getInputsInfo(const std::string& shape_st
|
||||
throw std::logic_error(
|
||||
"shape command line parameter doesn't support multiple shapes for one input.");
|
||||
}
|
||||
info.partialShape = parsePartialShape(shape_map.at(name)[0]);
|
||||
info.partialShape = parse_partial_shape(shape_map.at(name)[0]);
|
||||
reshape_required = true;
|
||||
} else {
|
||||
info.partialShape = item.get_partial_shape();
|
||||
@@ -505,10 +505,10 @@ std::vector<benchmark_app::InputsInfo> getInputsInfo(const std::string& shape_st
|
||||
|
||||
// Tensor Shape
|
||||
if (info.partialShape.is_dynamic() && data_shapes_map.count(name)) {
|
||||
info.dataShape = parseDataShape(data_shapes_map.at(name)[i % data_shapes_map.at(name).size()]);
|
||||
} else if (info.partialShape.is_dynamic() && fileNames.count(filesInputName) && info.isImage()) {
|
||||
info.dataShape = parse_data_shape(data_shapes_map.at(name)[i % data_shapes_map.at(name).size()]);
|
||||
} else if (info.partialShape.is_dynamic() && fileNames.count(filesInputName) && info.is_image()) {
|
||||
auto& namesVector = fileNames.at(filesInputName);
|
||||
if (containsBinaries(namesVector)) {
|
||||
if (contains_binaries(namesVector)) {
|
||||
throw std::logic_error("Input files list for input " + item.get_any_name() +
|
||||
" contains binary file(s) and input shape is dynamic. Tensor shape should "
|
||||
"be defined explicitly (using -tensor_shape).");
|
||||
@@ -603,11 +603,11 @@ std::vector<benchmark_app::InputsInfo> getInputsInfo(const std::string& shape_st
|
||||
}
|
||||
|
||||
// Update scale and mean
|
||||
std::map<std::string, std::vector<float>> scale_map = parseScaleOrMean(scale_string, info_map);
|
||||
std::map<std::string, std::vector<float>> mean_map = parseScaleOrMean(mean_string, info_map);
|
||||
std::map<std::string, std::vector<float>> scale_map = parse_scale_or_mean(scale_string, info_map);
|
||||
std::map<std::string, std::vector<float>> mean_map = parse_scale_or_mean(mean_string, info_map);
|
||||
|
||||
for (auto& item : info_map) {
|
||||
if (item.second.isImage()) {
|
||||
if (item.second.is_image()) {
|
||||
item.second.scale.assign({1, 1, 1});
|
||||
item.second.mean.assign({0, 0, 0});
|
||||
|
||||
@@ -626,24 +626,24 @@ std::vector<benchmark_app::InputsInfo> getInputsInfo(const std::string& shape_st
|
||||
return info_maps;
|
||||
}
|
||||
|
||||
std::vector<benchmark_app::InputsInfo> getInputsInfo(const std::string& shape_string,
|
||||
const std::string& layout_string,
|
||||
const size_t batch_size,
|
||||
const std::string& tensors_shape_string,
|
||||
const std::map<std::string, std::vector<std::string>>& fileNames,
|
||||
const std::string& scale_string,
|
||||
const std::string& mean_string,
|
||||
const std::vector<ov::Output<const ov::Node>>& input_info) {
|
||||
std::vector<benchmark_app::InputsInfo> get_inputs_info(const std::string& shape_string,
|
||||
const std::string& layout_string,
|
||||
const size_t batch_size,
|
||||
const std::string& tensors_shape_string,
|
||||
const std::map<std::string, std::vector<std::string>>& fileNames,
|
||||
const std::string& scale_string,
|
||||
const std::string& mean_string,
|
||||
const std::vector<ov::Output<const ov::Node>>& input_info) {
|
||||
bool reshape_required = false;
|
||||
return getInputsInfo(shape_string,
|
||||
layout_string,
|
||||
batch_size,
|
||||
tensors_shape_string,
|
||||
fileNames,
|
||||
scale_string,
|
||||
mean_string,
|
||||
input_info,
|
||||
reshape_required);
|
||||
return get_inputs_info(shape_string,
|
||||
layout_string,
|
||||
batch_size,
|
||||
tensors_shape_string,
|
||||
fileNames,
|
||||
scale_string,
|
||||
mean_string,
|
||||
input_info,
|
||||
reshape_required);
|
||||
}
|
||||
|
||||
#ifdef USE_OPENCV
|
||||
@@ -748,29 +748,29 @@ const std::vector<std::string> supported_image_extensions = {"bmp"};
|
||||
#endif
|
||||
const std::vector<std::string> supported_binary_extensions = {"bin"};
|
||||
|
||||
std::string getExtension(const std::string& name) {
|
||||
std::string get_extension(const std::string& name) {
|
||||
auto extensionPosition = name.rfind('.', name.size());
|
||||
return extensionPosition == std::string::npos ? "" : name.substr(extensionPosition + 1, name.size() - 1);
|
||||
};
|
||||
|
||||
bool isBinaryFile(const std::string& filePath) {
|
||||
auto extension = getExtension(filePath);
|
||||
bool is_binary_file(const std::string& filePath) {
|
||||
auto extension = get_extension(filePath);
|
||||
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
|
||||
return std::find(supported_binary_extensions.begin(), supported_binary_extensions.end(), extension) !=
|
||||
supported_binary_extensions.end();
|
||||
}
|
||||
|
||||
bool isImageFile(const std::string& filePath) {
|
||||
auto extension = getExtension(filePath);
|
||||
bool is_image_file(const std::string& filePath) {
|
||||
auto extension = get_extension(filePath);
|
||||
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
|
||||
return std::find(supported_binary_extensions.begin(), supported_binary_extensions.end(), extension) !=
|
||||
supported_binary_extensions.end();
|
||||
}
|
||||
|
||||
bool containsBinaries(const std::vector<std::string>& filePaths) {
|
||||
bool contains_binaries(const std::vector<std::string>& filePaths) {
|
||||
std::vector<std::string> filtered;
|
||||
for (auto& filePath : filePaths) {
|
||||
auto extension = getExtension(filePath);
|
||||
auto extension = get_extension(filePath);
|
||||
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
|
||||
if (std::find(supported_binary_extensions.begin(), supported_binary_extensions.end(), extension) !=
|
||||
supported_binary_extensions.end()) {
|
||||
@@ -779,15 +779,15 @@ bool containsBinaries(const std::vector<std::string>& filePaths) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> filterFilesByExtensions(const std::vector<std::string>& filePaths,
|
||||
const std::vector<std::string>& extensions) {
|
||||
std::vector<std::string> filter_files_by_extensions(const std::vector<std::string>& filePaths,
|
||||
const std::vector<std::string>& extensions) {
|
||||
std::vector<std::string> filtered;
|
||||
for (auto& filePath : filePaths) {
|
||||
auto extension = getExtension(filePath);
|
||||
auto extension = get_extension(filePath);
|
||||
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
|
||||
if (std::find(extensions.begin(), extensions.end(), extension) != extensions.end()) {
|
||||
filtered.push_back(filePath);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user