if (initializer_tensor.has_name())
{
Tensor tensor = Tensor{initializer_tensor};
- initializers.emplace(initializer_tensor.name(), tensor);
-
+ std::shared_ptr<default_opset::Constant> ng_constant;
// For each initializer create a Constant node and store it in cache
- auto ng_constant = tensor.get_ng_constant();
+ try
+ {
+ ng_constant = tensor.get_ng_constant();
+ }
+ catch (const ngraph::ngraph_error& exc)
+ {
+ NGRAPH_WARN << "Could not create an nGraph Constant for initializer '"
+ << initializer_tensor.name() << "'. Detailed error:\n"
+ << exc.what();
+ ng_constant =
+ default_opset::Constant::create(tensor.get_ng_type(), Shape{}, {0});
+ }
+
+ initializers.emplace(initializer_tensor.name(), tensor);
add_provenance_tag_to_initializer(tensor, ng_constant);
m_cache->emplace_node(initializer_tensor.name(), std::move(ng_constant));
}
{12.0, 14.0, 16.0, 18.0, 21.0, 41.0, 61.0, 81.0});
test_case.run();
}
+
+NGRAPH_TEST(${BACKEND_NAME}, onnx_empty_initializers_handling)
+{
+ // int this test the "scales" input of the Resize operator is set to an empty initializer
+ // this input should be ignored since the "sizes" optional input is provided
+ // and the inference should use the data from the latter
+ const auto function = onnx_import::import_onnx_model(
+ file_util::path_join(SERIALIZED_ZOO, "onnx/empty_initializers_handling.prototxt"));
+
+ const Shape expected_output_shape{2, 1, 4, 8};
+ auto test_case = test::TestCase<TestEngine>(function);
+ std::vector<float> input_data{2.0f, 4.0f, 1.0f, 3.0f, 7.0f, 8.0f, 9.0f, 6.0f};
+ test_case.add_input<float>(input_data);
+ test_case.add_expected_output<float>(
+ expected_output_shape,
+ {2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.0f, 4.0f, 4.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f,
+ 3.5f, 3.5f, 3.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 1.0f, 1.5f,
+ 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 7.0f, 7.25f, 7.5f, 7.75f, 8.0f, 8.0f, 8.0f,
+ 8.0f, 8.0f, 7.75f, 7.5f, 7.25f, 7.0f, 7.0f, 7.0f, 7.0f, 9.0f, 8.25f, 7.5f, 6.75f,
+ 6.0f, 6.0f, 6.0f, 6.0f, 9.0f, 8.25f, 7.5f, 6.75f, 6.0f, 6.0f, 6.0f, 6.0f});
+
+ test_case.run();
+}