Skip to content

Commit

Permalink
Merge branch 'master' into issue#27715
Browse files Browse the repository at this point in the history
  • Loading branch information
amanmogal authored Dec 8, 2024
2 parents 61cf09e + e8fa9f7 commit 0ba97f5
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 43 deletions.
4 changes: 4 additions & 0 deletions src/core/shape_inference/include/ov_optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <cstddef>

namespace ov {
#ifdef OPENVINO_CPP_17_VER
using optional = std::optional;
#else

/**
* @brief Store optional object of type T (basic version of std::optional).
Expand Down Expand Up @@ -132,4 +135,5 @@ class optional {
bool m_has_value = false;
Storage<T> m_opt{};
};
#endif
} // namespace ov
6 changes: 3 additions & 3 deletions src/core/tests/pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ TEST(pattern, multiple_optionals_in_row) {

// Pattern:
auto in = wrap_type<v0::Parameter>();
auto pattern_convert = optional<v0::Convert>(in);
auto pattern_relu = optional<v0::Relu>(pattern_convert);
auto pattern_convert = pattern::optional<v0::Convert>(in);
auto pattern_relu = pattern::optional<v0::Relu>(pattern_convert);
auto pattern_sigmoid = wrap_type<v0::Sigmoid>({pattern_relu});

// Test:
Expand Down Expand Up @@ -1255,4 +1255,4 @@ TEST(pattern, pattern_optional_root) {

// Should perfectly match
ASSERT_TRUE(tm.match(pattern_relu, model_relu));
}
}
50 changes: 50 additions & 0 deletions src/inference/include/openvino/runtime/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "openvino/runtime/remote_context.hpp"
#include "openvino/runtime/tensor.hpp"

#ifdef OPENVINO_CPP_VER_17
# include <filesystem>
#endif

namespace ov {

/**
Expand Down Expand Up @@ -95,9 +99,18 @@ class OPENVINO_RUNTIME_API Core {
* * TF (*.pb)
* * TFLite (*.tflite)
* @return A model.
* @{
*/
std::shared_ptr<ov::Model> read_model(const std::string& model_path, const std::string& bin_path = {}) const;

#ifdef OPENVINO_CPP_VER_17
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
std::shared_ptr<ov::Model> read_model(const Path& model_path, const Path& bin_path = {}) const {
return read_model(model_path.string(), bin_path.string());
}
#endif
/// @}

/**
* @brief Reads models from IR / ONNX / PDPD / TF / TFLite formats.
* @param model String with a model in IR / ONNX / PDPD / TF / TFLite format.
Expand Down Expand Up @@ -197,6 +210,13 @@ class OPENVINO_RUNTIME_API Core {
*/
CompiledModel compile_model(const std::string& model_path, const AnyMap& properties = {});

#ifdef OPENVINO_CPP_VER_17
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
auto compile_model(const Path& model_path, const AnyMap& properties = {}) const {
return compile_model(model_path.string(), properties);
}
#endif

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
CompiledModel compile_model(const std::wstring& model_path, const AnyMap& properties = {});
#endif
Expand All @@ -223,6 +243,13 @@ class OPENVINO_RUNTIME_API Core {
return compile_model(model_path, AnyMap{std::forward<Properties>(properties)...});
}

#ifdef OPENVINO_CPP_VER_17
template <class Path, class... Properties, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
auto compile_model(const Path& model_path, Properties&&... properties) {
return compile_model(model_path.string(), std::forward<Properties>(properties)...);
}
#endif

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
template <typename... Properties>
util::EnableIfAllStringAny<CompiledModel, Properties...> compile_model(const std::wstring& model_path,
Expand Down Expand Up @@ -250,6 +277,13 @@ class OPENVINO_RUNTIME_API Core {
const std::string& device_name,
const AnyMap& properties = {});

#ifdef OPENVINO_CPP_VER_17
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
auto compile_model(const Path& model_path, const std::string& device_name, const AnyMap& properties = {}) {
return compile_model(model_path.string(), device_name, properties);
}
#endif

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
CompiledModel compile_model(const std::wstring& model_path,
const std::string& device_name,
Expand Down Expand Up @@ -279,6 +313,13 @@ class OPENVINO_RUNTIME_API Core {
return compile_model(model_path, device_name, AnyMap{std::forward<Properties>(properties)...});
}

#ifdef OPENVINO_CPP_VER_17
template <class Path, class... Properties, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
auto compile_model(const Path& model_path, const std::string& device_name, Properties&&... properties) {
return compile_model(model_path.string(), device_name, std::forward<Properties>(properties)...);
}
#endif

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
template <typename... Properties>
util::EnableIfAllStringAny<CompiledModel, Properties...> compile_model(const std::wstring& model_path,
Expand Down Expand Up @@ -359,9 +400,18 @@ class OPENVINO_RUNTIME_API Core {
/**
* @brief Registers an extension to a Core object.
* @param library_path Path to the library with ov::Extension.
* @{
*/
void add_extension(const std::string& library_path);

#ifdef OPENVINO_CPP_VER_17
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
void add_extension(const Path& model_path) {
add_extension(model_path.string());
}
#endif
/// @}

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
/**
* @brief Registers an extension to a Core object.
Expand Down
69 changes: 63 additions & 6 deletions src/inference/tests/functional/ov_core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@

#include "common_test_utils/common_utils.hpp"
#include "common_test_utils/file_utils.hpp"
#include "functional_test_utils/test_model/test_model.hpp"
#include "openvino/runtime/core.hpp"
#include "openvino/util/file_util.hpp"

class CoreBaseTest : public testing::Test {
protected:
void generate_test_model_files(const std::string& name) {
auto prefix = ov::test::utils::generateTestFilePrefix();
model_file_name = prefix + name + ".xml";
weight_file_name = prefix + name + ".bin";
ov::test::utils::generate_test_model(model_file_name, weight_file_name);
}

void TearDown() override {
ov::test::utils::removeIRFiles(model_file_name, weight_file_name);
}

std::string model_file_name, weight_file_name;
};

#ifndef OPENVINO_STATIC_LIBRARY

static void create_plugin_xml(const std::string& file_name, const std::string& plugin_name = "1") {
Expand All @@ -33,7 +50,7 @@ static void remove_plugin_xml(const std::string& file_name) {
ov::test::utils::removeFile(file_name);
}

TEST(CoreBaseTest, LoadPluginXML) {
TEST_F(CoreBaseTest, LoadPluginXML) {
std::string xml_file_name = "test_plugin.xml";
std::string xml_file_path =
ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits<char>::file_separator + xml_file_name;
Expand All @@ -42,7 +59,7 @@ TEST(CoreBaseTest, LoadPluginXML) {
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadPluginDifferentXMLExtension) {
TEST_F(CoreBaseTest, LoadPluginDifferentXMLExtension) {
std::string xml_file_name = "test_plugin.test";
std::string xml_file_path =
ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits<char>::file_separator + xml_file_name;
Expand All @@ -51,7 +68,7 @@ TEST(CoreBaseTest, LoadPluginDifferentXMLExtension) {
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadAbsoluteOVPathPluginXML) {
TEST_F(CoreBaseTest, LoadAbsoluteOVPathPluginXML) {
std::string xml_file_name = "test_plugin.xml";
std::string xml_file_path =
ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits<char>::file_separator + xml_file_name;
Expand All @@ -60,7 +77,7 @@ TEST(CoreBaseTest, LoadAbsoluteOVPathPluginXML) {
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadAbsoluteCWPathPluginXML) {
TEST_F(CoreBaseTest, LoadAbsoluteCWPathPluginXML) {
std::string xml_file_name = "test_plugin.xml";
std::string xml_file_path =
ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::file_separator + xml_file_name;
Expand All @@ -69,7 +86,7 @@ TEST(CoreBaseTest, LoadAbsoluteCWPathPluginXML) {
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadRelativeCWPathPluginXML) {
TEST_F(CoreBaseTest, LoadRelativeCWPathPluginXML) {
std::string xml_file_name = "test_plugin.xml";
std::string xml_file_path =
ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::file_separator + xml_file_name;
Expand All @@ -78,7 +95,7 @@ TEST(CoreBaseTest, LoadRelativeCWPathPluginXML) {
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadOVFolderOverCWPathPluginXML) {
TEST_F(CoreBaseTest, LoadOVFolderOverCWPathPluginXML) {
std::string xml_file_name = "test_plugin.xml";
std::string cwd_file_path =
ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::file_separator + xml_file_name;
Expand All @@ -96,3 +113,43 @@ TEST(CoreBaseTest, LoadOVFolderOverCWPathPluginXML) {
}

#endif

#if defined(OPENVINO_CPP_VER_17) && defined(ENABLE_OV_IR_FRONTEND)
namespace ov::test {
TEST_F(CoreBaseTest, read_model_with_std_fs_path) {
generate_test_model_files("test-model");

const auto model_path = std::filesystem::path(model_file_name);
const auto weight_path = std::filesystem::path(weight_file_name);

ov::Core core;
{
const auto model = core.read_model(model_path);
EXPECT_NE(model, nullptr);
}
{
const auto model = core.read_model(model_path, weight_path);
EXPECT_NE(model, nullptr);
}
}

TEST_F(CoreBaseTest, compile_model_with_std_fs_path) {
generate_test_model_files("model2");

const auto model_path = std::filesystem::path(model_file_name);
const auto weight_path = std::filesystem::path(weight_file_name);

ov::Core core;
{
const auto model = core.compile_model(model_path);
EXPECT_TRUE(model);
}
{
const auto devices = core.get_available_devices();

const auto model = core.compile_model(model_path, devices.at(0), ov::AnyMap{});
EXPECT_TRUE(model);
}
}
} // namespace ov::test
#endif
6 changes: 6 additions & 0 deletions src/inference/tests/functional/ov_extension_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class CustomReLU : public ov::op::Op {
};

#if defined(ENABLE_OV_IR_FRONTEND)
# ifdef OPENVINO_CPP_VER_17
TEST_F(OVExtensionTests, ReshapeIRWithNewExtensionsPathLib) {
core.add_extension(std::filesystem::path(getOVExtensionPath()));
test();
}
# endif

TEST_F(OVExtensionTests, ReshapeIRWithNewExtensionsLib) {
core.add_extension(getOVExtensionPath());
Expand Down
53 changes: 19 additions & 34 deletions tests/layer_tests/tensorflow_tests/test_tf_HSVToRGB.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import platform

import numpy as np
import pytest
import tensorflow as tf
from common.tf_layer_test_class import CommonTFLayerTest

rng = np.random.default_rng(23345)


class TestHSVToRGB(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
assert 'images:0' in inputs_info
if self.special_case == "Black Image":
images_shape = inputs_info['images:0']
inputs_data = {}
inputs_data['images:0'] = np.zeros(images_shape).astype(self.input_type)
elif self.special_case == "Grayscale Image":
images_shape = inputs_info['images:0']
inputs_data = {}
images_shape = inputs_info['images:0']
inputs_data = {}
if self.special_case == 'Black Image':
inputs_data['images:0'] = np.zeros(images_shape).astype(self.input_type)
elif self.special_case == 'Grayscale Image':
inputs_data['images:0'] = np.broadcast_to([0, 0, 0.5], images_shape).astype(self.input_type)
else:
images_shape = inputs_info['images:0']
inputs_data = {}
inputs_data['images:0'] = np.random.rand(*images_shape).astype(self.input_type)

inputs_data['images:0'] = rng.uniform(0.0, 1.0, images_shape).astype(self.input_type)
return inputs_data

def create_hsv_to_rgb_net(self, input_shape, input_type, special_case=False):
def create_hsv_to_rgb_net(self, input_shape, input_type, special_case):
self.special_case = special_case
self.input_type = input_type
tf.compat.v1.reset_default_graph()
Expand All @@ -39,27 +35,16 @@ def create_hsv_to_rgb_net(self, input_shape, input_type, special_case=False):

return tf_net, None

# Each input is a tensor of with values in [0,1].
# The last dimension must be size 3.
test_data_basic = [
dict(input_shape=[7, 7, 3], input_type=np.float32, special_case="Black Image"),
dict(input_shape=[7, 7, 3], input_type=np.float32, special_case="Grayscale Image"),
dict(input_shape=[5, 5, 3], input_type=np.float32),
dict(input_shape=[5, 23, 27, 3], input_type=np.float64),
dict(input_shape=[3, 4, 13, 15, 3], input_type=np.float64),
]

@pytest.mark.parametrize("params", test_data_basic)
@pytest.mark.parametrize('input_shape', [[3], [5, 3], [4, 5, 3], [5, 21, 21, 3]])
@pytest.mark.parametrize('input_type', [np.float16, np.float32, np.float64])
@pytest.mark.parametrize('special_case', [None, 'Black Image', 'Grayscale Image'])
@pytest.mark.precommit
@pytest.mark.nightly
@pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ['arm', 'armv7l',
'aarch64',
'arm64', 'ARM64'],
reason='Ticket - 126314, 132699')
def test_hsv_to_rgb_basic(self, params, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
def test_hsv_to_rgb_basic(self, input_shape, input_type, special_case,
ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
if ie_device == 'GPU':
pytest.skip("Accuracy mismatch on GPU")
self._test(*self.create_hsv_to_rgb_net(**params),
pytest.skip('158898: accuracy issue on GPU')
self._test(*self.create_hsv_to_rgb_net(input_shape, input_type, special_case),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)
use_legacy_frontend=use_legacy_frontend, custom_eps=3 * 1e-3)

0 comments on commit 0ba97f5

Please sign in to comment.