From bf07405c394a22aa3b0af1a12b0a463fb3e5e58a Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Fri, 22 Jan 2021 08:27:53 +0100 Subject: [PATCH] [ML][Single] Implemented SingleShot.output member - get [ACR] https://code.sec.samsung.net/jira/browse/TWDAPI-273 [Verification] Code compiles without errors. Checked in Chrome console: // open model var model = tizen.ml.single.openModel("documents/mobilenet_v1_1.0_224_quant.tflite") // below works well model.input.getDimensions(0) model.output.getDimensions(0) Change-Id: I43120610873a455eb813bb02db9c3eeff7a02e91 --- src/ml/js/ml_single.js | 27 ++++++++++++++++++++++++--- src/ml/ml_instance.cc | 20 ++++++++++++-------- src/ml/ml_instance.h | 3 +-- src/ml/ml_single_manager.cc | 6 +++--- src/ml/ml_single_manager.h | 3 +-- src/ml/ml_singleshot.cc | 17 +++++++++++------ src/ml/ml_singleshot.h | 4 +--- 7 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/ml/js/ml_single.js b/src/ml/js/ml_single.js index e79731dd..40a00de3 100755 --- a/src/ml/js/ml_single.js +++ b/src/ml/js/ml_single.js @@ -97,13 +97,14 @@ MachineLearningSingle.prototype.openModel = function() { // OpenModelSuccessCallback // SingleShot interface (input & output) -var ValidInputExceptions = ['TypeMismatch', 'AbortError']; +var ValidInputExceptions = ['TypeMismatchError', 'AbortError']; var SingleShot = function(id) { Object.defineProperties(this, { input: { get: function() { - var result = native_.callSync('MLSingleShotGetInputInfo', { - id: this._id + var result = native_.callSync('MLSingleShotGetTensorsInfo', { + id: this._id, + getInputMode: true // true means gathering input information }); if (native_.isFailure(result)) { throw native_.getErrorObjectAndValidate( @@ -119,6 +120,26 @@ var SingleShot = function(id) { /* TODO*/ } }, + output: { + get: function() { + var result = native_.callSync('MLSingleShotGetTensorsInfo', { + id: this._id, + getInputMode: false // false means gathering output information + }); + if (native_.isFailure(result)) { + throw native_.getErrorObjectAndValidate( + result, + ValidInputExceptions, + AbortError + ); + } + + return new TensorsInfo(result.id); + }, + set: function(v) { + /* readonly */ + } + }, _id: { value: id, writable: false, enumerable: false } }); }; diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 9fe01114..b56fcbc9 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -94,8 +94,7 @@ MlInstance::MlInstance() : single_manager_{&tensors_info_manager_}, pipeline_man REGISTER_METHOD(MLSingleManagerOpenModel); // MachineLearningSingle::openModelAsync() // OpenModelSuccessCallback - REGISTER_METHOD(MLSingleShotGetInputInfo); - // SingleShot output + REGISTER_METHOD(MLSingleShotGetTensorsInfo); // SingleShot::invoke() // SingleShot::getValue() // SingleShot::setValue() @@ -608,7 +607,7 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: int res_id = -1; result = single_manager_.OpenModel(model_path, in_tensors_info, out_tensors_info, nnfw_e, hw_e, - is_dynamic_mode, &res_id); + is_dynamic_mode, &res_id); if (!result) { ReportError(result, &out); return; @@ -622,15 +621,22 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: // OpenModelSuccessCallback -// SingleShot input -void MlInstance::MLSingleShotGetInputInfo(const picojson::value& args, picojson::object& out) { +// SingleShot input/output +// TODO move to the up section with field names +namespace { +const std::string kGetInputMode = "getInputMode"; +} // namespace +void MlInstance::MLSingleShotGetTensorsInfo(const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); + CHECK_ARGS(args, kGetInputMode, bool, out); auto id = static_cast(args.get(kId).get()); + // true means gathering input data; false means gathering output data + auto get_input_mode = static_cast(args.get(kGetInputMode).get()); int res_id = -1; - auto ret = single_manager_.GetNativeInputInfo(id, &res_id); + auto ret = single_manager_.GetNativeTensorsInfo(id, get_input_mode, &res_id); if (!ret) { ReportError(ret, &out); return; @@ -640,8 +646,6 @@ void MlInstance::MLSingleShotGetInputInfo(const picojson::value& args, picojson: ReportSuccess(out); } -// SingleShot output - // SingleShot::invoke() // SingleShot::getValue() diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index 9619647b..5488f760 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -59,8 +59,7 @@ class MlInstance : public common::ParsedInstance { void MLSingleManagerOpenModel(const picojson::value& args, picojson::object& out); // MachineLearningSingle::openModelAsync() // OpenModelSuccessCallback - void MLSingleShotGetInputInfo(const picojson::value& args, picojson::object& out); - // SingleShot output + void MLSingleShotGetTensorsInfo(const picojson::value& args, picojson::object& out); // SingleShot::invoke() // SingleShot::getValue() // SingleShot::setValue() diff --git a/src/ml/ml_single_manager.cc b/src/ml/ml_single_manager.cc index 0bb6a0a4..4bc3d1a7 100644 --- a/src/ml/ml_single_manager.cc +++ b/src/ml/ml_single_manager.cc @@ -67,7 +67,7 @@ SingleShot* SingleManager::GetSingleShot(int id) { return nullptr; } -PlatformResult SingleManager::GetNativeInputInfo(int id, int* res_id) { +PlatformResult SingleManager::GetNativeTensorsInfo(int id, bool get_input_mode, int* res_id) { ScopeLogger(); SingleShot* single = GetSingleShot(id); @@ -77,7 +77,7 @@ PlatformResult SingleManager::GetNativeInputInfo(int id, int* res_id) { } ml_tensors_info_h in_info = nullptr; - PlatformResult ret = single->GetInputInfo(&in_info); + PlatformResult ret = single->GetTensorsInfo(get_input_mode, &in_info); if (!ret) { return ret; } @@ -86,7 +86,7 @@ PlatformResult SingleManager::GetNativeInputInfo(int id, int* res_id) { *res_id = tensor_info->Id(); return PlatformResult{}; } -// SingleShot output + // SingleShot::invoke() // SingleShot::getValue() // SingleShot::setValue() diff --git a/src/ml/ml_single_manager.h b/src/ml/ml_single_manager.h index 8dc38046..bf983739 100644 --- a/src/ml/ml_single_manager.h +++ b/src/ml/ml_single_manager.h @@ -43,8 +43,7 @@ class SingleManager { bool isDynamicMode, int* res_id); // MachineLearningSingle::openModelAsync() // OpenModelSuccessCallback - PlatformResult GetNativeInputInfo(int id, int* res_id); - // SingleShot output + PlatformResult GetNativeTensorsInfo(int id, bool get_input_mode, int* res_id); // SingleShot::invoke() // SingleShot::getValue() // SingleShot::setValue() diff --git a/src/ml/ml_singleshot.cc b/src/ml/ml_singleshot.cc index 6fbe25c6..beff9f1e 100644 --- a/src/ml/ml_singleshot.cc +++ b/src/ml/ml_singleshot.cc @@ -43,21 +43,26 @@ SingleShot::~SingleShot() { } } -PlatformResult SingleShot::GetInputInfo(ml_tensors_info_h* result) { +PlatformResult SingleShot::GetTensorsInfo(bool get_input_mode, ml_tensors_info_h* result) { ScopeLogger(); ml_tensors_info_h info = nullptr; - int ret = ml_single_get_input_info(handle_, &info); + int ret = 0; + if (get_input_mode) { + ret = ml_single_get_input_info(handle_, &info); + } else { + ret = ml_single_get_output_info(handle_, &info); + } if (ML_ERROR_NONE != ret) { - LoggerE("ml_single_get_input_info failed: %d (%s)", ret, get_error_message(ret)); - return util::ToPlatformResult(ret, "Failed to get tensor dimension"); + LoggerE("%s failed: %d (%s)", + get_input_mode ? "ml_single_get_input_info" : "ml_single_get_output_info", ret, + get_error_message(ret)); + return util::ToPlatformResult(ret, "Failed to get tensors info"); } *result = info; return PlatformResult{}; } -// SingleShot output - // SingleShot::invoke() // SingleShot::getValue() diff --git a/src/ml/ml_singleshot.h b/src/ml/ml_singleshot.h index eb174f0c..a78d955d 100644 --- a/src/ml/ml_singleshot.h +++ b/src/ml/ml_singleshot.h @@ -41,9 +41,7 @@ class SingleShot { SingleShot& operator=(SingleShot&& o) = delete; ~SingleShot(); - PlatformResult GetInputInfo(ml_tensors_info_h* result); - - // SingleShot output + PlatformResult GetTensorsInfo(bool get_input_mode, ml_tensors_info_h* result); // SingleShot::invoke() -- 2.34.1