Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 21 additions & 15 deletions src/frontends/paddle/src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,29 +381,35 @@ bool FrontEnd::supported_impl(const std::vector<ov::Any>& variants) const {

// Validating first path, it must contain a model
if (variants[0].is<std::string>()) {
std::string suffix = ".pdmodel";
std::string model_path = variants[0].as<std::string>();
FRONT_END_GENERAL_CHECK(util::file_exists(model_path), "Could not open the file: \"", model_path, '"');
if (!ov::util::ends_with(model_path, suffix)) {
model_path += paddle::get_path_sep<char>() + "__model__";
auto model_path = ov::util::make_path(variants[0].as<std::string>());
if (ov::util::directory_exists(model_path)) {
model_path /= "__model__";
FRONT_END_GENERAL_CHECK(util::file_exists(model_path), "Could not open the file: ", model_path);
} else {
FRONT_END_GENERAL_CHECK(util::file_exists(model_path), "Could not open the file: ", model_path);
if (model_path.extension() != ".pdmodel") {
return false;
}
}
std::ifstream model_str(model_path, std::ios::in | std::ifstream::binary);

std::ifstream model_str(model_path, std::ifstream::binary);
// It is possible to validate here that protobuf can read model from the stream,
// but it will complicate the check, while it should be as quick as possible
return model_str && model_str.is_open();
}
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
else if (variants[0].is<std::wstring>()) {
std::wstring suffix = L".pdmodel";
std::wstring model_path = variants[0].as<std::wstring>();
FRONT_END_GENERAL_CHECK(util::file_exists(model_path),
"Could not open the file: \"",
util::path_to_string(model_path),
'"');
if (!ov::util::ends_with(model_path, suffix)) {
model_path += paddle::get_path_sep<wchar_t>() + L"__model__";
auto model_path = ov::util::make_path(variants[0].as<std::wstring>());
if (ov::util::directory_exists(model_path)) {
model_path /= L"__model__";
FRONT_END_GENERAL_CHECK(util::file_exists(model_path), "Could not open the file: ", model_path);
} else {
FRONT_END_GENERAL_CHECK(util::file_exists(model_path), "Could not open the file: ", model_path);
if (model_path.extension() != L".pdmodel") {
return false;
}
}
std::ifstream model_str(model_path.c_str(), std::ios::in | std::ifstream::binary);
std::ifstream model_str(model_path, std::ifstream::binary);
// It is possible to validate here that protobuf can read model from the stream,
// but it will complicate the check, while it should be as quick as possible
return model_str && model_str.is_open();
Expand Down
50 changes: 50 additions & 0 deletions src/frontends/paddle/tests/basic_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include "basic_api.hpp"

#include "common_test_utils/common_utils.hpp"
#include "common_test_utils/test_assertions.hpp"
#include "openvino/frontend/paddle/frontend.hpp"
#include "openvino/util/file_util.hpp"
#include "paddle_utils.hpp"

using namespace ov::frontend;
Expand All @@ -24,3 +28,49 @@ INSTANTIATE_TEST_SUITE_P(PaddleBasicTest,
::testing::Values(std::string(TEST_PADDLE_MODELS_DIRNAME)),
::testing::ValuesIn(models)),
FrontEndBasicTest::getTestCaseName);

TEST(PaddleBasicTest, check_supported_legacy_model) {
const auto test_dir = std::filesystem::path(ov::test::utils::generateTestFilePrefix());
const auto legacy_model_path = test_dir / "paddle_legacy.model";

{
ov::util::create_directory_recursive(legacy_model_path);
std::ofstream model(legacy_model_path / "__model__");
model << "Fake model data which are not important for this test";
}

paddle::FrontEnd fe;

EXPECT_TRUE(fe.supported({{legacy_model_path.native()}, {false}}));
EXPECT_FALSE(fe.supported({{legacy_model_path}, {false}})) << "Should be true if std path supported";

std::filesystem::remove_all(test_dir);
}

TEST(PaddleBasicTest, check_supported_legacy_model_not_exists) {
const auto test_dir = std::filesystem::path(ov::test::utils::generateTestFilePrefix());
const auto legacy_model_path = test_dir / "dir.with_dot" / "paddle_legacy_model";

paddle::FrontEnd fe;

OV_EXPECT_THROW(fe.supported({{legacy_model_path.native()}, {false}}), ov::Exception, testing::_);
EXPECT_FALSE(fe.supported({{legacy_model_path}, false})) << "Should throw if std path supported";
}

TEST(PaddleBasicTest, check_supported_incorrect_extension) {
const auto test_dir = std::filesystem::path(ov::test::utils::generateTestFilePrefix());
const auto model_path = test_dir / "model.onnx";

{
ov::util::create_directory_recursive(test_dir);
std::ofstream model(model_path);
model << "Fake model data which are not important for this test";
}

paddle::FrontEnd fe;

EXPECT_FALSE(fe.supported({{model_path.native()}, {false}}));
EXPECT_FALSE(fe.supported({{model_path}, {false}}));

std::filesystem::remove_all(test_dir);
}
Loading