[ML] Train - added load() method implementation
[platform/core/api/webapi-plugins.git] / src / ml / js / ml_trainer.js
index 81e8d83..8354bec 100755 (executable)
@@ -516,6 +516,46 @@ Model.prototype.saveToFile = function () {
     }
 };
 
+Model.prototype.load = function () {
+    var args = validator_.validateArgs(arguments, [
+        {
+            name: 'path',
+            type: types_.STRING
+        },
+        {
+            name: 'format',
+            type: types_.ENUM,
+            values: Object.values(SaveFormat)
+        }
+    ]);
+
+    var callArgs = {
+        id: this._id,
+        savePath: args.path,
+        saveFormat: args.format
+    }
+
+    try {
+        callArgs.savePath = tizen.filesystem.toURI(args.path);
+    } catch (e) {
+        throw new WebAPIException(WebAPIException.InvalidValuesError, 'Invalid file path given');
+    }
+
+    if (!tizen.filesystem.pathExists(callArgs.savePath)) {
+        throw new WebAPIException(WebAPIException.NotFoundError, 'Path not found');
+    }
+
+    var result = native_.callSync('MLTrainerModelLoad', callArgs);
+
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObjectAndValidate(
+            result,
+            ValidModelSaveExceptions,
+            AbortError
+        );
+    }
+};
+
 Model.prototype.addLayer = function() {
     var args = validator_.validateArgs(arguments, [
         {