Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyAM committed Dec 10, 2024
1 parent ede684c commit 3e7534b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 169 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,35 @@ on:
types: [opened, synchronize, reopened]
branches:
- dev

jobs:
build:
name: Build
runs-on: windows-latest
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
fetch-depth: 0
- name: Set up msbuild
uses: microsoft/setup-msbuild@v2
- name: Install sonar-scanner and build-wrapper
uses: sonarsource/sonarcloud-github-c-cpp@v3

- name: Build with build-wrapper
run: |
build-wrapper-win-x86-64.exe --out-dir build_wrapper_output_directory msbuild opennn.sln /t:Rebuild /p:Configuration=Release
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} # Put the name of your token here
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
run: |
sonar-scanner \
--define sonar.inclusions="opennn/opennn/**/*.cpp,opennn/opennn/**/*.h"
-Dsonar.projectKey=opennn \
-Dsonar.organization=Artelnics \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=${{ secrets.SONARCLOUD_TOKEN }} \
-Dsonar.cfamily.build-wrapper-output=build_wrapper_output_directory \
-Dsonar.inclusions="opennn/opennn/**/*.cpp,opennn/opennn/**/*.h"
2 changes: 1 addition & 1 deletion examples/mnist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main()

NeuralNetwork neural_network(NeuralNetwork::ModelType::ImageClassification,
image_data_set.get_input_dimensions(),
{ 16,8 },
{ 16 },
image_data_set.get_target_dimensions());

//neural_network.print();
Expand Down
4 changes: 4 additions & 0 deletions examples/mnist/mnist.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<ImportLibrary>Debug/mnist.lib</ImportLibrary>
<ProgramDataBaseFile>Debug/mnist.pdb</ProgramDataBaseFile>
<SubSystem>Console</SubSystem>
<Profile>true</Profile>
</Link>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
Expand Down Expand Up @@ -176,6 +177,7 @@
<ImportLibrary>Release/mnist.lib</ImportLibrary>
<ProgramDataBaseFile>Release/mnist.pdb</ProgramDataBaseFile>
<SubSystem>Console</SubSystem>
<Profile>true</Profile>
</Link>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
Expand Down Expand Up @@ -221,6 +223,7 @@
<ImportLibrary>MinSizeRel/mnist.lib</ImportLibrary>
<ProgramDataBaseFile>MinSizeRel/mnist.pdb</ProgramDataBaseFile>
<SubSystem>Console</SubSystem>
<Profile>true</Profile>
</Link>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
Expand Down Expand Up @@ -265,6 +268,7 @@
<ImportLibrary>RelWithDebInfo/mnist.lib</ImportLibrary>
<ProgramDataBaseFile>RelWithDebInfo/mnist.pdb</ProgramDataBaseFile>
<SubSystem>Console</SubSystem>
<Profile>true</Profile>
</Link>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
Expand Down
175 changes: 15 additions & 160 deletions tests/convolutional_layer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,149 +1,21 @@
#include "pch.h"

#include "../opennn/convolutional_layer.h"
/*
TEST(ConvolutionalLayerTest, EigenConvolution)
{
Tensor<type, 2> input_2;
Tensor<type, 2> kernel_2;
Tensor<type, 2> output_2;
std::cout << "Hello";
const Eigen::array<ptrdiff_t, 2> dimensions_2 = { 0, 1 };
Tensor<type, 3> input_3;
Tensor<type, 3> kernel_3;
Tensor<type, 3> output_3;
const Eigen::array<ptrdiff_t, 3> dimensions_3 = { 0, 1, 2 };
Tensor<type, 4> input_4;
Tensor<type, 3> kernel_4;
Tensor<type, 4> output_4;
const Eigen::array<ptrdiff_t, 3> dimensions_4 = { 1, 2, 3 };
// Convolution 2D, 1 channel
input_2.resize(3, 3);
input_2.setRandom();
kernel_2.resize(2, 2);
kernel_2.setRandom();
output_2 = input_2.convolve(kernel_2, dimensions_2);
// EXPECT_EQ(output_2.dimension(0), dimensions{ 2,1 });
// EXPECT_EQ( == 2);
// EXPECT_EQ(output_2.dimension(1) == 2);
// Convolution 3D, 3 channels
input_3.resize(5, 5, 3);
input_3.setRandom();
kernel_3.resize(2, 2, 3);
kernel_3.setRandom();
output_3 = input_3.convolve(kernel_3, dimensions_3);
// EXPECT_EQ(output_3.dimension(0) == 4);
// EXPECT_EQ(output_3.dimension(1) == 4);
// EXPECT_EQ(output_3.dimension(2) == 1);
// Convolution 2D, 3 channels, multiple images, 1 kernel
input_4.resize(10, 3, 5, 5);
input_4.setConstant(type(1));
input_4.chip(1, 0).setConstant(type(2));
input_4.chip(2, 0).setConstant(type(3));
kernel_4.resize(3, 2, 2);
kernel_4.setConstant(type(1.0 / 12.0));
output_4 = input_4.convolve(kernel_4, dimensions_4);
// EXPECT_EQ(output_3.dimension(0) == 10);
// EXPECT_EQ(output_3.dimension(1) == 1);
// EXPECT_EQ(output_3.dimension(2) == 4);
// EXPECT_EQ(output_3.dimension(3) == 4);
// EXPECT_EQ(abs(output_3(0, 0, 0, 0) - type(1)) < type(NUMERIC_LIMITS_MIN)
// && abs(output_3(0, 0, 0, 1) - type(1)) < type(NUMERIC_LIMITS_MIN)
// && abs(output_3(0, 0, 0, 2) - type(1)) < type(NUMERIC_LIMITS_MIN)
// && abs(output_3(0, 0, 0, 3) - type(1)) < type(NUMERIC_LIMITS_MIN)
// && abs(output_3(0, 0, 1, 0) - type(1)) < type(NUMERIC_LIMITS_MIN)
// && abs(output_3(0, 0, 1, 1) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 1, 2) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 1, 3) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 2, 0) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 2, 1) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 2, 2) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 2, 3) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 3, 0) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 3, 1) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 3, 2) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(0, 0, 3, 3) - type(1)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 0, 0) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 0, 1) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 0, 2) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 0, 3) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 1, 0) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 1, 1) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 1, 2) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 1, 3) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 2, 0) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 2, 1) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 2, 2) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 2, 3) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 3, 0) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 3, 1) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 3, 2) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(1, 0, 3, 3) - type(2)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 0, 0) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 0, 1) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 0, 2) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 0, 3) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 1, 0) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 1, 1) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 1, 2) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 1, 3) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 2, 0) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 2, 1) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 2, 2) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 2, 3) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 3, 0) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 3, 1) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 3, 2) - type(3)) < type(NUMERIC_LIMITS_MIN) &&
// abs(output_3(2, 0, 3, 3) - type(3)) <= type(NUMERIC_LIMITS_MIN));
// Convolution 3D, 2 channels
Tensor<type, 3> input(3, 3, 2);
Tensor<type, 3> kernel(2, 2, 2);
Tensor<type, 3> output(2, 2, 1);
for (int i = 0; i < 3 * 3 * 2; i++)
*(input.data() + i) = i;
for (int i = 0; i < 2 * 2 * 2; i++)
*(kernel.data() + i) = i + 1;
const Eigen::array<ptrdiff_t, 3> dimensions = { 0, 1, 2 };
output = input.convolve(kernel, dimensions);
// EXPECT_EQ(fabs(output(0, 0, 0) - 320) < type(NUMERIC_LIMITS_MIN));
// EXPECT_EQ(fabs(output(1, 0, 0) - 356) < type(NUMERIC_LIMITS_MIN));
// EXPECT_EQ(fabs(output(0, 1, 0) - 428) < type(NUMERIC_LIMITS_MIN));
// EXPECT_EQ(fabs(output(1, 1, 0) - 464) < type(NUMERIC_LIMITS_MIN));
}
=======
#include "../opennn/tensors.h"
>>>>>>> acde2b25554c3cb1fe0ef447c58dfba1588857fa


Tensor<type, 4> generate_input_tensor_convolution(const Tensor<type, 2>& data,
const vector<Index>& rows_indices,
const vector<Index>& columns_indices,
const dimensions& input_dimensions) {
Tensor<type, 4> input_tensor(rows_indices.size(),
input_dimensions[0],
input_dimensions[1],
input_dimensions[2]);
type* tensor_data = input_tensor.data();
fill_tensor_data(data, rows_indices, columns_indices, tensor_data);
return input_tensor;
}


struct ConvolutionalLayerConfig {
Expand All @@ -157,24 +29,8 @@ struct ConvolutionalLayerConfig {
Tensor<type, 4> expected_output;
};

class ConvolutionalLayerTest : public ::testing::TestWithParam<ConvolutionalLayerConfig> {};

Tensor<type, 4> generate_input_tensor_convolution(const Tensor<type, 2>& data,
const vector<Index>& rows_indices,
const vector<Index>& columns_indices,
const dimensions& input_dimensions) {
Tensor<type, 4> input_tensor(rows_indices.size(),
input_dimensions[0],
input_dimensions[1],
input_dimensions[2]);
type* tensor_data = input_tensor.data();
fill_tensor_data(data, rows_indices, columns_indices, tensor_data);
return input_tensor;
}
INSTANTIATE_TEST_CASE_P(ConvolutionalLayerTests, ConvolutionalLayerTest, ::testing::Values(
ConvolutionalLayerConfig{
{4, 4, 1}, {3, 3, 1, 1}, {1, 1}, ConvolutionalLayer::ActivationFunction::Linear, ConvolutionalLayer::ConvolutionType::Valid, "ConvolutionLayer",
Expand Down Expand Up @@ -362,5 +218,4 @@ TEST_P(ConvolutionalLayerTest, BackPropagate) {
EXPECT_EQ(weight_derivatives.dimension(1), parameters.kernel_dimensions[0]);
EXPECT_EQ(weight_derivatives.dimension(2), parameters.kernel_dimensions[1]);
EXPECT_EQ(weight_derivatives.dimension(3), parameters.kernel_dimensions[2]);
}
*/
}
6 changes: 2 additions & 4 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ int main(int argc, char **argv) {

::testing::InitGoogleTest(&argc, argv);

//::testing::GTEST_FLAG(filter) = "PerformanceTest.ImageClassification";

//::testing::GTEST_FLAG(filter) = "FlattenLayerTest";
::testing::GTEST_FLAG(filter) = "PoolingLayerTests/*";
//::testing::GTEST_FLAG(filter) = "ConvolutionalLayerTest/*";
//::testing::GTEST_FLAG(filter) = "PoolingLayerTests/*";
//::testing::GTEST_FLAG(filter) = "ConvolutionalLayerTests/*";

return RUN_ALL_TESTS();
}

0 comments on commit 3e7534b

Please sign in to comment.