Skip to content

Conversation

edgarriba
Copy link
Contributor

@edgarriba edgarriba commented Jun 27, 2016

This pull request creates a new module for deep learning.

  • it requires tiny-dnn (check README for installation)
  • the module provides a caffe model loader
  • a quick sample on how to use caffe loader is also provided

@edgarriba edgarriba force-pushed the dnn-modern branch 4 times, most recently from 1d8219c to 971f2a7 Compare June 28, 2016 11:10
@edgarriba edgarriba force-pushed the dnn-modern branch 2 times, most recently from 28c53bf to bcfb93e Compare September 11, 2016 11:01
# MODULE REQUIREMENTS
# ----------------------------------------------------------------------------

find_package(TinyDNN)
Copy link
Member

Choose a reason for hiding this comment

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

please use QUIET mode

@@ -0,0 +1,283 @@
# Locate Intel Threading Building Blocks include paths and libraries
Copy link
Member

@alalek alalek Oct 12, 2016

Choose a reason for hiding this comment

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

OpenCV has TBB support: https://github.com/opencv/opencv/blob/master/cmake/OpenCVDetectTBB.cmake
What kind of problems do you have with reusing of mentioned code?

Copy link
Contributor Author

@edgarriba edgarriba Dec 18, 2016

Choose a reason for hiding this comment

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

the motivation for this is that I want the user to choose if he want to build the module with TBB totally independent of the rest of the opencv modules. So, if opencv was built with TBB support maybe for X reason I don't want to use TBB with this module. /cc @bhack

Copy link
Member

Choose a reason for hiding this comment

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

This is to avoid potential conflicts, which are hard to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my solution or your solution?

@@ -0,0 +1,46 @@
# Locate the tiny-cnn library.
Copy link
Member

Choose a reason for hiding this comment

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

Replace everywhere:

tiny-cnn -> tiny-dnn
FindTinyCNN -> FindTinyDNN
TinyCNN -> TinyDNN
etc

Download tiny-cnn project somewhere in your system

cd /opt
git clone https://github.com/nyanp/tiny-cnn.git
Copy link
Member

Choose a reason for hiding this comment

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

Project has new link:

https://github.com/tiny-dnn/tiny-dnn

Copy link
Member

Choose a reason for hiding this comment

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

Problem is still here.

@edgarriba
Copy link
Contributor Author

@vpisarev @garybradski Are we going to merge this module as it is or do we wait for a clear roadmap for the dnn module? /cc @bhack

@Auron-X Auron-X mentioned this pull request Nov 18, 2016
@bhack
Copy link

bhack commented Dec 2, 2016

@edgarriba We are on this topic. I hope that we can have news soon

@sovrasov
Copy link
Contributor

@edgarriba this PR will be merged but first you need to resolve infrastructure problems mentioned by @alalek

@edgarriba
Copy link
Contributor Author

@alalek @sovrasov ready to merge

# ----------------------------------------------------------------------------
# MODULE REQUIREMENTS
# ----------------------------------------------------------------------------

Copy link
Contributor

Choose a reason for hiding this comment

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

Add cmake_policy(SET CMP0028 OLD) to avoid warning caused by :: in TinyDNN::tiny_dnn target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

endif()

find_package(Protobuf)
find_package(Caffe)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Caffe required by this module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me check

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

ocv_define_module(dnn_modern opencv_core opencv_imgproc opencv_imgcodecs WRAP python)
ocv_target_link_libraries(${the_module} TinyDNN::tiny_dnn ${REQUIRED_LIBRARIES})
Copy link
Contributor

@sovrasov sovrasov Dec 19, 2016

Choose a reason for hiding this comment

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

I followed the instructions form README, but tiny-dnn headers are missing during compilation,
so it's needed to add implicit include of sources.
Also in case if headers are included compilation fails due to -Werror=non-virtual-dtor flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you download the last version and installed via cmake commands?

Copy link
Contributor

Choose a reason for hiding this comment

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

Install target in tiny-dnn's CMake is broken at the moment (headers of 3rd party libs are not installed), so I'm just using instructions from readme. CMake command is cmake . -DTINYDNN_ROOT=~/repositories/tiny-dnn/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's what I suspected. The idea for third-party libraries is that you don't need them to run the internal algorithms. However, it's clear that something is not doing the job. We need to checkout this issue and update the upstream since I don't have a quick answer for this now. /cc @nyanp

results->clear();
results->reserve(result.size());

for (cnn_size_t i = 0; i < result.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

cnn_size_t doesn't exist anymore and should be replaced with size_t.

@edgarriba
Copy link
Contributor Author

@sovrasov @alalek could you check again? We fixed some issues in master that allows to compile without external dependencies. I tried in local and it works for me.

@@ -0,0 +1,114 @@
set(the_description "Modern Deep Learning module")

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add CMake version check here:

if(${CMAKE_VERSION} VERSION_LESS 3.2)
  message(STATUS "Module opencv_dnn_modern disabled beacuse CMake version is less than 3.2")
  ocv_module_disable(dnn_modern)
  return()
endif()

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

ocv_define_module(dnn_modern opencv_core opencv_imgproc opencv_imgcodecs WRAP python)
ocv_target_link_libraries(${the_module} ${REQUIRED_LIBRARIES})
Copy link
Contributor

Choose a reason for hiding this comment

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

For me it doesn't work unless I add the below two lines:

ocv_target_include_directories(${the_module} ${TINYDNN_INCLUDE_DIRS})
target_compile_options(${the_module} PRIVATE "-Wno-error=non-virtual-dtor")


#define CNN_USE_CAFFE_CONVERTER
#include <tiny_dnn/tiny_dnn.h>

Copy link
Contributor

Choose a reason for hiding this comment

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

Build fails with tons of linker errors related to caffe, but it can be fixed by adding here
#include <tiny_dnn/io/caffe/caffe.pb.cc>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sovrasov ok. However, not sure what's the proper way to handle this since in the library those proto files are generated during the cmake configuration
https://github.com/tiny-dnn/tiny-dnn/blob/master/examples/caffe_converter/CMakeLists.txt

Should we include this piece of code here?

Copy link
Contributor

@sovrasov sovrasov Jan 11, 2017

Choose a reason for hiding this comment

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

I think it's better to handle this in CMake and just didn't know how it done in tiny-dnn.

In case if tiny-dnn was configured with it's own CMake the most part of dnn_modern CMake becomes useless and can be removed, but current implementation can work with raw unconfigured sources. Why did you choose this way instead of relying on CMake from tiny-dnn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well the point is that tiny-dnn is header-only and very configurable so you have to setup the configuration at the moment you "link" it to the target project. However, if you have any better idea it will be welcomed.

Copy link
Contributor

@sovrasov sovrasov Jan 11, 2017

Choose a reason for hiding this comment

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

I see your point, just interested why tinydnn-config.cmake is not used.
Devs of tiny-dnn recommend it as far as I can see:

# Example to find TinyDNN headers only::
#
#   find_package(TinyDNN 0.1.0)
#   if(TinyDNN_FOUND)
#     add_executable(foo foo.cc)
#     target_link_libraries(foo TinyDNN::tiny_cnn)
#   endif()
#
# Example to find TinyDNN headers and some *static* libraries::
#
#   set(TinyDNN_USE_TBB              ON) # only find static libs
#   set(TInyCNN_USE_AVX2             ON)
#   find_package(TinyDNN 0.1.0)
#   if(TinyDNN_FOUND)
#     add_executable(foo foo.cc)
#     target_link_libraries(foo TinyDNN::tiny_cnn ${TinyDNN_LIBRARIES})
#   endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well yes, I'm the one who wrote those codes. But to use you need to install tiny-dnn headers via cmake in order to create all the targets. I didn't test at all the config file, so this can be a good starting point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave all as is, because now rewriting dnn_modern CMake and testing tiny-dnn config will take too much effort.

add FindTinyCNN.cmake and setup CMakeLists.txt

add find TBB and NNPACK to CMakeLists.txt

add caffe converter skeleton

add simple sample

eval method return scores

Update README.md

Update README.md

Update README.md
Copy link
Contributor

@sovrasov sovrasov left a comment

Choose a reason for hiding this comment

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

👍

add_definitions(-DCNN_USE_OMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
Copy link
Member

Choose a reason for hiding this comment

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

OpenCV already defines TBB and OpenMP dependencies.

@edgarriba
Copy link
Contributor Author

@alalek ping

@alalek
Copy link
Member

alalek commented Feb 8, 2017

@edgarriba
There are still several places with legacy name "tiny-cnn". Could you please replace it to "tiny-dnn" to prevent confusing of developers/users?

@edgarriba
Copy link
Contributor Author

@alalek now should be fine

@alalek
Copy link
Member

alalek commented Feb 8, 2017

Thanks!

@alalek alalek merged commit 1a26f99 into opencv:master Feb 8, 2017
allnes pushed a commit to allnes/opencv_contrib that referenced this pull request Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants