* @author Parichay Kapoor <pk.kapoor@samsung.com>
* @bug No known bugs except for NYI items
*/
-#include <databuffer_factory.h>
-#include <layer_factory.h>
-#include <layer_internal.h>
-#include <neuralnet.h>
-#include <nntrainer_error.h>
+
+#include <cstdarg>
+#include <cstring>
+#include <sstream>
+#include <string>
+
+#include <nntrainer.h>
#include <nntrainer_internal.h>
+
+#include <nntrainer_error.h>
#include <nntrainer_log.h>
-#include <optimizer_factory.h>
-#include <sstream>
-#include <stdarg.h>
-#include <string.h>
/**
* @brief Global lock for nntrainer C-API
*/
template <typename T>
static int ml_train_dataset_create(ml_train_dataset_h *dataset,
- nntrainer::DataBufferType type, T train,
+ ml::train::DatasetType type, T train,
T valid, T test) {
int status = ML_ERROR_NONE;
nndataset->in_use = false;
returnable f = [&]() {
- nndataset->data_buffer =
- nntrainer::createDataBuffer(type, train, valid, test);
+ nndataset->dataset = ml::train::createDataset(type, train, valid, test);
return ML_ERROR_NONE;
};
#endif
/**
- * @brief Function to create Network::NeuralNetwork object.
+ * @brief Function to create ml::train::Model object.
*/
static int nn_object(ml_train_model_h *model) {
int status = ML_ERROR_NONE;
*model = nnmodel;
- status =
- exception_bounded_make_shared<nntrainer::NeuralNetwork>(nnmodel->network);
+ returnable f = [&]() {
+ nnmodel->model = ml::train::createModel(ml::train::ModelType::NEURAL_NET);
+ return ML_ERROR_NONE;
+ };
+
+ status = nntrainer_exception_boundary(f);
if (status != ML_ERROR_NONE) {
- ml_loge("Error: creating nn object failed");
delete nnmodel;
+ ml_loge("Error: creating nn object failed");
}
return status;
ml_train_model_h *model) {
int status = ML_ERROR_NONE;
ml_train_model *nnmodel;
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
+ std::shared_ptr<ml::train::Model> m;
returnable f;
status = ml_train_model_construct(model);
return status;
nnmodel = (ml_train_model *)(*model);
- NN = nnmodel->network;
+ m = nnmodel->model;
- f = [&]() { return NN->loadFromConfig(model_conf); };
+ f = [&]() { return m->loadFromConfig(model_conf); };
status = nntrainer_exception_boundary(f);
if (status != ML_ERROR_NONE) {
ml_train_model_destroy(*model);
const char *data;
ml_train_model *nnmodel;
returnable f;
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
+ std::shared_ptr<ml::train::Model> m;
check_feature_state();
{
ML_TRAIN_GET_VALID_MODEL_LOCKED(nnmodel, model);
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
- NN = nnmodel->network;
+ m = nnmodel->model;
}
- f = [&]() { return NN->setProperty(arg_list); };
+ f = [&]() { return m->setProperty(arg_list); };
status = nntrainer_exception_boundary(f);
if (status != ML_ERROR_NONE)
return status;
- f = [&]() { return NN->compile(); };
+ f = [&]() { return m->compile(); };
status = nntrainer_exception_boundary(f);
if (status != ML_ERROR_NONE)
return status;
- f = [&]() { return NN->initialize(); };
+ f = [&]() { return m->initialize(); };
status = nntrainer_exception_boundary(f);
if (status != ML_ERROR_NONE)
return status;
int status = ML_ERROR_NONE;
ml_train_model *nnmodel;
const char *data;
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
+ std::shared_ptr<ml::train::Model> m;
check_feature_state();
{
ML_TRAIN_GET_VALID_MODEL_LOCKED(nnmodel, model);
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
- NN = nnmodel->network;
+ m = nnmodel->model;
}
- returnable f = [&]() { return NN->train(arg_list); };
+ returnable f = [&]() { return m->train(arg_list); };
status = nntrainer_exception_boundary(f);
return status;
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
}
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
- NN = nnmodel->network;
+ std::shared_ptr<ml::train::Model> m;
+ m = nnmodel->model;
if (nnmodel->optimizer) {
ML_TRAIN_RESET_VALIDATED_HANDLE(nnmodel->optimizer);
std::stringstream &ss) {
int status = ML_ERROR_NONE;
ml_train_model *nnmodel;
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
+ std::shared_ptr<ml::train::Model> m;
{
ML_TRAIN_GET_VALID_MODEL_LOCKED(nnmodel, model);
ML_TRAIN_ADOPT_LOCK(nnmodel, model_lock);
- NN = nnmodel->network;
+ m = nnmodel->model;
}
returnable f = [&]() {
- NN->printPreset(ss, verbosity);
+ m->summarize(ss, verbosity);
return ML_ERROR_NONE;
};
}
*summary = (char *)malloc((size + 1) * sizeof(char));
- memcpy(*summary, str.c_str(), size + 1);
+ std::memcpy(*summary, str.c_str(), size + 1);
return status;
}
return ML_ERROR_INVALID_PARAMETER;
}
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
- std::shared_ptr<nntrainer::Layer> NL;
+ std::shared_ptr<ml::train::Model> m;
+ std::shared_ptr<ml::train::Layer> l;
- NN = nnmodel->network;
- NL = nnlayer->layer;
+ m = nnmodel->model;
+ l = nnlayer->layer;
- if (nnmodel->layers_map.count(NL->getName())) {
+ if (nnmodel->layers_map.count(l->getName())) {
ml_loge("It is not allowed to add layer with same name: %s",
- NL->getName().c_str());
+ l->getName().c_str());
return ML_ERROR_INVALID_PARAMETER;
}
- returnable f = [&]() { return NN->addLayer(NL); };
+ returnable f = [&]() { return m->addLayer(l); };
status = nntrainer_exception_boundary(f);
if (status != ML_ERROR_NONE)
return status;
- nnmodel->layers_map.insert({NL->getName(), nnlayer});
+ nnmodel->layers_map.insert({l->getName(), nnlayer});
nnlayer->in_use = true;
return status;
}
return ML_ERROR_INVALID_PARAMETER;
}
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
- std::shared_ptr<nntrainer::Optimizer> opt;
+ std::shared_ptr<ml::train::Model> m;
+ std::shared_ptr<ml::train::Optimizer> opt;
- NN = nnmodel->network;
+ m = nnmodel->model;
opt = nnopt->optimizer;
- returnable f = [&]() { return NN->setOptimizer(opt); };
+ returnable f = [&]() { return m->setOptimizer(opt); };
status = nntrainer_exception_boundary(f);
if (status == ML_ERROR_NONE) {
return ML_ERROR_INVALID_PARAMETER;
}
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
- std::shared_ptr<nntrainer::DataBuffer> data;
+ std::shared_ptr<ml::train::Model> m;
+ std::shared_ptr<ml::train::Dataset> d;
- NN = nnmodel->network;
- data = nndataset->data_buffer;
+ m = nnmodel->model;
+ d = nndataset->dataset;
- returnable f = [&]() { return NN->setDataBuffer(data); };
+ returnable f = [&]() { return m->setDataset(d); };
status = nntrainer_exception_boundary(f);
if (status == ML_ERROR_NONE) {
}
/**
- * if layer not found in layers_map, get layer from NeuralNetwork,
+ * if layer not found in layers_map, get layer from model,
* wrap it in struct nnlayer, add new entry in layer_map and then return
*/
- std::shared_ptr<nntrainer::NeuralNetwork> NN;
- std::shared_ptr<nntrainer::Layer> NL;
+ std::shared_ptr<ml::train::Model> m;
+ std::shared_ptr<ml::train::Layer> l;
- NN = nnmodel->network;
- returnable f = [&]() { return NN->getLayer(layer_name, &NL); };
+ m = nnmodel->model;
+ returnable f = [&]() { return m->getLayer(layer_name, &l); };
status = nntrainer_exception_boundary(f);
if (status != ML_ERROR_NONE)
ml_train_layer *nnlayer = new ml_train_layer;
nnlayer->magic = ML_NNTRAINER_MAGIC;
- nnlayer->layer = NL;
+ nnlayer->layer = l;
nnlayer->in_use = true;
- nnmodel->layers_map.insert({NL->getName(), nnlayer});
+ nnmodel->layers_map.insert({l->getName(), nnlayer});
*layer = nnlayer;
return status;
nnlayer->in_use = false;
returnable f = [&]() {
- nnlayer->layer = nntrainer::createLayer(ml_layer_to_nntrainer_type(type));
+ nnlayer->layer = ml::train::createLayer((ml::train::LayerType)type);
return ML_ERROR_NONE;
};
int status = ML_ERROR_NONE;
ml_train_layer *nnlayer;
const char *data;
- std::shared_ptr<nntrainer::Layer> NL;
+ std::shared_ptr<ml::train::Layer> l;
check_feature_state();
ML_TRAIN_GET_VALID_LAYER_LOCKED(nnlayer, layer);
ML_TRAIN_ADOPT_LOCK(nnlayer, layer_lock);
- NL = nnlayer->layer;
+ l = nnlayer->layer;
}
- returnable f = [&]() { return NL->setProperty(arg_list); };
+ returnable f = [&]() { return l->setProperty(arg_list); };
status = nntrainer_exception_boundary(f);
return status;
returnable f = [&]() {
nnopt->optimizer =
- nntrainer::createOptimizer(ml_optimizer_to_nntrainer_type(type));
+ ml::train::createOptimizer((ml::train::OptimizerType)type);
return ML_ERROR_NONE;
};
int status = ML_ERROR_NONE;
ml_train_optimizer *nnopt;
const char *data;
- std::shared_ptr<nntrainer::Optimizer> opt;
+ std::shared_ptr<ml::train::Optimizer> opt;
check_feature_state();
ml_train_datagen_cb train_cb,
ml_train_datagen_cb valid_cb,
ml_train_datagen_cb test_cb) {
- return ml_train_dataset_create(dataset, nntrainer::DataBufferType::GENERATOR,
+ return ml_train_dataset_create(dataset, ml::train::DatasetType::GENERATOR,
train_cb, valid_cb, test_cb);
}
const char *train_file,
const char *valid_file,
const char *test_file) {
- return ml_train_dataset_create(dataset, nntrainer::DataBufferType::FILE,
+ return ml_train_dataset_create(dataset, ml::train::DatasetType::FILE,
train_file, valid_file, test_file);
}
int status = ML_ERROR_NONE;
ml_train_dataset *nndataset;
void *data;
- std::shared_ptr<nntrainer::DataBuffer> data_buffer;
+ std::shared_ptr<ml::train::Dataset> d;
check_feature_state();
ML_TRAIN_GET_VALID_DATASET_LOCKED(nndataset, dataset);
ML_TRAIN_ADOPT_LOCK(nndataset, dataset_lock);
- data_buffer = nndataset->data_buffer;
+ d = nndataset->dataset;
}
- returnable f = [&]() { return data_buffer->setProperty(arg_list); };
+ returnable f = [&]() { return d->setProperty(arg_list); };
status = nntrainer_exception_boundary(f);
return status;
+++ /dev/null
-// SPDX-License-Identifier: Apache-2.0
-/**
- * Copyright (C) 2020 Parichay Kapoor <pk.kapoor@samsung.com>
- *
- * @file nntrainer_util.cpp
- * @date 10 July 2020
- * @brief NNTrainer/Utilizer C-API Wrapper.
- * @see https://github.com/nnstreamer/nntrainer
- * @author Parichay Kapoor <pk.kapoor@samsung.com>
- * @bug No known bugs except for NYI items
- */
-
-#include <nntrainer_error.h>
-#include <nntrainer_internal.h>
-
-#include <activation_layer.h>
-#include <addition_layer.h>
-#include <bn_layer.h>
-#include <concat_layer.h>
-#include <conv2d_layer.h>
-#include <fc_layer.h>
-#include <flatten_layer.h>
-#include <input_layer.h>
-#include <loss_layer.h>
-#include <output_layer.h>
-#include <pooling2d_layer.h>
-
-/**
- * @brief Convert nntrainer API optimizer type to neural network optimizer type
- */
-const std::string
-ml_optimizer_to_nntrainer_type(ml_train_optimizer_type_e type) {
- switch (type) {
- case ML_TRAIN_OPTIMIZER_TYPE_ADAM:
- return "adam";
- case ML_TRAIN_OPTIMIZER_TYPE_SGD:
- return "sgd";
- case ML_TRAIN_OPTIMIZER_TYPE_UNKNOWN:
- /// fall through intended
- default:
- throw nntrainer::exception::not_supported(
- "[ml_optimmizer_to_nntrainer_type] Not supported type given");
- }
-
- throw nntrainer::exception::not_supported(
- "[ml_optimmizer_to_nntrainer_type] Not supported type given");
-}
-
-/**
- * @brief Convert nntrainer API layer type to neural network layer type
- */
-const std::string ml_layer_to_nntrainer_type(ml_train_layer_type_e type) {
- switch (type) {
- case ML_TRAIN_LAYER_TYPE_FC:
- return nntrainer::FullyConnectedLayer::type;
- case ML_TRAIN_LAYER_TYPE_INPUT:
- return nntrainer::InputLayer::type;
- case ML_TRAIN_LAYER_TYPE_BN:
- return nntrainer::BatchNormalizationLayer::type;
- case ML_TRAIN_LAYER_TYPE_CONV2D:
- return nntrainer::Conv2DLayer::type;
- case ML_TRAIN_LAYER_TYPE_POOLING2D:
- return nntrainer::Pooling2DLayer::type;
- case ML_TRAIN_LAYER_TYPE_FLATTEN:
- return nntrainer::FlattenLayer::type;
- case ML_TRAIN_LAYER_TYPE_ACTIVATION:
- return nntrainer::ActivationLayer::type;
- case ML_TRAIN_LAYER_TYPE_ADDITION:
- return nntrainer::AdditionLayer::type;
- case ML_TRAIN_LAYER_TYPE_CONCAT:
- return nntrainer::ConcatLayer::type;
- case ML_TRAIN_LAYER_TYPE_MULTIOUT:
- return nntrainer::OutputLayer::type;
- case ML_TRAIN_LAYER_TYPE_UNKNOWN:
- /// fall through intended
- default:
- throw nntrainer::exception::not_supported(
- "[ml_layer_to_nntrainer_type] Not supported type given");
- }
-
- throw std::logic_error(
- "[ml_layer_to_nntrainer_type] Control shouldn't reach here");
-}
include $(CLEAR_VARS)
-CAPI_NNTRAINER_SRCS := $(NNTRAINER_ROOT)/api/capi/src/nntrainer.cpp \
- $(NNTRAINER_ROOT)/api/capi/src/nntrainer_util.cpp
+CCAPI_NNTRAINER_SRCS := $(NNTRAINER_ROOT)/api/ccapi/src/factory.cpp
-CAPI_NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/nntrainer \
+CCAPI_NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/nntrainer \
$(NNTRAINER_ROOT)/nntrainer/dataset \
$(NNTRAINER_ROOT)/nntrainer/layers \
$(NNTRAINER_ROOT)/nntrainer/models \
- $(NNTRAINER_ROOT)/nntrainer/graph \
$(NNTRAINER_ROOT)/nntrainer/tensor \
+ $(NNTRAINER_ROOT)/nntrainer/graph \
$(NNTRAINER_ROOT)/nntrainer/optimizers \
$(NNTRAINER_ROOT)/api \
$(NNTRAINER_ROOT)/api/ccapi/include \
- $(NNTRAINER_ROOT)/api/capi/include \
$(NNTRAINER_ROOT)/api/capi/include/platform
LOCAL_SHARED_LIBRARIES := nntrainer
LOCAL_LDLIBS := -llog -landroid
-LOCAL_MODULE := capi-nntrainer
-LOCAL_SRC_FILES := $(CAPI_NNTRAINER_SRCS)
-LOCAL_C_INCLUDES := $(CAPI_NNTRAINER_INCLUDES)
+LOCAL_MODULE := ccapi-nntrainer
+LOCAL_SRC_FILES := $(CCAPI_NNTRAINER_SRCS)
+LOCAL_C_INCLUDES := $(CCAPI_NNTRAINER_INCLUDES)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
-CCAPI_NNTRAINER_SRCS := $(NNTRAINER_ROOT)/api/ccapi/src/factory.cpp
+CAPI_NNTRAINER_SRCS := $(NNTRAINER_ROOT)/api/capi/src/nntrainer.cpp
-CCAPI_NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/nntrainer \
- $(NNTRAINER_ROOT)/nntrainer/dataset \
- $(NNTRAINER_ROOT)/nntrainer/layers \
- $(NNTRAINER_ROOT)/nntrainer/models \
- $(NNTRAINER_ROOT)/nntrainer/tensor \
- $(NNTRAINER_ROOT)/nntrainer/graph \
- $(NNTRAINER_ROOT)/nntrainer/optimizers \
+CAPI_NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/nntrainer \
$(NNTRAINER_ROOT)/api \
$(NNTRAINER_ROOT)/api/ccapi/include \
+ $(NNTRAINER_ROOT)/api/capi/include \
$(NNTRAINER_ROOT)/api/capi/include/platform
-LOCAL_SHARED_LIBRARIES := nntrainer
+LOCAL_SHARED_LIBRARIES := ccapi-nntrainer
LOCAL_ARM_NEON := true
LOCAL_CFLAGS += -pthread -fexceptions
LOCAL_LDLIBS := -llog -landroid
-LOCAL_MODULE := ccapi-nntrainer
-LOCAL_SRC_FILES := $(CCAPI_NNTRAINER_SRCS)
-LOCAL_C_INCLUDES := $(CCAPI_NNTRAINER_INCLUDES)
+LOCAL_MODULE := capi-nntrainer
+LOCAL_SRC_FILES := $(CAPI_NNTRAINER_SRCS)
+LOCAL_C_INCLUDES := $(CAPI_NNTRAINER_INCLUDES)
include $(BUILD_SHARED_LIBRARY)