Skip to content

add java wrappers to dnn module#8998

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
abratchik:DNN.java.wrappers.fix
Jul 3, 2017
Merged

add java wrappers to dnn module#8998
opencv-pushbot merged 1 commit intoopencv:masterfrom
abratchik:DNN.java.wrappers.fix

Conversation

@abratchik
Copy link
Copy Markdown
Contributor

@abratchik abratchik commented Jun 27, 2017

This pullrequest changes

Added java wrappers to dnn module.
Added autotests based on Google Inception 5 model graph. The autotest depends on OPENCV_DNN_TEST_DATA_PATH and OPENCV_TEST_DATA_PATH environment variables pointing at correct folders where the following files should exist:

  • {OPENCV_DNN_TEST_DATA_PATH }/dnn/tensorflow_inception_graph.pb
  • {OPENCV_TEST_DATA_PATH}/dnn/space_shutte.jpg

If the OPENCV_DNN_TEST_DATA_PATH is not set the test will be disabled. If OPENCV_TEST_DATA_PATH is not set it will fail. If both env vars are set but one of the files or both are missing the test will fail.

@@ -0,0 +1,30 @@
function(download_google_inception5 dst_dir status_var)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to download these files, because they are not external to OpenCV.

  • space_shuttle.jpg : opencv sources
  • tensorflow_inception_graph.pb: opencv_extra testdata directory, check for $ENV{OPENCV_TEST_DATA_PATH}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi, Alex, thank you, this helps. Need your advice though: $ENV{OPENCV_TEST_DATA_PATH} - is this cmake variable or environment? I did not find it in CMakeVars.txt. The closest match was OPENCV_TEST_DATA_INSTALL_PATH=share/OpenCV/testdata. As far as I can see it is used currently only by text module.
The other question - do I have to copy space_shuttle to one of the build/ subfolders during cmake? Which one I need to use?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, @abratchik ! OPENCV_TEST_DATA_PATH and OPENCV_DNN_TEST_DATA_PATH both works only as environment variables.

Copy link
Copy Markdown
Contributor Author

@abratchik abratchik Jun 27, 2017

Choose a reason for hiding this comment

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

Hi, Dmitry, thank you. This makes sense. I checked on my Mac, OPENCV_TEST_DATA_PATH points at contrib_extra/testdata i.e. part of contrib_extra repository. I'm not sure if it was set automatically or I did it manually, don't remember. This is fine but here are few questions:

  1. I'd like to use space_shuttle.jpg, which is in the opencv/dnn/tutorials/images. If I copy it there it means I'm duplicating the file from opencv to opencv_extra, which is not good. On the other hand, when I'm running unit test in java, I need to find this file somehow. If it is somewhere under build/ it is easy because this is current directory for java autotests. I can also use OPENCV_TEST_DATA_PATH but this is less attractive because this variable may be not defined - do I have to skip test in this case?
  2. OPENCV_DNN_TEST_DATA_PATH is empty on my Mac. If I want my tests to be included in auto-builds, I need to know where this var is pointing to on auto-build environments.
    Sorry if my questions are a bit unclear. Please give me more detailed guidance where I need to place the test files for dnn module. I'm fine with either approach but having them in the tree under /build folder seems to be more convenient for java autotests. I also found build/share/OpenCV/testdata, could place it there. Please advise which way is the right one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OPENCV_TEST_DATA_PATH is specified manually before OpenCV test launch.

this variable may be not defined - do I have to skip test in this case?

OpenCV C++ tests fail in this case. They are "skipped" in case of external data only.
Unfortunately we don't have Java tests that uses OPENCV_TEST_DATA_PATH (in C++ tests test data is managed by "opencv_ts" module - via cvtest::findDataFile() call).

OPENCV_DNN_TEST_DATA_PATH points to additional optional data (large files with DNN models).
They can be downloaded by this script into separate directory ("OPENCV_DNN_TEST_DATA_PATH/dnn", size is 2.1Gb).

Copy link
Copy Markdown
Contributor Author

@abratchik abratchik Jun 28, 2017

Choose a reason for hiding this comment

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

Thank you Alex. So would that be safe to assume that OPENCV_DNN_TEST_DATA_PATH is set on the auto-build environments?

Last question - is it possible to move space_shuttle to testdata/dnn? I mean since there is a general rule to store test data there then I guess no point to have any test images in the main repository?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OPENCV_TEST_DATA_PATH - it must be set
OPENCV_DNN_TEST_DATA_PATH - optional, especially in case of embedded device.

is it possible to move space_shuttle to testdata/dnn

Yes, you can copy this file to opencv_extra.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great, just added, please kindly check and merge. I'll be waiting for your merge to complete the dnn wrappers pull request.

@abratchik
Copy link
Copy Markdown
Contributor Author

Hi, @alalek , with your latest patch java wrappers are generated successfully but it seems like CV__DNN_EXPERIMENTAL_ is also creating issues for python wrappers:

In file included from /build/precommit_linux64/build/modules/python3/pyopencv_generated_include.h:42:0,
                 from /build/precommit_linux64/opencv/modules/python/src2/cv2.cpp:12:
/build/precommit_linux64/opencv/modules/dnn/include/opencv2/dnn/dict.hpp:51:1: error: 'CV__DNN_EXPERIMENTAL_NS_BEGIN' does not name a type
 CV__DNN_EXPERIMENTAL_NS_BEGIN
 ^
In file included from /build/precommit_linux64/build/modules/python3/pyopencv_generated_include.h:42:0,
                 from /build/precommit_linux64/opencv/modules/python/src2/cv2.cpp:12:

@alalek
Copy link
Copy Markdown
Member

alalek commented Jun 30, 2017

Order of includes is important, please add this line into dict.hpp.

@@ -1,4 +1,4 @@
#!/usr/bin/env python
##!/usr/bin/env python
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please revert this change

Copy link
Copy Markdown
Contributor Author

@abratchik abratchik Jun 30, 2017

Choose a reason for hiding this comment

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

@alalek Sure, will do. Please also let know where I can find tensorflow_inception_graph.pb on the autobuild servers? :) I'm using OPENCV_DNN_TEST_DATA_PATH variable and it gives me /opt/build-testdata. You can check the junit report here. But it is not there ))

@alalek
Copy link
Copy Markdown
Member

alalek commented Jun 30, 2017

BTW, I have moved my fixes here: #9050

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 1, 2017

@abratchik Current failures are related to non-ASCII symbols in source code comments. I'm investigating workaround for this problem.

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 1, 2017

non-ASCII messages are related to #8895 and currently they don't cause build failure.

@abratchik
Copy link
Copy Markdown
Contributor Author

abratchik commented Jul 1, 2017

@alalek it seems like the issue with python3 wrappers. What is strange: I have both python2 and python 3 enabled on my Mac, all builds up well without any issue. I even did make clean/make just to ensure no leftovers from previous builds. One warning pops out on python3 like this:


In file included from /Users/abratchik/netbeansprojects/opencv/modules/python/src2/cv2.cpp:10:
In file included from /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/core/include/numpy/ndarrayobject.h:18:
In file included from /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/core/include/numpy/ndarraytypes.h:4:
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/core/include/numpy/npy_common.h:17:5: warning: 
      'NPY_INTERNAL_BUILD' is not defined, evaluates to 0 [-Wundef]
#if NPY_INTERNAL_BUILD

But the end all builds and compiles successfully on my machine but not on autobuild servers. I also rebased on the latest master build (e5aa213) so all your fixes should be there already. Please kindly help me as I'm out of ideas how to fix it. Seems to be some old error as if it would be before your fixes but I cannot reproduce it locally.

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 1, 2017

all builds up well without any issue

I have the same problem - can't reproduce current failures on my machine locally. Will take a look on build containers.

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 1, 2017

@abratchik Please apply this patch

@abratchik
Copy link
Copy Markdown
Contributor Author

ok, trying ...

@abratchik
Copy link
Copy Markdown
Contributor Author

abratchik commented Jul 1, 2017

@alalek Kindly merge this one please.

File currentRelativePath = new File(System.getenv("OPENCV_DNN_TEST_DATA_PATH"));
modelFileName = new File(currentRelativePath, "dnn/tensorflow_inception_graph.pb").toString();

File f = new File(currentRelativePath, "dnn/space_shuttle.jpg");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

opencv_extra testdata files are located under
OPENCV_TEST_DATA_PATH
env variable instead of
OPENCV_DNN_TEST_DATA_PATH

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alalek now tensorflow_inception_graph.pb is also missing whereas it was previously there for OPENCV_DNN_TEST_DATA_PATH :)

Copy link
Copy Markdown
Member

@alalek alalek Jul 1, 2017

Choose a reason for hiding this comment

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

There are two environment variables:

  • for general OpenCV testdata from opencv_extra: OPENCV_TEST_DATA_PATH
  • optional large DNN models: OPENCV_DNN_TEST_DATA_PATH

You should use both.

@abratchik
Copy link
Copy Markdown
Contributor Author

abratchik commented Jul 1, 2017

@alalek Alex, there is also one warning on the Mac environment, not sure what that means. Please also let me know the right location of tensorflow_inception_graph.pb and space_shutte.jpg. The first one seems to be found in the OPENCV_DNN_TEST_DATA_PATH/dnn folder but the last one is not there. Should I try to search the model in OPENCV_DNN_TEST_DATA_PATH/dnn and the jpg in OPENCV_TEST_DATA_PATH/dnn?

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 1, 2017

For Mac build try to suppress warning here:

-ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-const-variable)
+ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-const-variable -Wundef)

@abratchik
Copy link
Copy Markdown
Contributor Author

@alalek done, the compilation warning seems to be addressed. Now the only remaining issue is placement of test files )

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 1, 2017

#8998 (comment) :

There are two environment variables:

  • for general OpenCV testdata from opencv_extra: OPENCV_TEST_DATA_PATH
  • optional large DNN models: OPENCV_DNN_TEST_DATA_PATH

You should use both.

@abratchik
Copy link
Copy Markdown
Contributor Author

@alalek thank you Alex, it seems like worked this time around. Sorry it took a bit long for me to figure out since it is first time I'm writing the test case ))

@abratchik
Copy link
Copy Markdown
Contributor Author

@alalek this is ready for merge, no more commits )

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 2, 2017

👍

1 similar comment
@mshabunin
Copy link
Copy Markdown
Contributor

👍

@opencv-pushbot opencv-pushbot merged commit 8f71814 into opencv:master Jul 3, 2017
@abratchik abratchik deleted the DNN.java.wrappers.fix branch August 31, 2017 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants