Can you try something like this? First you need to read-in a model, the iterate over the nodes in the graph and filter the Constants (I'm making a copy here because the nodes are held as shared pointers). Then each Constant node can be transformed into a vector of values if you're looking for that. To do that you can use the templated method cast_vector<T>
and you can figure out which type to use by checking what the Constant holds (using get_element_type
).
const auto model = core.read_model("path");
std::vector<std::shared_ptr<ov::op::v0::Constant>> weights;
const auto ops = model->get_ops();
std::copy_if(std::begin(ops), std::end(ops), std::back_inserter(weights), [](const std::shared_ptr<ov::Node>& op) {
return std::dynamic_pointer_cast<ov::op::v0::Constant>(op) != nullptr;
});
for (const auto& w : weights) {
if (w->get_element_type() == ov::element::Type_t::f32) {
const std::vector<float> floats = w->cast_vector<float>();
} else if (w->get_element_type() == ov::element::Type_t::i32) {
const std::vector<int32_t> ints = w->cast_vector<int32_t>();
} else if (...) {
...
}
}