#include "machine_learning_exception.h"
#include "pose_landmark_adapter.h"
+#include "mv_landmark_detection_config.h"
using namespace std;
using namespace MediaVision::Common;
{
template<typename T, typename V> PoseLandmarkAdapter<T, V>::PoseLandmarkAdapter() : _source()
{
- // In default, Mobilenet v1 ssd model will be used.
- // If other model is set by user then strategy pattern will be used
- // to create its corresponding concrete class by calling create().
- _landmark_detection = make_unique<PldCpm>(LandmarkDetectionTaskType::PLD_CPM);
+ auto config = make_unique<EngineConfig>(MV_CONFIG_PATH + _config_file_name);
+
+ string defaultModelName;
+
+ int ret = config->getStringAttribute(MV_LANDMARK_DETECTION_DEFAULT_MODEL_NAME, &defaultModelName);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get default model name.");
+
+ create(convertToTaskType(defaultModelName));
}
template<typename T, typename V> PoseLandmarkAdapter<T, V>::~PoseLandmarkAdapter()
template<typename T, typename V> void PoseLandmarkAdapter<T, V>::create(LandmarkDetectionTaskType task_type)
{
- // If default task type is same as a given one then skip.
- if (_landmark_detection->getTaskType() == task_type)
- return;
-
- _landmark_detection.reset();
+ // If a concrete class object created already exists, reset the object
+ // so that other concrete class object can be created again according to a given task_type.
+ if (_landmark_detection) {
+ // If default task type is same as a given one then skip.
+ if (_landmark_detection->getTaskType() == task_type)
+ return;
+ }
if (task_type == LandmarkDetectionTaskType::PLD_CPM)
_landmark_detection = make_unique<PldCpm>(task_type);
- // TODO.
}
template<typename T, typename V>
-void PoseLandmarkAdapter<T, V>::setModelInfo(const char *model_file, const char *meta_file, const char *label_file,
- const char *model_name)
+LandmarkDetectionTaskType PoseLandmarkAdapter<T, V>::convertToTaskType(string model_name)
{
- string model_name_str(model_name);
+ if (model_name.empty())
+ throw InvalidParameter("model name is empty.");
+
+ transform(model_name.begin(), model_name.end(), model_name.begin(), ::toupper);
- if (!model_name_str.empty()) {
- transform(model_name_str.begin(), model_name_str.end(), model_name_str.begin(), ::toupper);
+ LandmarkDetectionTaskType task_type = LandmarkDetectionTaskType::LANDMARK_DETECTION_TASK_NONE;
- LandmarkDetectionTaskType task_type = LandmarkDetectionTaskType::LANDMARK_DETECTION_TASK_NONE;
+ if (model_name == "PLD_CPM")
+ return LandmarkDetectionTaskType::PLD_CPM;
- if (model_name_str == string("PLD_CPM"))
- task_type = LandmarkDetectionTaskType::PLD_CPM;
- // TODO.
- else
- throw InvalidParameter("Invalid landmark detection model name.");
+ throw InvalidParameter("Invalid pose landmark model name.");
+}
- create(task_type);
+template<typename T, typename V>
+void PoseLandmarkAdapter<T, V>::setModelInfo(const char *model_file, const char *meta_file, const char *label_file,
+ const char *model_name)
+{
+ try {
+ create(convertToTaskType(model_name));
+ } catch (const BaseException &e) {
+ LOGW("A given model name is invalid so default task type will be used.");
}
- _model_file = string(model_file);
- _meta_file = string(meta_file);
- _label_file = string(label_file);
+ if (model_file)
+ _model_file = model_file;
+ if (meta_file)
+ _meta_file = meta_file;
+ if (label_file)
+ _label_file = label_file;
if (_model_file.empty() && _meta_file.empty()) {
LOGW("Given model info is invalid so default model info will be used instead.");
template<typename T, typename V> void PoseLandmarkAdapter<T, V>::configure()
{
- _landmark_detection->configure("pose_landmark.json");
+ _landmark_detection->configure(_config_file_name);
}
template<typename T, typename V> void PoseLandmarkAdapter<T, V>::getNumberOfEngines(unsigned int *number_of_engines)