FORMAT_BIN: 'FORMAT_BIN',
FORMAT_INI: 'FORMAT_INI',
FORMAT_INI_WITH_BIN: 'FORMAT_INI_WITH_BIN'
-}
+};
+
+var DatasetMode = {
+ MODE_TRAIN: 'MODE_TRAIN',
+ MODE_VALID: 'MODE_VALID',
+ MODE_TEST: 'MODE_TEST'
+};
var Layer = function(id, type) {
Object.defineProperties(this, {
{
name: 'value',
type: types_.STRING
+ },
+ {
+ name: 'mode',
+ type: types_.ENUM,
+ values: Object.values(DatasetMode)
}
]);
- if (!args.has.name || !args.has.value) {
+ if (!args.has.name || !args.has.value || !args.has.mode) {
throw new WebAPIException(
WebAPIException.TYPE_MISMATCH_ERR,
- 'Invalid parameter: ' + (args.has.name ? 'value' : 'name') + ' is undefined'
+ 'Invalid parameter: name, value and mode have to be defined'
);
}
var callArgs = {
id: this._id,
name: args.name,
- value: args.value
+ value: args.value,
+ mode: args.mode
};
var result = native_.callSync('MLTrainerDatasetSetProperty', callArgs);
const std::string kSummary = "summary";
const std::string kSavePath = "savePath";
const std::string kSaveFormat = "saveFormat";
+const std::string kMode = "mode";
} // namespace
using namespace common;
CHECK_ARGS(args, kId, double, out);
CHECK_ARGS(args, kName, std::string, out);
CHECK_ARGS(args, kValue, std::string, out);
+ CHECK_ARGS(args, kMode, std::string, out);
auto id = static_cast<int>(args.get(kId).get<double>());
auto name = args.get(kName).get<std::string>();
auto value = args.get(kValue).get<std::string>();
- PlatformResult result = trainer_manager_.DatasetSetProperty(id, name, value);
+ ml_train_dataset_mode_e datasetMode = ML_TRAIN_DATASET_MODE_TRAIN;
+ PlatformResult result = types::DatasetModeEnum.getValue(
+ args.get(kMode).get<std::string>(), &datasetMode);
+ if (!result) {
+ LogAndReportError(result, &out);
+ return;
+ }
+
+ result = trainer_manager_.DatasetSetProperty(id, name, value, datasetMode);
if (!result) {
ReportError(result, &out);
return;
// MK-TODO Add creating Dataset with generator
-PlatformResult TrainerManager::DatasetSetProperty(int id,
- const std::string& name,
- const std::string& value) {
+PlatformResult TrainerManager::DatasetSetProperty(
+ int id,
+ const std::string& name,
+ const std::string& value,
+ ml_train_dataset_mode_e mode) {
ScopeLogger("id: %d, name: %s, value: %s", id, name.c_str(), value.c_str());
if (datasets_.find(id) == datasets_.end()) {
auto dataset = datasets_[id];
std::string opt = name + "=" + value;
- // ml_train_dataset_set_property() is marked as deprecated
- // temporary set same property for all modes (all data files) if possible
- int ret_val = ml_train_dataset_set_property_for_mode(
- dataset->getNative(), ML_TRAIN_DATASET_MODE_TRAIN, opt.c_str(), NULL);
+ int ret_val = ml_train_dataset_set_property_for_mode(dataset->getNative(),
+ mode, opt.c_str(), NULL);
if (ret_val != ML_ERROR_NONE) {
- LoggerE("Could not set dataset property for train mode: %d (%s)", ret_val,
- ml_strerror(ret_val));
- return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val));
- }
-
- ret_val = ml_train_dataset_set_property_for_mode(
- dataset->getNative(), ML_TRAIN_DATASET_MODE_VALID, opt.c_str(), NULL);
- if (ret_val != ML_ERROR_NONE) {
- LoggerE("Could not set dataset property for validation mode: %d (%s)",
+ LoggerE("Could not set dataset property for mode %d: %d (%s)", mode,
ret_val, ml_strerror(ret_val));
- // MK-TODO report error for each file when extracted to separate functions
- // return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val));
- }
-
- ret_val = ml_train_dataset_set_property_for_mode(
- dataset->getNative(), ML_TRAIN_DATASET_MODE_TEST, opt.c_str(), NULL);
- if (ret_val != ML_ERROR_NONE) {
- LoggerE("Could not set dataset property for test mode: %d (%s)", ret_val,
- ml_strerror(ret_val));
- // MK-TODO report error for each file when extracted to separate functions
- // return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val));
+ return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val));
}
return PlatformResult();
PlatformResult CreateFileDataset(int& id, const std::string train_file,
const std::string valid_file, const std::string test_file);
- PlatformResult DatasetSetProperty(int id, const std::string& name,
- const std::string& value);
+ PlatformResult DatasetSetProperty(int id,
+ const std::string& name,
+ const std::string& value,
+ ml_train_dataset_mode_e mode);
PlatformResult DatasetDispose(int id);
private:
{"FORMAT_INI", ML_TRAIN_MODEL_FORMAT_INI},
{"FORMAT_INI_WITH_BIN", ML_TRAIN_MODEL_FORMAT_INI_WITH_BIN}};
+const PlatformEnum<ml_train_dataset_mode_e> DatasetModeEnum{
+ {"MODE_TRAIN", ML_TRAIN_DATASET_MODE_TRAIN},
+ {"MODE_VALID", ML_TRAIN_DATASET_MODE_VALID},
+ {"MODE_TEST", ML_TRAIN_DATASET_MODE_TEST}};
+
} // namespace types
namespace util {
extern const PlatformEnum<ml_train_layer_type_e> LayerTypeEnum;
extern const PlatformEnum<ml_train_summary_type_e> SummaryTypeEnum;
extern const PlatformEnum<ml_train_model_format_e> ModelSaveFormatEnum;
+extern const PlatformEnum<ml_train_dataset_mode_e> DatasetModeEnum;
} // namespace types