Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Check if model file exists on read model #24864

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cc30473
Check if model and weights files exists on read model
praasz Jun 5, 2024
e854fb0
Remove not required using from core tests
praasz Jun 5, 2024
6cf0a3f
Checks weights path when specified
praasz Jun 5, 2024
b87dc78
Apply suggestions from code review
ilya-lavrenov Jun 5, 2024
3963312
FEs throw exception if model file cannot be found
praasz Jun 13, 2024
ad806a5
Add "" for model path in exception message
praasz Jun 17, 2024
525e45f
Correct variables names
praasz Jun 17, 2024
93a7e62
Fix print path in exception
praasz Jun 17, 2024
00316e1
Fix test
praasz Jun 17, 2024
adbab90
Add path to string conversion util
praasz Jun 18, 2024
db3caa0
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
mlukasze Jun 19, 2024
22e0107
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
mlukasze Jun 20, 2024
cd032d8
Remove using regex for path not working correctly on win
praasz Jun 20, 2024
d4bee10
Update exception throw logic for MO
praasz Jun 20, 2024
881ed36
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
mlukasze Jun 21, 2024
187d0ab
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
mlukasze Jun 25, 2024
a0d490e
Fix ONNX tests
praasz Jun 20, 2024
16a9835
Merge remote-tracking branch 'origin/master' into improve-error-msg-w…
praasz Jun 25, 2024
293bc1d
Corrects TF FE iterator path check
praasz Jun 26, 2024
a23a5c0
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
mlukasze Jun 28, 2024
f96d52a
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
mlukasze Jul 1, 2024
a6a2b46
Fix MO test with temporary file
praasz Jul 1, 2024
ef460ce
Add FE name to exception message
praasz Jul 1, 2024
3cc02ed
Update path validation in frontends
praasz Jul 1, 2024
69b60aa
Fix create tmp file in test_failed_extension test
praasz Jul 1, 2024
07715ea
Fix create tmp file in pytorch test_failed_extension test
praasz Jul 2, 2024
d9563ab
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
mlukasze Jul 2, 2024
cbd1eb9
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
praasz Jul 2, 2024
6c6848d
Merge branch 'master' into improve-error-msg-when-model-no-found-on-disk
mlukasze Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/inference/src/model_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ std::shared_ptr<ov::Model> read_model(const std::string& modelPath,
const std::string& binPath,
const std::vector<ov::Extension::Ptr>& extensions,
bool enable_mmap) {
OPENVINO_ASSERT(file_exists(modelPath.c_str()), "Model file not exists at: ", modelPath);

// Fix unicode name
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
std::wstring model_path = ov::util::string_to_wstring(modelPath.c_str());
Expand All @@ -126,6 +128,7 @@ std::shared_ptr<ov::Model> read_model(const std::string& modelPath,
ov::AnyVector params{model_path};

if (!binPath.empty()) {
OPENVINO_ASSERT(file_exists(binPath.c_str()), "Model's weights file not exists at: ", binPath);
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
const std::wstring& weights_path = ov::util::string_to_wstring(binPath.c_str());
#else
Expand Down
32 changes: 31 additions & 1 deletion src/inference/tests/unit/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "openvino/runtime/device_id_parser.hpp"
#include "openvino/util/file_util.hpp"

using namespace testing;
using namespace ov::util;

TEST(CoreTests, Throw_on_register_plugin_twice) {
Expand Down Expand Up @@ -407,6 +406,37 @@ TEST(CoreTests_parse_device_config, get_batch_device_name) {
::testing::HasSubstr("BATCH accepts only one device in list but got 'CPU,GPU'"));
}

TEST(CoreTests_read_model, model_not_exist_at_path) {
ov::Core core;

auto model_file_path = ov::test::utils::generateTestFilePrefix();
model_file_path += "not_existing_model.xml";

OV_EXPECT_THROW(core.read_model(model_file_path),
ov::Exception,
testing::HasSubstr("Model file not exists at: " + model_file_path));
}

TEST(CoreTests_read_model, model_weights_not_exist_at_path) {
ov::Core core;

const auto name_prefix = ov::test::utils::generateTestFilePrefix();
const auto model_file_path = name_prefix + "existing_model.xml";
const auto weights_file_path = name_prefix + "not_existing_weights.xml";

{
std::ofstream model_file;
model_file.open(model_file_path);
model_file.close();
}

OV_EXPECT_THROW(core.read_model(model_file_path, weights_file_path),
ov::Exception,
testing::HasSubstr("Model's weights file not exists at: " + weights_file_path));

std::remove(model_file_path.c_str());
}

class ApplyAutoBatchThreading : public testing::Test {
public:
static void runParallel(std::function<void(void)> func,
Expand Down
Loading