Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues fixed #310,#309 #320

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 14 additions & 31 deletions src_cpp/opennnBridge/nerlWorkerOpenNN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,36 +132,6 @@ namespace nerlnet
_optimizer_type = optimizer_type;
//cout << "optimizer_type = " << optimizer_type << endl;
_training_strategy_ptr->set_optimization_method(translate_optimizer_type(optimizer_type));
/*
switch(_optimizer_type){
case OPTIMIZER_GD:
{
break; //No implementation for learning rate in GD
}
case OPTIMIZER_SGD:
{
_training_strategy_ptr->get_stochastic_gradient_descent_pointer()->set_initial_learning_rate(learning_rate);
break;
}
case OPTIMIZER_CGD:
{
break; // No learning rate for CGD
}
case OPTIMIZER_QUASINEUTON:
{
break; //No learning rate for Quasi Newton
}
case OPTIMIZER_LVM:
{
break; //No learning rate for LVM
}
case OPTIMIZER_ADAM:
{
_training_strategy_ptr->get_adaptive_moment_estimation_pointer()->set_initial_learning_rate(learning_rate);
break;
}
}
*/
}

void NerlWorkerOpenNN::set_loss_method(int loss_method){
Expand Down Expand Up @@ -237,7 +207,20 @@ namespace nerlnet
}



void NerlWorkerOpenNN::get_result_calc(fTensor2DPtr calculate_res,int num_of_samples,int inputs_number,fTensor2DPtr predictData){
Tensor<Index, 1> input_variable_dimension(4);
Tensor<Index, 1> inputs_dimensions(2);
std::shared_ptr<opennn::NeuralNetwork> neural_network_ptr = get_neural_network_ptr();
if(neural_network_ptr->has_convolutional_layer())
{
ConvolutionalLayer* conv = (ConvolutionalLayer*)neural_network_ptr->get_layer_pointer(0);
input_variable_dimension.setValues({num_of_samples,conv->get_input_variables_dimensions()(1), conv->get_input_variables_dimensions()(2), conv->get_input_variables_dimensions()(3)});
*calculate_res = neural_network_ptr->calculate_outputs(predictData->data(), input_variable_dimension);
}else{
inputs_dimensions.setValues({num_of_samples, inputs_number});
*calculate_res = neural_network_ptr->calculate_outputs(predictData->data(), inputs_dimensions);
}
}

void NerlWorkerOpenNN::set_dataset(std::shared_ptr<opennn::DataSet> data_set,fTensor2DPtr TrainDataNNptr){
_data_set = data_set;
Expand Down
2 changes: 1 addition & 1 deletion src_cpp/opennnBridge/nerlWorkerOpenNN.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class NerlWorkerOpenNN : public NerlWorker
std::shared_ptr<opennn::DataSet> get_data_set() { return _data_set; };
void post_training_process(fTensor2DPtr TrainDataNNptr);
void post_predict_process(fTensor2DPtr result_ptr);

void get_result_calc(fTensor2DPtr calculate_res,int num_of_samples,int inputs_number,fTensor2DPtr predictData);
void set_optimization_method(int optimizer_type ,int learning_rate);
void set_loss_method(int loss_method);
void set_learning_rate(float learning_rate);
Expand Down
13 changes: 1 addition & 12 deletions src_cpp/opennnBridge/openNNnif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,7 @@ void* PredictFun(void* arg)
Index num_of_samples = PredictNNptr->data->dimension(0);
Index inputs_number = neural_network->get_inputs_number();
fTensor2DPtr calculate_res = std::make_shared<fTensor2D>(num_of_samples, neural_network->get_outputs_number());
Tensor<Index, 1> input_variable_dimension(4);
Tensor<Index, 1> inputs_dimensions(2);

if(neural_network->has_convolutional_layer())
{
ConvolutionalLayer* conv = (ConvolutionalLayer*)neural_network->get_layer_pointer(0);
input_variable_dimension.setValues({num_of_samples,conv->get_input_variables_dimensions()(1), conv->get_input_variables_dimensions()(2), conv->get_input_variables_dimensions()(3)});
*calculate_res = neural_network->calculate_outputs(PredictNNptr->data->data(), input_variable_dimension);
}else{
inputs_dimensions.setValues({num_of_samples, inputs_number});
*calculate_res = neural_network->calculate_outputs(PredictNNptr->data->data(), inputs_dimensions);
}
nerlworker_opennn->get_result_calc(calculate_res, num_of_samples, inputs_number, PredictNNptr->data);
nerlworker_opennn->post_predict_process(calculate_res);
nifpp::make_tensor_2d<float,fTensor2D>(env, prediction, calculate_res);
// only for AE and AEC calculate the distance between prediction labels and input data
Expand Down