mv_machine_learning: use carnel notation
[platform/core/api/mediavision.git] / mv_machine_learning / image_classification / src / image_classification_adapter.cpp
1 /**
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <string>
18
19 #include "machine_learning_exception.h"
20 #include "mv_image_classification_config.h"
21 #include "image_classification_adapter.h"
22
23 using namespace std;
24 using namespace MediaVision::Common;
25 using namespace mediavision::machine_learning;
26 using namespace mediavision::machine_learning::exception;
27
28 namespace mediavision
29 {
30 namespace machine_learning
31 {
32 template<typename T, typename V> ImageClassificationAdapter<T, V>::ImageClassificationAdapter() : _source()
33 {
34         _image_classification = make_unique<ImageClassificationDefault>();
35 }
36
37 template<typename T, typename V> ImageClassificationAdapter<T, V>::~ImageClassificationAdapter()
38 {}
39
40 template<typename T, typename V> void ImageClassificationAdapter<T, V>::create(int type)
41 {
42         throw InvalidOperation("Interface not supported.");
43 }
44
45 template<typename T, typename V> void ImageClassificationAdapter<T, V>::configure()
46 {
47         _image_classification->parseMetaFile();
48         _image_classification->configure();
49 }
50
51 template<typename T, typename V> void ImageClassificationAdapter<T, V>::prepare()
52 {
53         _image_classification->prepare();
54 }
55
56 template<typename T, typename V> void ImageClassificationAdapter<T, V>::setInput(T &t)
57 {
58         _source = t;
59
60         if (!_source.model_file.empty() && !_source.meta_file.empty() && !_source.label_file.empty())
61                 _image_classification->setUserModel(_source.model_file, _source.meta_file, _source.label_file);
62 }
63
64 template<typename T, typename V> void ImageClassificationAdapter<T, V>::perform()
65 {
66         _image_classification->preprocess(_source.inference_src);
67         _image_classification->inference(_source.inference_src);
68 }
69
70 template<typename T, typename V> V &ImageClassificationAdapter<T, V>::getOutput()
71 {
72         return _image_classification->result();
73 }
74
75 template class ImageClassificationAdapter<ImageClassificationInput, ImageClassificationResult>;
76 }
77 }