@@ -122,6 +122,10 @@ cv::Mat segm_postprocess(const SegmentedObject& box, const cv::Mat& unpadded, in
122122}
123123
124124void InstanceSegmentation::serialize (std::shared_ptr<ov::Model>& ov_model) {
125+ if (utils::model_has_embedded_processing (ov_model)) {
126+ std::cout << " model already was serialized" << std::endl;
127+ return ;
128+ }
125129 if (ov_model->inputs ().size () != 1 ) {
126130 throw std::logic_error (" MaskRCNNModel model wrapper supports topologies with only 1 input" );
127131 }
@@ -187,23 +191,18 @@ void InstanceSegmentation::serialize(std::shared_ptr<ov::Model>& ov_model) {
187191}
188192
189193InstanceSegmentation InstanceSegmentation::load (const std::string& model_path) {
190- auto core = ov::Core ();
191- std::shared_ptr<ov::Model> model = core.read_model (model_path);
192-
193- if (model->has_rt_info (" model_info" , " model_type" )) {
194- std::cout << " has model type in info: " << model->get_rt_info <std::string>(" model_info" , " model_type" )
195- << std::endl;
196- } else {
197- throw std::runtime_error (" Incorrect or unsupported model_type" );
198- }
194+ auto adapter = std::make_shared<OpenVINOInferenceAdapter>();
195+ adapter->loadModelFile (model_path, " " , {}, false );
199196
200- if (utils::model_has_embedded_processing (model)) {
201- std::cout << " model already was serialized" << std::endl;
202- } else {
203- serialize (model);
197+ std::string model_type;
198+ model_type = utils::get_from_any_maps (" model_type" , adapter->getModelConfig (), {}, model_type);
199+
200+ if (model_type.empty () || model_type != " MaskRCNN" ) {
201+ throw std::runtime_error (" Incorrect or unsupported model_type, expected: MaskRCNN" );
204202 }
205- auto adapter = std::make_shared<OpenVINOInferenceAdapter>();
206- adapter->loadModel (model, core, " AUTO" );
203+ adapter->applyModelTransform (InstanceSegmentation::serialize);
204+ adapter->compileModel (" AUTO" , {});
205+
207206 return InstanceSegmentation (adapter);
208207}
209208
0 commit comments