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)
+ 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)
+++ /dev/null
-/**
- * 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:
- std::unique_ptr<IInferenceServiceInterface>createInferenceService(TaskType taskType);
-
-public:
- MvInferenceServiceFactory() = default;
- virtual ~MvInferenceServiceFactory() = default;
-
- std::unique_ptr<IInferenceServiceInterface> createImageClassification() override;
- std::unique_ptr<IInferenceServiceInterface> createObjectDetection() override;
- std::unique_ptr<IInferenceServiceInterface> createFaceDetection() override;
- std::unique_ptr<IInferenceServiceInterface> createFaceLandmarkDetection() override;
-};
-
-}
-}
-
-#endif
+++ /dev/null
-/**
- * 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 "MvInferenceServiceFactory.h"
-#include "InferenceServiceDefault.h"
-#include "SingleoLog.h"
-#include "SingleoException.h"
-
-using namespace std;
-using namespace singleo::exception;
-
-namespace singleo
-{
-namespace inference
-{
-namespace backends
-{
-
-std::unique_ptr<IInferenceServiceInterface>MvInferenceServiceFactory::createInferenceService(TaskType taskType)
-{
- auto service = make_unique<InferenceServiceDefault>();
-
- service->configure(taskType);
-
- return service;
-}
-
-std::unique_ptr<IInferenceServiceInterface> MvInferenceServiceFactory::createImageClassification()
-{
- throw InvalidOperation("Interface not supported yet.");
-}
-
-std::unique_ptr<IInferenceServiceInterface> MvInferenceServiceFactory::createObjectDetection()
-{
- return createInferenceService(TaskType::OBJECT_DETECTION);
-}
-
-std::unique_ptr<IInferenceServiceInterface> MvInferenceServiceFactory::createFaceDetection()
-{
- return createInferenceService(TaskType::FACE_DETECTION);
-}
-
-std::unique_ptr<IInferenceServiceInterface> MvInferenceServiceFactory::createFaceLandmarkDetection()
-{
- throw InvalidOperation("Interface not supported yet.");
-}
-
-}
-}
-}
virtual std::unique_ptr<IInferenceServiceInterface> createObjectDetection() = 0;
virtual std::unique_ptr<IInferenceServiceInterface> createFaceDetection() = 0;
virtual std::unique_ptr<IInferenceServiceInterface> createFaceLandmarkDetection() = 0;
-}
+};
}
}
public:
virtual ~IInferenceServiceInterface() {};
- virtual void configure(TaskType task_type) = 0;
+ virtual void configure() = 0;
virtual void prepare() = 0;
virtual void invoke(BaseDataType &input, bool async = false) = 0;
virtual BaseResultType &result() = 0;
{
private:
std::unique_ptr<IInferenceTaskInterface> _task;
- static bool _registered;
public:
- InferenceServiceDefault() = default;
+ explicit InferenceServiceDefault(TaskType task_type);
virtual ~InferenceServiceDefault() = default;
- void configure(TaskType task_type) override;
+ void configure() override;
void prepare() override;
void invoke(BaseDataType &input, bool async = false) override;
BaseResultType &result() override;
#include <string>
#include <memory>
#include <stdexcept>
-#include "IInferenceServiceInterface.h"
+#include "IInferenceServiceFactory.h"
#include "SingleoException.h"
#include "SingleoLog.h"
class InferenceServiceFactory
{
public:
- using createFunc = std::unique_ptr<IInferenceServiceInterface> (*)();
+ using createFunc = std::unique_ptr<IInferenceServiceFactory> (*)();
static InferenceServiceFactory &instance()
{
return factory;
}
- std::unique_ptr<IInferenceServiceInterface> create(const std::string &name)
+ std::unique_ptr<IInferenceServiceFactory> create(const std::string &name)
{
auto it = _inference_service_table.find(name);
if (it != _inference_service_table.end())
return it->second();
- throw singleo::exception::InvalidParameter("Invalid inference service.");
+ throw singleo::exception::InvalidParameter("Invalid inference service factory.");
}
void registerBackend(const std::string &name, const createFunc &func)
std::unordered_map<std::string, createFunc> _inference_service_table;
};
-template<typename ServiceType> bool registerInferenceService(const std::string &name)
+template<typename FactoryType> bool registerInferenceServiceFactory(const std::string &name)
{
InferenceServiceFactory::instance().registerBackend(name, []() {
- return std::unique_ptr<IInferenceServiceInterface>(new ServiceType());
+ return std::unique_ptr<IInferenceServiceFactory>(new FactoryType());
});
return true;
--- /dev/null
+/**
+ * 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<IInferenceServiceInterface> createImageClassification() override;
+ std::unique_ptr<IInferenceServiceInterface> createObjectDetection() override;
+ std::unique_ptr<IInferenceServiceInterface> createFaceDetection() override;
+ std::unique_ptr<IInferenceServiceInterface> createFaceLandmarkDetection() override;
+};
+
+}
+}
+
+#endif
* limitations under the License.
*/
-#include "InferenceServiceFactory.h"
#include "InferenceServiceDefault.h"
#include "MvObjectDetection.h"
#include "MvFaceDetection.h"
{
namespace inference
{
-bool InferenceServiceDefault::_registered =
- registerInferenceService<InferenceServiceDefault>("InferenceServiceDefault");
-
-void InferenceServiceDefault::configure(TaskType task_type)
+InferenceServiceDefault::InferenceServiceDefault(TaskType task_type)
{
// TODO. add other task types later.
if (task_type != TaskType::OBJECT_DETECTION && task_type != TaskType::FACE_DETECTION)
_task = make_unique<MvFaceDetection>();
break;
}
+}
+void InferenceServiceDefault::configure()
+{
_task->configure();
}
--- /dev/null
+/**
+ * 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>("MvInferenceServiceFactory");
+
+std::unique_ptr<IInferenceServiceInterface> MvInferenceServiceFactory::createImageClassification()
+{
+ throw InvalidOperation("Interface not supported yet.");
+}
+
+std::unique_ptr<IInferenceServiceInterface> MvInferenceServiceFactory::createObjectDetection()
+{
+ return make_unique<InferenceServiceDefault>(TaskType::OBJECT_DETECTION);
+}
+
+std::unique_ptr<IInferenceServiceInterface> MvInferenceServiceFactory::createFaceDetection()
+{
+ return make_unique<InferenceServiceDefault>(TaskType::FACE_DETECTION);
+}
+
+std::unique_ptr<IInferenceServiceInterface> MvInferenceServiceFactory::createFaceLandmarkDetection()
+{
+ throw InvalidOperation("Interface not supported yet.");
+}
+
+}
+}
#include <algorithm>
#include "SingleoException.h"
#include "AutoZoom.h"
+#include "IInferenceServiceFactory.h"
#include "InferenceServiceFactory.h"
#include "SingleoLog.h"
#include "ImagePreprocessor.h"
AutoZoom::AutoZoom(InputConfigBase &config)
{
- // In default, we will use InferenceServiceDefault class to use Mediavision framework
+ // In default, we will use Inference service factory for Mediavision to use Mediavision framework
// for inference service. TODO. introduce meta config file approach later.
- _inference_service = InferenceServiceFactory::instance().create("InferenceServiceDefault");
+ auto factory = InferenceServiceFactory::instance().create("MvInferenceServiceFactory");
+
+ _inference_service = factory->createFaceDetection();
// Create InputCamera service if input service type is CAMERA.
if (config._input_feed_type == InputFeedType::CAMERA) {
SINGLEO_LOGD("Camera input service has been initialized.");
}
- _inference_service->configure(_task_type);
+ _inference_service->configure();
_inference_service->prepare();
_postprocessor = make_unique<Postprocessor>();
}