Skip to content
Snippets Groups Projects
Commit 60b8533d authored by Thibault Allenet's avatar Thibault Allenet
Browse files

Merge branch 'dev' into layout

parents d0b35714 516846ea
No related branches found
No related tags found
2 merge requests!10Update backend_opencv with modifications from aidge_core,!8Fix layout from [H,W,C] to [C,H,W]
Pipeline #39419 passed
include:
- remote: 'https://gitlab.eclipse.org/eclipse/aidge/gitlab_shared_files/-/raw/main/.gitlab/ci/shared_script.gitlab-ci.yml'
build:ubuntu_cpp:
stage: build
needs: []
......@@ -8,10 +11,7 @@ build:ubuntu_cpp:
- DEPENDENCY_JOB="build:ubuntu_cpp"
# aidge_core
- DEPENDENCY_NAME="aidge_core"
- !reference [.download_dependency, script]
# aidge_backend_cpu
- DEPENDENCY_NAME="aidge_backend_cpu"
- !reference [.download_dependency, script]
- !reference [.download_dependency, script]
# Build current module
- export CMAKE_PREFIX_PATH=../install_cpp
......@@ -37,9 +37,6 @@ build:ubuntu_cpp_g++10:
# aidge_core
- DEPENDENCY_NAME="aidge_core"
- !reference [.download_dependency, script]
# aidge_backend_cpu
- DEPENDENCY_NAME="aidge_backend_cpu"
- !reference [.download_dependency, script]
# Build current module
- export CMAKE_PREFIX_PATH=../install_cpp
......@@ -62,10 +59,7 @@ build:ubuntu_cpp_g++12:
- DEPENDENCY_JOB="build:ubuntu_cpp"
# aidge_core
- DEPENDENCY_NAME="aidge_core"
- !reference [.download_dependency, script]
# aidge_backend_cpu
- DEPENDENCY_NAME="aidge_backend_cpu"
- !reference [.download_dependency, script]
- !reference [.download_dependency, script]
# Build current module
- export CMAKE_PREFIX_PATH=../install_cpp
......@@ -88,9 +82,6 @@ build:ubuntu_cpp_clang12:
- DEPENDENCY_JOB="build:ubuntu_cpp"
# aidge_core
- DEPENDENCY_NAME="aidge_core"
- !reference [.download_dependency, script]
# aidge_backend_cpu
- DEPENDENCY_NAME="aidge_backend_cpu"
- !reference [.download_dependency, script]
# Build current module
......@@ -114,10 +105,7 @@ build:ubuntu_cpp_clang15:
- DEPENDENCY_JOB="build:ubuntu_cpp"
# aidge_core
- DEPENDENCY_NAME="aidge_core"
- !reference [.download_dependency, script]
# aidge_backend_cpu
- DEPENDENCY_NAME="aidge_backend_cpu"
- !reference [.download_dependency, script]
- !reference [.download_dependency, script]
# Build current module
- export CMAKE_PREFIX_PATH=../install_cpp
......@@ -140,9 +128,6 @@ build:ubuntu_python:
- DEPENDENCY_JOB="build:ubuntu_python"
# aidge_core
- DEPENDENCY_NAME="aidge_core"
- !reference [.download_dependency, script]
# aidge_backend_cpu
- DEPENDENCY_NAME="aidge_backend_cpu"
- !reference [.download_dependency, script]
- python3 -m pip install virtualenv
......
......@@ -31,7 +31,6 @@ endif()
##############################################
# Find system dependencies
find_package(aidge_core REQUIRED)
find_package(aidge_backend_cpu REQUIRED)
find_package(OpenCV REQUIRED)
if (${OpenCV_VERSION_MAJOR} LESS 3)
MESSAGE(FATAL_ERROR "Unsupported OpenCV version. OpenCV 3.0.0+ is required")
......@@ -47,7 +46,6 @@ add_library(${module_name} ${src_files} ${inc_files})
target_link_libraries(${module_name}
PUBLIC
_aidge_core # _ is added because we link the target not the project
_aidge_backend_cpu
)
target_link_libraries(${module_name} PUBLIC ${OpenCV_LIBS})
......
......@@ -108,7 +108,7 @@ if __name__ == '__main__':
cmdclass={
'build_ext': CMakeBuild,
},
install_requires=['aidge_core','aidge_backend_cpu'],
install_requires=['aidge_core'],
zip_safe=False,
)
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#include <catch2/catch_test_macros.hpp>
#include "aidge/backend/opencv/database/MNIST.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/data/DataProvider.hpp"
// #include "aidge/backend/opencv/data/TensorImpl.hpp"
// #include "aidge/backend/cpu/data/TensorImpl.hpp"
using namespace Aidge;
TEST_CASE("DataProvider instanciation & test mnist","[Data][OpenCV]") {
// Create database
std::string path = "/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/test_mnist_database";
bool train = false;
MNIST mnist(path, train);
// DataProvider settings
unsigned int batchSize = 256;
unsigned int number_batch = std::ceil(mnist.getLen() / batchSize);
// Instanciate the dataloader
DataProvider provider(mnist, batchSize);
// Perform the tests on the batches
for (unsigned int i = 0; i < number_batch; ++i){
auto batch = provider.readBatch(i*batchSize);
auto data_batch_ptr = static_cast<uint8_t*>(batch[0]->getImpl()->rawPtr());
auto label_batch_ptr = static_cast<int*>(batch[1]->getImpl()->rawPtr());
for (unsigned int s = 0; s < batchSize; ++s){
auto data = mnist.getItem(i*batchSize+s)[0];
auto label = mnist.getItem(i*batchSize+s)[1];
unsigned int size_data = data->size();
unsigned int size_label = label->size();
auto data_ptr = static_cast<uint8_t*>(data->getImpl()->rawPtr());
auto label_ptr = static_cast<int*>(label->getImpl()->rawPtr());
for (unsigned int j = 0; j < size_data; ++j){
auto element_data = data_ptr[j];
auto element_data_batch = data_batch_ptr[size_data*s+j];
REQUIRE(element_data == element_data_batch);
}
for (unsigned int j = 0; j < size_label; ++j){
auto element_label = label_ptr[j];
auto element_label_batch = label_batch_ptr[size_label*s+j];
REQUIRE(element_label == element_label_batch);
}
}
}
}
\ No newline at end of file
......@@ -19,17 +19,37 @@
#include "aidge/backend/opencv/data/TensorImpl.hpp"
#include "aidge/data/Tensor.hpp"
#include "Tools.hpp"
using namespace Aidge;
TEST_CASE("Stimulus creation", "[Stimulus][OpenCV]") {
SECTION("Instanciation & load an image") {
// Load image with imread
cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", cv::IMREAD_UNCHANGED);
REQUIRE(true_mat.empty()==false);
// // Load image with imread
// cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", cv::IMREAD_UNCHANGED);
// REQUIRE(true_mat.empty()==false);
// // Create Stimulus
// Stimulus stimg("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", true);
// stimg.setBackend("opencv");
// Generate random matrix and save it
std::vector<cv::Mat> channels;
cv::Mat true_mat;
for (int c = 0; c < 3; ++c){
// Create a random matrix
cv::Mat randomMat = createRandomMat<unsigned char>(224, 224);
// Add each random matrix to the vector
channels.push_back(randomMat);
}
// Merge the vector of cv mat into one cv mat
cv::merge(channels, true_mat);
cv::imwrite("output_image.png", true_mat);
// Create Stimulus
Stimulus stimg("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", true);
Stimulus stimg("output_image.png", true);
stimg.setBackend("opencv");
// Load the image in a tensor & save it in memory
......@@ -38,10 +58,21 @@ TEST_CASE("Stimulus creation", "[Stimulus][OpenCV]") {
// Access the cv::Mat with the tensor
TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensor_load->getImpl().get());
auto mat_tensor = tImpl_opencv->data();
// Check the dimensions
REQUIRE((mat_tensor.total() * mat_tensor.channels()) == (true_mat.total() * true_mat.channels()));
REQUIRE((tImpl_opencv->data().total() * tImpl_opencv->data().channels()) == (true_mat.total() * true_mat.channels()));
REQUIRE(cv::countNonZero(tImpl_opencv->data() != true_mat) == 0);
// Split it in channels
std::vector<cv::Mat> channels_tensor;
cv::split(mat_tensor, channels_tensor);
REQUIRE(channels_tensor.size() == channels.size());
// Check the elements
for (size_t i = 0; i < channels_tensor.size(); ++i) {
REQUIRE(cv::countNonZero(channels_tensor[i] != channels[i]) == 0);
}
// This time the tensor is already loaded in memory
std::shared_ptr<Tensor> tensor_load_2;
......@@ -49,9 +80,20 @@ TEST_CASE("Stimulus creation", "[Stimulus][OpenCV]") {
// Access the cv::Mat with the tensor
TensorImpl_opencv_* tImpl_opencv_2 = dynamic_cast<TensorImpl_opencv_*>(tensor_load_2->getImpl().get());
auto mat_tensor_2 = tImpl_opencv_2->data();
// Check the dimensions
REQUIRE((mat_tensor_2.total() * mat_tensor_2.channels()) == (true_mat.total() * true_mat.channels()));
// Split it in channels
std::vector<cv::Mat> channels_tensor_2;
cv::split(mat_tensor_2, channels_tensor_2);
REQUIRE((tImpl_opencv_2->data().total() * tImpl_opencv_2->data().channels()) == (true_mat.total() * true_mat.channels()));
REQUIRE(cv::countNonZero(tImpl_opencv_2->data() != true_mat) == 0);
REQUIRE(channels_tensor_2.size() == channels.size());
// Check the elements
for (size_t i = 0; i < channels_tensor_2.size(); ++i) {
REQUIRE(cv::countNonZero(channels_tensor_2[i] != channels[i]) == 0);
}
}
}
......@@ -19,27 +19,60 @@
#include "aidge/backend/opencv/data/TensorImpl.hpp"
#include "aidge/data/Tensor.hpp"
#include "Tools.hpp"
using namespace Aidge;
TEST_CASE("StimulusImpl_opencv_imread creation", "[StimulusImpl_opencv_imread][OpenCV]") {
SECTION("Instanciation & load an image") {
// Load image with imread
// cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/Lenna.png");
cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", cv::IMREAD_UNCHANGED);
REQUIRE(true_mat.empty()==false);
// Create StimulusImpl_opencv_imread
// StimulusImpl_opencv_imread stImpl("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/Lenna.png");
StimulusImpl_opencv_imread stImpl("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm");
// // Load image with imread
// // cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/Lenna.png");
// cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", cv::IMREAD_UNCHANGED);
// REQUIRE(true_mat.empty()==false);
// // Create StimulusImpl_opencv_imread
// // StimulusImpl_opencv_imread stImpl("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/Lenna.png");
// StimulusImpl_opencv_imread stImpl("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm");
// Generate random matrix and save it
std::vector<cv::Mat> channels;
cv::Mat true_mat;
for (int c = 0; c < 3; ++c){
// Create a random matrix
cv::Mat randomMat = createRandomMat<unsigned char>(224, 224);
// Add each random matrix to the vector
channels.push_back(randomMat);
}
// Merge the vector of cv mat into one cv mat
cv::merge(channels, true_mat);
// Save image into a png file
cv::imwrite("output_image_stimpl.png", true_mat);
// Instanciate timulusImpl_opencv_imread
StimulusImpl_opencv_imread stImpl("output_image_stimpl.png");
// Load the image as a tensor
std::shared_ptr<Tensor> tensor_load;
tensor_load = stImpl.load();
// Access the cv::Mat with the tensor
TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensor_load->getImpl().get());
auto mat_tensor = tImpl_opencv->data();
// Check the dimensions
REQUIRE((mat_tensor.total() * mat_tensor.channels()) == (true_mat.total() * true_mat.channels()));
// Split it in channels
std::vector<cv::Mat> channels_tensor;
cv::split(mat_tensor, channels_tensor);
REQUIRE((tImpl_opencv->data().total() * tImpl_opencv->data().channels()) == (true_mat.total() * true_mat.channels()));
REQUIRE(cv::countNonZero(tImpl_opencv->data() != true_mat) == 0);
REQUIRE(channels_tensor.size() == channels.size());
// Check the elements
for (size_t i = 0; i < channels_tensor.size(); ++i) {
REQUIRE(cv::countNonZero(channels_tensor[i] != channels[i]) == 0);
}
}
}
......@@ -21,18 +21,10 @@
#include "aidge/backend/opencv/data/TensorImpl.hpp"
#include "aidge/backend/cpu/data/TensorImpl.hpp"
#include "Tools.hpp"
using namespace Aidge;
template <typename T>
cv::Mat createRandomMat(int rows, int cols) {
cv::Mat randomMat(rows, cols, cv::DataType<T>::type);
cv::randu(randomMat, cv::Scalar::all(0), cv::Scalar::all(255));
return randomMat;
}
// TEMPLATE_TEST_CASE("Opencv Utils", "[Utils][OpenCV]", char, unsigned char, short, unsigned short, int, float, double) {
// TODO : perform test for char and double
TEMPLATE_TEST_CASE("Opencv Utils", "[Utils][OpenCV]", signed char, unsigned char, short, unsigned short, int, float, double) {
......@@ -74,21 +66,17 @@ TEMPLATE_TEST_CASE("Opencv Utils", "[Utils][OpenCV]", signed char, unsigned char
REQUIRE(mat.cols == tensorOcv->dims()[2]);
// Check the matrix inside the tensor coorresponds to the matrix
//Get the matrix inside the tensor
TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensorOcv->getImpl().get());
auto mat_tensor = tImpl_opencv->data();
REQUIRE(mat_tensor.size() == mat.size());
REQUIRE(cv::countNonZero(mat_tensor != mat) == 0);
// Convert opencv tensor to cpu tensor
auto tensorCpu = convertCpu(tensorOcv);
// Split the mat from tensor opencv into channels
std::vector<cv::Mat> channels_split;
cv::split(mat_tensor, channels_split);
// Get the ptr to the std::vector<TestType> as a void * with rawPtr()
// Convert opencv tensor to cpu tensor
auto tensorCpu = convertCpu(tensorOcv);
// Get the cpu ptr of the converted tensor
auto cpu_ptr = static_cast<TestType*>(tensorCpu->getImpl()->rawPtr());
// Compare the tensor cpu values with the cv mat in an elementwise fashion
......
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#ifndef AIDGE_OPENCV_TOOLS_H_
#define AIDGE_OPENCV_TOOLS_H_
#include "opencv2/core.hpp"
template <typename T>
cv::Mat createRandomMat(int rows, int cols) {
cv::Mat randomMat(rows, cols, cv::DataType<T>::type);
cv::randu(randomMat, cv::Scalar::all(0), cv::Scalar::all(255));
return randomMat;
}
#endif // AIDGE_OPENCV_TESTS_UTILS_H_
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment