This commit is contained in:
Daniel 2024-06-12 03:26:41 +02:00 committed by GitHub
commit c7f48601b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View File

@ -251,6 +251,20 @@ void ov::Model::validate_nodes_and_infer_types() const {
"Model references undeclared Variables: ",
unregistered_variables.str());
for (const auto& input : inputs()) {
const auto& p_shape = input.get_partial_shape();
const auto& layout = ov::layout::get_layout(input);
if (p_shape.rank().is_static() && p_shape.rank() != 0 && ov::layout::has_batch(layout)) {
const auto batch_idx = ov::layout::batch_idx(layout);
const auto& batch_dim = p_shape[batch_idx];
OPENVINO_ASSERT(batch_dim.is_dynamic() || batch_dim.get_length() > 0,
"Batch size must be a positive value for input '",
input,
"', but has got: ",
batch_dim.get_length());
}
}
for (const auto& output : outputs()) {
OPENVINO_ASSERT(ov::layout::utils::is_compatible(ov::layout::get_layout(output), output.get_partial_shape()),
"Result '",

View File

@ -2137,3 +2137,20 @@ TEST(model, create_model) {
EXPECT_THROW(ov::Model(ov::ResultVector{}, {}, {}, {nullptr}, ""), ov::Exception);
EXPECT_THROW(ov::Model(ov::OutputVector{ov::Output<ov::Node>{nullptr, 0}}, {}, {}, {}, ""), ov::Exception);
}
TEST(model, batch_size_zero) {
OV_EXPECT_THROW_HAS_SUBSTRING(bs_utils::create_n_inputs(ov::element::f32, {{0, 3, 16, 16}}, {"NCHW"}),
ov::Exception,
"Batch size must be a positive value for input 'opset1::Parameter input0");
OV_EXPECT_THROW_HAS_SUBSTRING(
bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}, {0, 3, 16, 16}}, {"NCHW", "NCHW"}),
ov::Exception,
"Batch size must be a positive value for input 'opset1::Parameter input1");
OV_EXPECT_THROW_HAS_SUBSTRING(
bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}}, {"NCHW"})->reshape({0, 3, 16, 16}),
ov::Exception,
"Batch size must be a positive value for input 'opset1::Parameter input0");
OV_EXPECT_THROW_HAS_SUBSTRING(set_batch(bs_utils::create_n_inputs(ov::element::f32, {{1, 3, 16, 16}}, {"NCHW"}), 0),
ov::Exception,
"Batch size must be a positive value for input 'opset1::Parameter input0");
}