[ML][Single] Implemented SingleShot.output member - get 64/252064/4
authorPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Fri, 22 Jan 2021 07:27:53 +0000 (08:27 +0100)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Tue, 26 Jan 2021 05:53:00 +0000 (06:53 +0100)
[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
src/ml/ml_instance.cc
src/ml/ml_instance.h
src/ml/ml_single_manager.cc
src/ml/ml_single_manager.h
src/ml/ml_singleshot.cc
src/ml/ml_singleshot.h

index e79731d..40a00de 100755 (executable)
@@ -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 }
     });
 };
index 9fe0111..b56fcbc 100644 (file)
@@ -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<int>(args.get(kId).get<double>());
+  // true means gathering input data; false means gathering output data
+  auto get_input_mode = static_cast<int>(args.get(kGetInputMode).get<bool>());
 
   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()
index 9619647..5488f76 100644 (file)
@@ -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()
index 0bb6a0a..4bc3d1a 100644 (file)
@@ -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()
index 8dc3804..bf98373 100644 (file)
@@ -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()
index 6fbe25c..beff9f1 100644 (file)
@@ -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()
index eb174f0..a78d955 100644 (file)
@@ -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()