Neural Networks Examples

I am trying to build the Neural Networks ITK example, but the compile fails because of a missing localMetaConfiguration.h. This requires the MetaIO package, but I do not see where this is an option to turn on in CMake, so maybe it is a default module (?)

The file is present in my build directory as ./Modules/ThirdParty/MetaIO/src/MetaIO/src/localMetaConfiguration.h

The class documentation shows ITKZLIB as a dependency, but this may be a default module as well.

Can anyone tell me how to enable these modules and get localMegaConfiguration.h so that I can complete the compile?

The ITK Neural Networks have not had any attention in many years. It would be great if you wanted to work on using them, but I will let you know that the last time I used them they were very sub-optimal performance. I think that everyone has abandoned using this implementation many years ago in favor of other more performant tools.

NeuralNetworks module does depend on MetaIO, but MetaIO is part of the default modules and is already built by default.

Which example are you trying to build? And can you provide the CMakeLists.txt file of that example?

I was wanting to build the code from the Insight Journal here: http://insight-journal.org/browse/publication/93

It might be a little bit old.

I am interested in seeing how ITK uses this technology and maybe there is some area of improvement.

Would a very simple CMakeLists.txt work?

I think the code from that Insight Journal article has already been integrated in NeuralNetworks module. A very simple CMakeLists.txt should work.

The build still failed:

[melrobin@scorpion NN]$ make
Scanning dependencies of target NNTest
[ 50%] Building CXX object CMakeFiles/NNTest.dir/itkNNetIOTest.cxx.o
In file included from /home/melrobin/projects/NN/itkNNETFileReader.h:21:0,
from /home/melrobin/projects/NN/itkNNetIOTest.cxx:26:
/usr/include/ITK-5.0/metaTypes.h:12:10: fatal error: localMetaConfiguration.h: No such file or directory
#include “localMetaConfiguration.h”
^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/NNTest.dir/build.make:63: CMakeFiles/NNTest.dir/itkNNetIOTest.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/NNTest.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Here is my CMakeLists.txt:
[melrobin@scorpion NN]$ cat CMakeLists.txt
project(NeuralNetworkExamples)

cmake_minimum_required(VERSION 3.11)

find_package(ITK REQUIRED)
add_executable(NNTest itkNNetIOTest.cxx)
target_link_libraries(NNTest ${ITK_LIBRARIES})

This file is generated, but maybe it is not installed in the correct area.

I was able to reproduce a problem with the code from IJ article. I get a slightly different error message:

2>itkNNetIOTest.cxx
2>c:\users\dzenan\desktop\nn\itknnetfilereader.h(21): fatal error C1083: Cannot open include file: 'metaTypes.h': No such file or directory

You are building quite outdated code. Can you start off from this source file instead? Enable NeuralNetworks remote module when building ITK in order to use it.

@rasoul Could you comment on issue 11 after you have tried my suggestion?

I’m sorry, but I put this response on Github instead of here:
I used the source here: https://github.com/InsightSoftwareConsortium/ITKNeuralNetworks/blob/master/test/itkNeuralNetworkIOTest.cxx

instead of the source in the Insight Journal and now receive this error:

[melrobin@scorpion NN]$ make
Scanning dependencies of target NNTest
[ 50%] Building CXX object CMakeFiles/NNTest.dir/itkNeuralNetworkIOTest.cxx.o
In file included from /usr/include/ITK-5.0/itkNeuralNetworkFileReader.h:21:0,
from /home/melrobin/projects/NN/itkNeuralNetworkIOTest.cxx:19:
/usr/include/ITK-5.0/itkMetaImageIO.h:25:10: fatal error: metaObject.h: No such file or directory
#include “metaObject.h”
^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/NNTest.dir/build.make:63: CMakeFiles/NNTest.dir/itkNeuralNetworkIOTest.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/NNTest.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Here is the CMakeLists.txt:
[melrobin@scorpion NN]$ cat CMakeLists.txt
project(NeuralNetworkExamples)

cmake_minimum_required(VERSION 3.11)

find_package(ITK REQUIRED)
add_executable(NNTest itkNeuralNetworkIOTest.cxx)
target_link_libraries(NNTest ${ITK_LIBRARIES})

You were missing include(${ITK_USE_FILE}) in your CMakeLists.txt. I also needed to rename itkNeuralNetworkIOTest into main so it reads int main(int argc,char* argv[]). Here is the modified CMakeLists.txt which worked for me:

project(NeuralNetworkExamples)

cmake_minimum_required(VERSION 3.11)

find_package(ITK REQUIRED) # includes all ITK modules
#find_package(ITK REQUIRED COMPONENTS NeuralNetworks) # only includes listed modules and their dependencies
include(${ITK_USE_FILE})

add_executable(NNTest itkNeuralNetworkIOTest.cxx)
target_link_libraries(NNTest ${ITK_LIBRARIES})

I still get more or less the same error:
Scanning dependencies of target NNTest
[ 50%] Building CXX object CMakeFiles/NNTest.dir/itkNeuralNetworkIOTest.cxx.o
In file included from /usr/include/ITK-5.0/itkNeuralNetworkFileReader.h:21:0,
from /home/melrobin/projects/NN/itkNeuralNetworkIOTest.cxx:19:
/usr/include/ITK-5.0/itkMetaImageIO.h:25:10: fatal error: metaObject.h: No such file or directory
#include “metaObject.h”
^~~~~~~~~~~~~~
compilation terminated.

Where should metaObject.h be located? It appears that the MetaIO module is installed on my filesystem.

This is the full path on my computer: C:\Dev\ITK-git\Modules\ThirdParty\MetaIO\src\MetaIO\src\metaObject.h

OK, where does this include file install to?

Since it is in the src directory, probably nowhere. But on Windows, I don’t usually “install” ITK. Or on Linux. I have many ITK builds and I use them from build directories.

But we have probably discovered the source of your problems. Bug: NeuralNetworks don’t work correctly when installed. Workaround: don’t install it, use it from build directory.

Can you try the workaround? When configuring the example, point to the build directory, not the install directory.