// 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(
/* 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 }
});
};
REGISTER_METHOD(MLSingleManagerOpenModel);
// MachineLearningSingle::openModelAsync()
// OpenModelSuccessCallback
- REGISTER_METHOD(MLSingleShotGetInputInfo);
- // SingleShot output
+ REGISTER_METHOD(MLSingleShotGetTensorsInfo);
// SingleShot::invoke()
// SingleShot::getValue()
// SingleShot::setValue()
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;
// 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;
ReportSuccess(out);
}
-// SingleShot output
-
// SingleShot::invoke()
// SingleShot::getValue()
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()
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);
}
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;
}
*res_id = tensor_info->Id();
return PlatformResult{};
}
-// SingleShot output
+
// SingleShot::invoke()
// SingleShot::getValue()
// SingleShot::setValue()
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()
}
}
-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()
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()