MODE_TEST: 'MODE_TEST'
};
+var ValidGetNameExceptions = [
+ 'InvalidValuesError',
+ 'AbortError'
+];
+
var Layer = function(id, type) {
Object.defineProperties(this, {
name: {
enumerable: true,
get: function() {
- // TODO
+ var result = native_.callSync('MLTrainerLayerGetName', { id: this._id });
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ ValidGetNameExceptions,
+ AbortError
+ );
+ }
+
+ return result.name
}
},
type: {
);
}
- return new Layer(result.id, args.type);
+ var nLay = new Layer(result.id, args.type);
+
+ nLay.setProperty("name", args.type.toString() + result.id.toString());
+
+ return nLay;
};
function ValidateAndReturnDatasetPaths(train, valid, test) {
REGISTER_METHOD(MLTrainerLayerSetProperty);
REGISTER_METHOD(MLTrainerLayerCreate);
+ REGISTER_METHOD(MLTrainerLayerGetName);
REGISTER_METHOD(MLTrainerLayerDispose);
REGISTER_METHOD(MLTrainerOptimizerSetProperty);
REGISTER_METHOD(MLTrainerOptimizerCreate);
ReportSuccess(out);
}
+void MlInstance::MLTrainerLayerGetName(const picojson::value& args,
+ picojson::object& out) {
+ ScopeLogger("args: %s", args.serialize().c_str());
+ CHECK_ARGS(args, kId, double, out);
+
+ auto id = static_cast<int>(args.get(kId).get<double>());
+
+ std::string name;
+ PlatformResult result = trainer_manager_.LayerGetName(id, name);
+ if (!result) {
+ ReportError(result, &out);
+ return;
+ }
+
+ out[kName] = picojson::value(static_cast<std::string>(name));
+ ReportSuccess(out);
+}
+
void MlInstance::MLTrainerLayerDispose(const picojson::value& args,
picojson::object& out) {
ScopeLogger("args: %s", args.serialize().c_str());
void MLTrainerLayerSetProperty(const picojson::value& args, picojson::object& out);
void MLTrainerLayerCreate(const picojson::value& args, picojson::object& out);
+ void MLTrainerLayerGetName(const picojson::value& args,
+ picojson::object& out);
void MLTrainerLayerDispose(const picojson::value& args,
picojson::object& out);
return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val));
}
- layers_[next_layer_id_] =
- std::make_shared<NativeWrapper<ml_train_layer_h>>(n_layer);
+ layers_[next_layer_id_] = std::make_shared<LayerWrapper>(n_layer);
id = next_layer_id_++;
return PlatformResult();
ml_strerror(ret_val));
return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val));
}
+
+ if (name == "name") {
+ LoggerI("Layer name set detected - changing to: %s", value.c_str());
+ layer->setName(value);
+ }
+ return PlatformResult();
+}
+
+PlatformResult TrainerManager::LayerGetName(int id, std::string& name) {
+ ScopeLogger();
+
+ if (layers_.find(id) == layers_.end()) {
+ LoggerE("Could not find layer with id: %d", id);
+ return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Could not find layer");
+ }
+
+ auto layer = layers_[id];
+
+ name = layer->getName();
return PlatformResult();
}
PlatformResult CreateLayer(int& id, ml_train_layer_type_e type);
PlatformResult LayerSetProperty(int id, const std::string& name,
const std::string& value);
+ PlatformResult LayerGetName(int id, std::string& name);
PlatformResult LayerDispose(int id);
PlatformResult CreateOptimizer(int& id, ml_train_optimizer_type_e type);
std::map<int, std::shared_ptr<Model>> models_;
std::map<int, std::shared_ptr<NativeWrapper<ml_train_optimizer_h>>> optimizers_;
- std::map<int, std::shared_ptr<NativeWrapper<ml_train_layer_h>>> layers_;
+ std::map<int, std::shared_ptr<LayerWrapper>> layers_;
std::map<int, std::shared_ptr<NativeWrapper<ml_train_dataset_h>>> datasets_;
// mutex for thread synchronization is needed only for model as only
**/
#include <mutex>
+#include <string>
#include <vector>
#include <nntrainer/nntrainer.h>
public:
NativeWrapper(T nativeHandle) : NativeWrapper() { native = nativeHandle; }
+ virtual ~NativeWrapper() = default;
+
T& operator=(const T&) = delete;
T getNative() { return native; }
bool isAttached() { return attached; }
};
+class LayerWrapper : public NativeWrapper<ml_train_layer_h> {
+ std::string name;
+
+ public:
+ LayerWrapper(ml_train_layer_h nativeHandle) : NativeWrapper(nativeHandle) {}
+ virtual ~LayerWrapper() = default;
+
+ void setName(const std::string& newName) { name = newName; }
+
+ std::string getName() { return name; }
+};
+
} // namespace ml
} // namespace extension