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

Suvorov DM/accuracy verification #115

Closed
wants to merge 9 commits into from
Closed
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
21 changes: 21 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
cmake_minimum_required(VERSION 3.7)

file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/3rdparty/opencv/build")

execute_process(
COMMAND ${CMAKE_COMMAND} -S "${CMAKE_SOURCE_DIR}/3rdparty/opencv" -B "${CMAKE_SOURCE_DIR}/3rdparty/opencv/build" -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/3rdparty/opencv/build"
)
execute_process(
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_SOURCE_DIR}/3rdparty/opencv/build" --config "${CMAKE_BUILD_TYPE}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/3rdparty/opencv/build"
)

add_executable(accuracy_app "./accuracy_app/accuracy_check.cpp")

find_package( OpenCV REQUIRED PATHS "${CMAKE_SOURCE_DIR}/3rdparty/opencv/build" )
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( accuracy_app ${OpenCV_LIBS} )

# ------------------------------------------

add_executable(Reader reader_img.cpp)
add_executable(alexnet alexnet.cpp)
target_link_libraries(alexnet AlexNetLib)
Expand Down
27 changes: 27 additions & 0 deletions app/accuracy_app/accuracy_check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <opencv2/opencv.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'opencv2/opencv.hpp' file not found [clang-diagnostic-error]

#include <opencv2/opencv.hpp>
         ^

#include <iostream>
#include <filesystem>

int main(int argc, char* argv[]) {
if (argc != 2)
throw std::exception("there must be exactly 2 arguments");
std::string image_directory(argv[1]);

std::vector<cv::String> image_paths;
cv::glob(image_directory + "*.jpg", image_paths);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opencv can read extensions

cv::glob(image_directory + "*.png", image_paths);

for (const auto& path : image_paths) {
cv::Mat image = cv::imread(path);
if (image.empty()) {
std::cerr << "The image could not be opened: " << path << std::endl;
continue;
}

// image processing will be here...
// For check. This is temporary:
std::cout << "Image size ::: " << path << " => " << image.size() << std::endl;
}

return 0;
}
Binary file added app/accuracy_app/photos/car1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/accuracy_app/photos/cat1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/accuracy_app/photos/cat2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/accuracy_app/photos/cat3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/accuracy_app/photos/cat4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/accuracy_app/photos/dog1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/accuracy_app/photos/dog2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/accuracy_app/photos/dog3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/accuracy_app/photos/dog4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion src/layers/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ std::ostream& operator<<(std::ostream& out, const Tensor& t) {
out << (*t.as<int>())[i] << " ";
} else if (t.get_type() == Type::kFloat) {
out << (*t.as<float>())[i] << " ";
}
}7
if (t.get_shape().dims() > 1) {
if ((i + 1) % t.get_shape()[1] == 0) out << std::endl;
}
}
return out;
}

template <typename T>
bool elementwiseTensorCmp(const Tensor& t1, const Tensor& t2, double threshold) {
if (t1.get_shape().count() != t2.get_shape().count())
throw std::exception("Diff_sizes");
if (t1.get_type() != t2.get_type())
throw std::exception("Diff_types");

size_t size = t1.get_shape().count();
for (size_t i = 0; i < size; i++) {
if (std::abs(*(t1.as<T>())[i] - *(t2.as<T>())[i]) > threshold) {
return false;
}
}
return true;
}
Loading