2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __OBJECT_DETECTION_H__
18 #define __OBJECT_DETECTION_H__
25 #include <mv_common.h>
26 #include <mv_inference_type.h>
27 #include "mv_private.h"
29 #include "EngineConfig.h"
30 #include "inference_engine_common_impl.h"
31 #include "Inference.h"
32 #include "object_detection_type.h"
33 #include "ObjectDetectionParser.h"
34 #include "machine_learning_preprocess.h"
35 #include "iobject_detection.h"
36 #include "async_manager.h"
40 namespace machine_learning
42 class ObjectDetection : public IObjectDetection
45 ObjectDetectionTaskType _task_type;
46 std::unique_ptr<AsyncManager<ObjectDetectionResult> > _async_manager;
47 ObjectDetectionResult _current_result {};
51 void getDeviceList(const char *engine_type);
53 void preprocess(mv_source_h &mv_src, std::shared_ptr<MetaInfo> metaInfo, std::vector<T> &inputVector);
54 std::shared_ptr<MetaInfo> getInputMetaInfo();
55 template<typename T> void perform(mv_source_h &mv_src, std::shared_ptr<MetaInfo> metaInfo);
56 template<typename T> void performAsync(ObjectDetectionInput &input, std::shared_ptr<MetaInfo> metaInfo);
59 std::unique_ptr<mediavision::inference::Inference> _inference;
60 std::unique_ptr<MediaVision::Common::EngineConfig> _config;
61 std::unique_ptr<MetaParser> _parser;
62 std::vector<std::string> _labels;
63 std::vector<std::string> _valid_backends;
64 std::vector<std::string> _valid_devices;
65 Preprocess _preprocess;
66 std::string _modelFilePath;
67 std::string _modelMetaFilePath;
68 std::string _modelDefaultPath;
69 std::string _modelLabelFilePath;
71 int _targetDeviceType;
73 void getOutputNames(std::vector<std::string> &names);
74 void getOutputTensor(std::string target_name, std::vector<float> &tensor);
75 void parseMetaFile(std::string meta_file_name);
76 template<typename T> void inference(std::vector<std::vector<T> > &inputVectors);
77 virtual ObjectDetectionResult &result() = 0;
80 ObjectDetection(ObjectDetectionTaskType task_type);
81 virtual ~ObjectDetection() = default;
82 void preDestroy() override;
83 ObjectDetectionTaskType getTaskType() override;
84 void setUserModel(std::string model_file, std::string meta_file, std::string label_file) override;
85 void setEngineInfo(std::string engine_type, std::string device_type) override;
86 void getNumberOfEngines(unsigned int *number_of_engines) override;
87 void getEngineType(unsigned int engine_index, char **engine_type) override;
88 void getNumberOfDevices(const char *engine_type, unsigned int *number_of_devices) override;
89 void getDeviceType(const char *engine_type, const unsigned int device_index, char **device_type) override;
90 void configure(std::string configFile) override;
91 void prepare() override;
92 void perform(mv_source_h &mv_src) override;
93 void performAsync(ObjectDetectionInput &input) override;
94 ObjectDetectionResult &getOutput() override;
95 ObjectDetectionResult &getOutputCache() override;