From: Inki Dae Date: Tue, 23 Apr 2024 08:01:41 +0000 (+0900) Subject: inference: drop InferenceTaskInterface X-Git-Tag: accepted/tizen/unified/20240903.110722~60 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=63ad9d80323fd6e9a4615b56ded8f527fc94689f;p=platform%2Fcore%2Fapi%2Fsingleo.git inference: drop InferenceTaskInterface Drop IInferenceTaskInterface and its concreate classes which aren't needed anymore. We can create targeted service through dedicated factory as a IInferenceServiceInterface type. Change-Id: I04e32648ff9e17cf85bc5d8d3032357e9f46379c Signed-off-by: Inki Dae --- diff --git a/inference/CMakeLists.txt b/inference/CMakeLists.txt index 6313a17..d8a19f6 100644 --- a/inference/CMakeLists.txt +++ b/inference/CMakeLists.txt @@ -2,14 +2,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.13) SET(INFERENCE_DIRECTORY ${ROOT_DIRECTORY}/inference) -IF (${USE_EXTERNAL_INFERENCE_SERVICE}) - SET(SINGLEO_SERVICE_SOURCE_FILES ${SINGLEO_SERVICE_SOURCE_FILES} ${INFERENCE_DIRECTORY}/src/InferenceServiceExternal.cpp) -ELSE() - SET(SINGLEO_SERVICE_SOURCE_FILES ${SINGLEO_SERVICE_SOURCE_FILES} - ${INFERENCE_DIRECTORY}/src/InferenceServiceDefault.cpp - ${INFERENCE_DIRECTORY}/src/MvInferenceServiceFactory.cpp) -ENDIF() - INCLUDE(${INFERENCE_DIRECTORY}/backends/mediavision/CMakeLists.txt) LIST(APPEND INFERENCE_HEADER_LIST ${INFERENCE_HEADER_LIST} ${INFERENCE_DIRECTORY}/include) diff --git a/inference/backends/mediavision/CMakeLists.txt b/inference/backends/mediavision/CMakeLists.txt index a32329e..6cbc300 100644 --- a/inference/backends/mediavision/CMakeLists.txt +++ b/inference/backends/mediavision/CMakeLists.txt @@ -9,6 +9,7 @@ SET(SINGLEO_SERVICE_SOURCE_FILES ${SINGLEO_SERVICE_SOURCE_FILES} ${INFERENCE_MEDIAVISION_BACKEND_DIRECTORY}/src/MvFaceDetection.cpp ${INFERENCE_MEDIAVISION_BACKEND_DIRECTORY}/src/MvObjectDetection.cpp + ${INFERENCE_MEDIAVISION_BACKEND_DIRECTORY}/src/MvInferenceServiceFactory.cpp ) LIST(APPEND INFERENCE_LIBRARY_LIST ${INFERENCE_LIBRARY_LIST} mv_common mv_inference mv_object_detection) diff --git a/inference/backends/mediavision/include/MvFaceDetection.h b/inference/backends/mediavision/include/MvFaceDetection.h index fe463f7..2379b29 100644 --- a/inference/backends/mediavision/include/MvFaceDetection.h +++ b/inference/backends/mediavision/include/MvFaceDetection.h @@ -17,7 +17,7 @@ #ifndef __FACE_DETECTION_H__ #define __FACE_DETECTION_H__ -#include "IInferenceTaskInterface.h" +#include "IInferenceServiceInterface.h" #include "mv_face_detection_internal.h" #include "SingleoCommonTypes.h" @@ -27,7 +27,7 @@ namespace inference { namespace backends { -class MvFaceDetection : public IInferenceTaskInterface +class MvFaceDetection : public IInferenceServiceInterface { private: mv_face_detection_h _handle {}; diff --git a/inference/backends/mediavision/include/MvInferenceServiceFactory.h b/inference/backends/mediavision/include/MvInferenceServiceFactory.h new file mode 100644 index 0000000..351203e --- /dev/null +++ b/inference/backends/mediavision/include/MvInferenceServiceFactory.h @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MV_INFERENCE_SERVICE_FACTORY_H__ +#define __MV_INFERENCE_SERVICE_FACTORY_H__ + +#include "IInferenceServiceFactory.h" + +namespace singleo +{ +namespace inference +{ +class MvInferenceServiceFactory : public IInferenceServiceFactory +{ +private: + static bool _registered; + +public: + MvInferenceServiceFactory() = default; + virtual ~MvInferenceServiceFactory() = default; + + std::unique_ptr createImageClassification() override; + std::unique_ptr createObjectDetection() override; + std::unique_ptr createFaceDetection() override; + std::unique_ptr createFaceLandmarkDetection() override; +}; + +} +} + +#endif diff --git a/inference/backends/mediavision/include/MvObjectDetection.h b/inference/backends/mediavision/include/MvObjectDetection.h index dab3a35..9c8a97f 100644 --- a/inference/backends/mediavision/include/MvObjectDetection.h +++ b/inference/backends/mediavision/include/MvObjectDetection.h @@ -17,7 +17,7 @@ #ifndef __OBJECT_DETECTION_H__ #define __OBJECT_DETECTION_H__ -#include "IInferenceTaskInterface.h" +#include "IInferenceServiceInterface.h" #include "mv_object_detection_internal.h" #include "SingleoCommonTypes.h" @@ -27,7 +27,7 @@ namespace inference { namespace backends { -class MvObjectDetection : public IInferenceTaskInterface +class MvObjectDetection : public IInferenceServiceInterface { private: mv_object_detection_h _handle {}; diff --git a/inference/backends/mediavision/src/MvInferenceServiceFactory.cpp b/inference/backends/mediavision/src/MvInferenceServiceFactory.cpp new file mode 100644 index 0000000..5ff3b7b --- /dev/null +++ b/inference/backends/mediavision/src/MvInferenceServiceFactory.cpp @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "InferenceServiceFactory.h" +#include "MvInferenceServiceFactory.h" +#include "MvFaceDetection.h" +#include "MvObjectDetection.h" +#include "SingleoLog.h" +#include "SingleoException.h" + +using namespace std; +using namespace singleo::exception; +using namespace singleo::inference::backends; + +namespace singleo +{ +namespace inference +{ +bool MvInferenceServiceFactory::_registered = + registerInferenceServiceFactory("MvInferenceServiceFactory"); + +std::unique_ptr MvInferenceServiceFactory::createImageClassification() +{ + throw InvalidOperation("Interface not supported yet."); +} + +std::unique_ptr MvInferenceServiceFactory::createObjectDetection() +{ + return make_unique(); +} + +std::unique_ptr MvInferenceServiceFactory::createFaceDetection() +{ + return make_unique(); +} + +std::unique_ptr MvInferenceServiceFactory::createFaceLandmarkDetection() +{ + throw InvalidOperation("Interface not supported yet."); +} + +} +} diff --git a/inference/include/IInferenceTaskInterface.h b/inference/include/IInferenceTaskInterface.h deleted file mode 100644 index 2b0aa78..0000000 --- a/inference/include/IInferenceTaskInterface.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __IINFERENCE_TASK_INTERFACE_H__ -#define __IINFERENCE_TASK_INTERFACE_H__ - -#include "SingleoCommonTypes.h" - -namespace singleo -{ -namespace inference -{ -class IInferenceTaskInterface -{ -public: - virtual ~IInferenceTaskInterface() {}; - - virtual void configure() = 0; - virtual void prepare() = 0; - virtual void invoke(BaseDataType &input, bool async = false) = 0; - virtual BaseResultType &result() = 0; -}; - -} // inference -} // singleo - -#endif \ No newline at end of file diff --git a/inference/include/InferenceServiceDefault.h b/inference/include/InferenceServiceDefault.h deleted file mode 100644 index c33f326..0000000 --- a/inference/include/InferenceServiceDefault.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __INFERENCE_SERVICE_DEFAULT_H__ -#define __INFERENCE_SERVICE_DEFAULT_H__ - -#include -#include "IInferenceServiceInterface.h" -#include "IInferenceTaskInterface.h" -#include "SingleoInferenceTypes.h" -#include "SingleoCommonTypes.h" - -namespace singleo -{ -namespace inference -{ -class InferenceServiceDefault : public IInferenceServiceInterface -{ -private: - std::unique_ptr _task; - -public: - explicit InferenceServiceDefault(TaskType task_type); - virtual ~InferenceServiceDefault() = default; - - void configure() override; - void prepare() override; - void invoke(BaseDataType &input, bool async = false) override; - BaseResultType &result() override; -}; - -} // inference -} // singleo - -#endif diff --git a/inference/include/InferenceServiceExternal.h b/inference/include/InferenceServiceExternal.h deleted file mode 100644 index 955ae1d..0000000 --- a/inference/include/InferenceServiceExternal.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __INFERENCE_SERVICE_EXTERNAL_H__ -#define __INFERENCE_SERVICE_EXTERNAL_H__ - -#include "IInferenceServiceInterface.h" -#include "IInferenceTaskInterface.h" -#include "SingleoInferenceTypes.h" -#include "SingleoCommonTypes.h" - -namespace singleo -{ -namespace inference -{ -class InferenceServiceExternal : public IInferenceServiceInterface -{ -public: - explicit InferenceServiceExternal(TaskType task_type); - virtual ~InferenceServiceExternal(); - - void configure(TaskType task_type) override; - void prepare() override; - void invoke(BaseDataType &input, bool async = false) override; - BaseResultType &result() override; -}; - -} // inference -} // singleo - -#endif diff --git a/inference/include/MvInferenceServiceFactory.h b/inference/include/MvInferenceServiceFactory.h deleted file mode 100644 index 351203e..0000000 --- a/inference/include/MvInferenceServiceFactory.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __MV_INFERENCE_SERVICE_FACTORY_H__ -#define __MV_INFERENCE_SERVICE_FACTORY_H__ - -#include "IInferenceServiceFactory.h" - -namespace singleo -{ -namespace inference -{ -class MvInferenceServiceFactory : public IInferenceServiceFactory -{ -private: - static bool _registered; - -public: - MvInferenceServiceFactory() = default; - virtual ~MvInferenceServiceFactory() = default; - - std::unique_ptr createImageClassification() override; - std::unique_ptr createObjectDetection() override; - std::unique_ptr createFaceDetection() override; - std::unique_ptr createFaceLandmarkDetection() override; -}; - -} -} - -#endif diff --git a/inference/src/InferenceServiceDefault.cpp b/inference/src/InferenceServiceDefault.cpp deleted file mode 100644 index 4de47f4..0000000 --- a/inference/src/InferenceServiceDefault.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "InferenceServiceDefault.h" -#include "MvObjectDetection.h" -#include "MvFaceDetection.h" - -using namespace std; -using namespace singleo::inference::backends; - -namespace singleo -{ -namespace inference -{ -InferenceServiceDefault::InferenceServiceDefault(TaskType task_type) -{ - // TODO. add other task types later. - if (task_type != TaskType::OBJECT_DETECTION && task_type != TaskType::FACE_DETECTION) - invalid_argument("Task type not supported."); - - switch (task_type) { - case TaskType::OBJECT_DETECTION: - _task = make_unique(); - break; - case TaskType::FACE_DETECTION: - _task = make_unique(); - break; - } -} - -void InferenceServiceDefault::configure() -{ - _task->configure(); -} - -void InferenceServiceDefault::prepare() -{ - _task->prepare(); -} - -void InferenceServiceDefault::invoke(BaseDataType &input, bool async) -{ - _task->invoke(input, async); -} - -BaseResultType &InferenceServiceDefault::result() -{ - return _task->result(); -} - -} -} diff --git a/inference/src/InferenceServiceExternal.cpp b/inference/src/InferenceServiceExternal.cpp deleted file mode 100644 index 76fa63a..0000000 --- a/inference/src/InferenceServiceExternal.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "InferenceServiceExternal.h" - -using namespace std; - -namespace singleo -{ -namespace inference -{ -InferenceServiceExternal::InferenceServiceExternal(TaskType task_type) -{} -InferenceServiceExternal::~InferenceServiceExternal() -{} - -void InferenceServiceExternal::configure(TaskType task_type) -{ - throw runtime_error("Not support yet."); -} - -void InferenceServiceExternal::prepare() -{ - throw runtime_error("Not support yet."); -} - -void InferenceServiceExternal::invoke(BaseDataType &input, bool async) -{ - throw runtime_error("Not support yet."); -} - -BaseResultType &InferenceServiceExternal::result() -{ - throw runtime_error("Not support yet."); -} - -} -} diff --git a/inference/src/MvInferenceServiceFactory.cpp b/inference/src/MvInferenceServiceFactory.cpp deleted file mode 100644 index 87b3a09..0000000 --- a/inference/src/MvInferenceServiceFactory.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "InferenceServiceFactory.h" -#include "InferenceServiceDefault.h" -#include "MvInferenceServiceFactory.h" -#include "SingleoLog.h" -#include "SingleoException.h" - -using namespace std; -using namespace singleo::exception; - -namespace singleo -{ -namespace inference -{ -bool MvInferenceServiceFactory::_registered = - registerInferenceServiceFactory("MvInferenceServiceFactory"); - -std::unique_ptr MvInferenceServiceFactory::createImageClassification() -{ - throw InvalidOperation("Interface not supported yet."); -} - -std::unique_ptr MvInferenceServiceFactory::createObjectDetection() -{ - return make_unique(TaskType::OBJECT_DETECTION); -} - -std::unique_ptr MvInferenceServiceFactory::createFaceDetection() -{ - return make_unique(TaskType::FACE_DETECTION); -} - -std::unique_ptr MvInferenceServiceFactory::createFaceLandmarkDetection() -{ - throw InvalidOperation("Interface not supported yet."); -} - -} -}