Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Artelnics/opennn into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
RoberLopez committed Dec 4, 2024
2 parents e34890a + f2f0ede commit 5ed0a5d
Show file tree
Hide file tree
Showing 84 changed files with 606 additions and 773 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: sonarsource/sonarcloud-github-c-cpp@v3
- name: Run build-wrapper
run: |
build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} msbuild sonar_scanner_example.vcxproj /t:rebuild /nodeReuse:false
build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} msbuild opennn.vcxproj /t:rebuild /nodeReuse:false
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions examples/mnist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ int main()
//image_data_set.set_data_path("data");
//image_data_set.set_data_path("C:/mnist/train");
// image_data_set.set_data_path("C:/binary_mnist");
image_data_set.set_data_path("C:/Users/Roberto Lopez/Documents/opennn/examples/mnist/data");
image_data_set.set_data_path("C:/binary_mnist");
//image_data_set.set_data_path("C:/Users/Roberto Lopez/Documents/opennn/examples/mnist/data");
//image_data_set.set_data_path("C:/melanoma_dataset_bmp");
//image_data_set.set_data_path("C:/melanoma_dataset_bmp_small");
//image_data_set.set_data_path("C:/melanoma_supersmall");
Expand Down
16 changes: 8 additions & 8 deletions opennn/adaptive_moment_estimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AdaptiveMomentEstimation : public OptimizationAlgorithm

public:

explicit AdaptiveMomentEstimation(LossIndex* = nullptr);
AdaptiveMomentEstimation(LossIndex* = nullptr);

const type& get_learning_rate() const;
const type& get_beta_1() const;
Expand All @@ -41,7 +41,7 @@ class AdaptiveMomentEstimation : public OptimizationAlgorithm

void set_batch_samples_number(const Index& new_batch_samples_number);

void set_default() final;
void set_default() override;

// Get

Expand All @@ -67,17 +67,17 @@ class AdaptiveMomentEstimation : public OptimizationAlgorithm

// Training

TrainingResults perform_training() final;
TrainingResults perform_training() override;

string write_optimization_algorithm_type() const final;
string write_optimization_algorithm_type() const override;

// Serialization

Tensor<string, 2> to_string_matrix() const final;
Tensor<string, 2> to_string_matrix() const override;

void from_XML(const XMLDocument&) final;
void from_XML(const XMLDocument&) override;

void to_XML(XMLPrinter&) const final;
void to_XML(XMLPrinter&) const override;

void update_parameters(BackPropagation&, AdaptiveMomentEstimationData&) const;

Expand Down Expand Up @@ -120,7 +120,7 @@ class AdaptiveMomentEstimation : public OptimizationAlgorithm

struct AdaptiveMomentEstimationData : public OptimizationAlgorithmData
{
explicit AdaptiveMomentEstimationData(AdaptiveMomentEstimation* = nullptr);
AdaptiveMomentEstimationData(AdaptiveMomentEstimation* = nullptr);

void set(AdaptiveMomentEstimation* = nullptr);

Expand Down
30 changes: 15 additions & 15 deletions opennn/addition_layer_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ class AdditionLayer3D : public Layer

public:

explicit AdditionLayer3D(const Index& = 0, const Index& = 0);
AdditionLayer3D(const Index& = 0, const Index& = 0);

Index get_inputs_number_xxx() const;
Index get_inputs_depth() const;

// @todo
dimensions get_input_dimensions() const final
dimensions get_input_dimensions() const override
{
throw runtime_error("XXX");
}

dimensions get_output_dimensions() const final;
dimensions get_output_dimensions() const override;

void set(const Index& = 0, const Index& = 0);

Expand All @@ -44,15 +44,15 @@ class AdditionLayer3D : public Layer

void forward_propagate(const vector<pair<type*, dimensions>>&,
unique_ptr<LayerForwardPropagation>&,
const bool&) final;
const bool&) override;

void back_propagate(const vector<pair<type*, dimensions>>&,
const vector<pair<type*, dimensions>>&,
unique_ptr<LayerForwardPropagation>&,
unique_ptr<LayerBackPropagation>&) const final;
unique_ptr<LayerBackPropagation>&) const override;

void from_XML(const XMLDocument&) final;
void to_XML(XMLPrinter&) const final;
void from_XML(const XMLDocument&) override;
void to_XML(XMLPrinter&) const override;

#ifdef OPENNN_CUDA
#include "../../opennn_cuda/opennn_cuda/addition_layer_3d_cuda.h"
Expand All @@ -68,27 +68,27 @@ class AdditionLayer3D : public Layer

struct AdditionLayer3DForwardPropagation : LayerForwardPropagation
{
explicit AdditionLayer3DForwardPropagation(const Index& = 0, Layer* new_layer = nullptr);
AdditionLayer3DForwardPropagation(const Index& = 0, Layer* new_layer = nullptr);

pair<type*, dimensions> get_outputs_pair() const final;
pair<type*, dimensions> get_outputs_pair() const override;

void set(const Index& = 0, Layer* = nullptr) final;
void set(const Index& = 0, Layer* = nullptr) override;

void print() const;
void print() const override;

Tensor<type, 3> outputs;
};


struct AdditionLayer3DBackPropagation : LayerBackPropagation
{
explicit AdditionLayer3DBackPropagation(const Index& = 0, Layer* = nullptr);
AdditionLayer3DBackPropagation(const Index& = 0, Layer* = nullptr);

vector<pair<type*, dimensions>> get_input_derivative_pairs() const;
vector<pair<type*, dimensions>> get_input_derivative_pairs() const override;

void set(const Index& = 0, Layer* = nullptr) final;
void set(const Index& = 0, Layer* = nullptr) override;

void print() const;
void print() const override;

Tensor<type, 3> input_1_derivatives;
Tensor<type, 3> input_2_derivatives;
Expand Down
2 changes: 1 addition & 1 deletion opennn/auto_association_data_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AutoAssociativeDataSet : public DataSet

public:

explicit AutoAssociativeDataSet();
AutoAssociativeDataSet();

vector<RawVariable> get_associative_raw_variables() const;
const Tensor<type, 2>& get_associative_data() const;
Expand Down
47 changes: 4 additions & 43 deletions opennn/auto_associative_neural_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,45 +622,9 @@ void AutoAssociativeNeuralNetwork::from_XML(const XMLDocument& document)

// Inputs

const XMLElement* inputs_element = neural_network_element->FirstChildElement("Inputs");

if(!inputs_element)
throw runtime_error("Inputs element is nullptr.");

XMLDocument inputs_document;
XMLNode* inputs_element_clone = inputs_element->DeepClone(&inputs_document);

inputs_document.InsertFirstChild(inputs_element_clone);

inputs_from_XML(inputs_document);

// Layers

const XMLElement* layers_element = neural_network_element->FirstChildElement("Layers");

if(!layers_element)
throw runtime_error("Layers element is nullptr.");

XMLDocument layers_document;
XMLNode* layers_element_clone = layers_element->DeepClone(&layers_document);

layers_document.InsertFirstChild(layers_element_clone);

layers_from_XML(layers_document);

// Outputs

const XMLElement* outputs_element = neural_network_element->FirstChildElement("Outputs");

if(!outputs_element)
throw runtime_error("Outputs element is nullptr.");

XMLDocument outputs_document;
XMLNode* outputs_element_clone = outputs_element->DeepClone(&outputs_document);

outputs_document.InsertFirstChild(outputs_element_clone);

outputs_from_XML(outputs_document);
inputs_from_XML(neural_network_element->FirstChildElement("Inputs"));
layers_from_XML(neural_network_element->FirstChildElement("Layers"));
outputs_from_XML(neural_network_element->FirstChildElement("Outputs"));

// Box plot distances

Expand Down Expand Up @@ -696,10 +660,7 @@ void AutoAssociativeNeuralNetwork::from_XML(const XMLDocument& document)

// Display

const XMLElement* display_element = neural_network_element->FirstChildElement("Display");

if(display_element)
set_display(display_element->GetText() != string("0"));
set_display(read_xml_bool(neural_network_element, "Display"));
}

}
Expand Down
2 changes: 1 addition & 1 deletion opennn/auto_associative_neural_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AutoAssociativeNeuralNetwork : public NeuralNetwork

public:

explicit AutoAssociativeNeuralNetwork();
AutoAssociativeNeuralNetwork();

BoxPlot get_auto_associative_distances_box_plot() const;
Descriptives get_distance_descriptives() const;
Expand Down
14 changes: 5 additions & 9 deletions opennn/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ void Batch::fill(const vector<Index>& sample_indices,

ImageDataSet* image_data_set = dynamic_cast<ImageDataSet*>(data_set);

if (image_data_set && image_data_set->get_augmentation())
if(image_data_set && image_data_set->get_augmentation())
{
ImageDataSet* image_data_set = static_cast<ImageDataSet*>(data_set);
/*
// @TODO
Tensor<type, 2>& augmented_data = perform_augmentation(data);
Expand Down Expand Up @@ -154,7 +153,6 @@ void Batch::set(const Index& new_batch_size, DataSet* new_data_set)
if(data_set_target_dimensions.size() == 1)
{
target_dimensions = {{batch_size, target_variables_number}};

target_tensor.resize(batch_size*target_variables_number);
}
else if(data_set_target_dimensions.size() == 2)
Expand Down Expand Up @@ -272,18 +270,16 @@ bool Batch::has_context() const

vector<pair<type*, dimensions>> Batch::get_input_pairs() const
{
vector<pair<type*, dimensions>> input_pairs(has_context() ? 2 : 1);
vector<pair<type*, dimensions>> input_pairs = {{(type*)input_tensor.data(), input_dimensions}};

input_pairs[0] = { (type*)input_tensor.data(), input_dimensions};

if (has_context())
input_pairs[1] = { (type*)context_tensor.data(), context_dimensions};
input_pairs.push_back({(type*)context_tensor.data(), context_dimensions});

return input_pairs;
}


pair<type*, dimensions> Batch::get_targets_pair() const
pair<type*, dimensions> Batch::get_target_pair() const
{
return { (type*)target_tensor.data() , target_dimensions};
}
Expand Down
2 changes: 1 addition & 1 deletion opennn/batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Batch

vector<pair<type*, dimensions>> get_input_pairs() const;

pair<type*, dimensions> get_targets_pair() const;
pair<type*, dimensions> get_target_pair() const;

Index get_batch_samples_number() const;

Expand Down
24 changes: 12 additions & 12 deletions opennn/bounding_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class BoundingLayer : public Layer

public:

explicit BoundingLayer(const dimensions& = {0}, const string& = "bounding_layer");
BoundingLayer(const dimensions& = {0}, const string& = "bounding_layer");

enum class BoundingMethod{NoBounding, Bounding};

dimensions get_input_dimensions() const final;
dimensions get_output_dimensions() const final;
dimensions get_input_dimensions() const override;
dimensions get_output_dimensions() const override;

const BoundingMethod& get_bounding_method() const;

Expand All @@ -40,8 +40,8 @@ class BoundingLayer : public Layer

void set(const dimensions & = { 0 }, const string & = "bounding_layer");

void set_input_dimensions(const dimensions&) final;
void set_output_dimensions(const dimensions&) final;
void set_input_dimensions(const dimensions&) override;
void set_output_dimensions(const dimensions&) override;

void set_bounding_method(const BoundingMethod&);
void set_bounding_method(const string&);
Expand All @@ -56,19 +56,19 @@ class BoundingLayer : public Layer

void forward_propagate(const vector<pair<type*, dimensions>>&,
unique_ptr<LayerForwardPropagation>&,
const bool&) final;
const bool&) override;

// Expression

string get_expression(const vector<string>& = vector<string>(), const vector<string>& = vector<string>()) const final;
string get_expression(const vector<string>& = vector<string>(), const vector<string>& = vector<string>()) const override;

// Serialization

void print() const;

void from_XML(const XMLDocument&) final;
void from_XML(const XMLDocument&) override;

void to_XML(XMLPrinter&) const final;
void to_XML(XMLPrinter&) const override;

private:

Expand All @@ -82,11 +82,11 @@ class BoundingLayer : public Layer

struct BoundingLayerForwardPropagation : LayerForwardPropagation
{
explicit BoundingLayerForwardPropagation(const Index& = 0, Layer* = nullptr);
BoundingLayerForwardPropagation(const Index& = 0, Layer* = nullptr);

pair<type*, dimensions> get_outputs_pair() const final;
pair<type*, dimensions> get_outputs_pair() const override;

void set(const Index& = 0, Layer* = nullptr) final;
void set(const Index& = 0, Layer* = nullptr) override;

void print() const;

Expand Down
10 changes: 5 additions & 5 deletions opennn/box_plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace opennn

struct BoxPlot
{
explicit BoxPlot(const type& = type(NAN),
const type& = type(NAN),
const type& = type(NAN),
const type& = type(NAN),
const type& = type(NAN));
BoxPlot(const type& = type(NAN),
const type& = type(NAN),
const type& = type(NAN),
const type& = type(NAN),
const type& = type(NAN));

void set(const type& = type(NAN),
const type& = type(NAN),
Expand Down
Loading

0 comments on commit 5ed0a5d

Please sign in to comment.