# Neural Networks Examples

**URL:** https://discourse.itk.org/t/neural-networks-examples/1408
**Category:** Engineering
**Created:** [November 10, 2018, 11:19pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408 "2018-11-10T23:19:13Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![melrobin](https://discourse.itk.org/user_avatar/discourse.itk.org/melrobin/32/277_2.png) [@melrobin](https://discourse.itk.org/u/melrobin)
#### Post date: [November 10, 2018, 11:19pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/1 "2018-11-10T23:19:14Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![hjmjohnson](https://discourse.itk.org/user_avatar/discourse.itk.org/hjmjohnson/32/23_2.png) [@hjmjohnson](https://discourse.itk.org/u/hjmjohnson)
#### Post date: [November 11, 2018, 1:11am UTC](https://discourse.itk.org/t/neural-networks-examples/1408/2 "2018-11-11T01:11:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 12, 2018, 4:12pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/3 "2018-11-12T16:12:33Z")

</div>

NeuralNetworks module does [depend](https://github.com/InsightSoftwareConsortium/ITKNeuralNetworks/blob/674d2201410399d3d7075ffc2a85bcc2e27a0275/itk-module.cmake#L18) 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?

---

<div class="post-metadata">

### Author: ![melrobin](https://discourse.itk.org/user_avatar/discourse.itk.org/melrobin/32/277_2.png) [@melrobin](https://discourse.itk.org/u/melrobin)
#### Post date: [November 12, 2018, 4:54pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/4 "2018-11-12T16:54:54Z")

</div>

I was wanting to build the code from the Insight Journal here: [http://insight-journal.org/browse/publication/93](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?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 12, 2018, 6:26pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/5 "2018-11-12T18:26:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![melrobin](https://discourse.itk.org/user_avatar/discourse.itk.org/melrobin/32/277_2.png) [@melrobin](https://discourse.itk.org/u/melrobin)
#### Post date: [November 13, 2018, 2:23pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/6 "2018-11-13T14:23:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 13, 2018, 3:36pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/7 "2018-11-13T15:36:18Z")

</div>

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

```nohighlight
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](https://github.com/InsightSoftwareConsortium/ITKNeuralNetworks/blob/master/test/itkNeuralNetworkIOTest.cxx) source file instead? Enable `NeuralNetworks` remote module when building ITK in order to use it.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 13, 2018, 3:56pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/8 "2018-11-13T15:56:42Z")

</div>

@rasoul Could you comment on [issue 11](https://github.com/InsightSoftwareConsortium/ITKNeuralNetworks/issues/11) after you have tried my suggestion?

---

<div class="post-metadata">

### Author: ![melrobin](https://discourse.itk.org/user_avatar/discourse.itk.org/melrobin/32/277_2.png) [@melrobin](https://discourse.itk.org/u/melrobin)
#### Post date: [November 13, 2018, 4:07pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/9 "2018-11-13T16:07:30Z")

</div>

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](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})

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 13, 2018, 5:37pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/10 "2018-11-13T17:37:57Z")

</div>

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:

```auto
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})

```

---

<div class="post-metadata">

### Author: ![melrobin](https://discourse.itk.org/user_avatar/discourse.itk.org/melrobin/32/277_2.png) [@melrobin](https://discourse.itk.org/u/melrobin)
#### Post date: [November 13, 2018, 7:28pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/11 "2018-11-13T19:28:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 13, 2018, 7:53pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/12 "2018-11-13T19:53:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![melrobin](https://discourse.itk.org/user_avatar/discourse.itk.org/melrobin/32/277_2.png) [@melrobin](https://discourse.itk.org/u/melrobin)
#### Post date: [November 13, 2018, 10:58pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/13 "2018-11-13T22:58:39Z")

</div>

OK, where does this include file install to?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 14, 2018, 2:46pm UTC](https://discourse.itk.org/t/neural-networks-examples/1408/14 "2018-11-14T14:46:57Z")

</div>

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.
