[Insight-developers] ItkNeuralNetworkIOTest : Code coverage...

Luis Ibanez luis.ibanez at kitware.com
Fri Aug 3 08:55:10 EDT 2007


A good reminder that we should require 100% coverage
on the code that enters the Code/Review directory.

The Mantra:


       "If it is not tested, it is broken"


proves to be true once again....


    Luis


---------------------------
Hans J. Johnson wrote:
> Raghu,
> 
> I am attempting to use the ITK neural network IO classes that you have 
> graciously provided. I am, however, getting segmentation faults when my 
> network is the specialization for a 
> OneHiddenLayerBackPropagationNeuralNetwork, and I can not read a saved 
> file into .  
> 
> I’ve added the following code to the very end of 
> itkNeuralNetworkIOTest.cxx  in an attempt to figure out what is going on:
> 
> ==============================================================
> //Now test reading and writing of OneHiddenLayerBackPropagationNeuralNetwork
>     {
>     typedef 
> itk::Statistics::OneHiddenLayerBackPropagationNeuralNetwork<MeasurementVectorType, 
> TargetVectorType> OneHiddenLayerBackPropagationNeuralNetworkType;
>     OneHiddenLayerBackPropagationNeuralNetworkType::Pointer 
> OneHiddenLayerNet = OneHiddenLayerBackPropagationNeuralNetworkType::New();
>     OneHiddenLayerNet->SetNumOfInputNodes(7);
>     OneHiddenLayerNet->SetNumOfHiddenNodes(13);
>     OneHiddenLayerNet->SetNumOfOutputNodes(5);
> 
>     OneHiddenLayerNet->Initialize();
>     OneHiddenLayerNet->InitializeWeights();
>     OneHiddenLayerNet->SetLearningRate(0.001);
>       {
>       WriterType::Pointer 
> writerOneHiddenLayerBackPropagation=WriterType::New();
>       writerOneHiddenLayerBackPropagation->SetWriteWeightValuesType(2);
>       writerOneHiddenLayerBackPropagation->SetFileName("OneHiddenLayerNet.txt");
>       writerOneHiddenLayerBackPropagation->SetInput(OneHiddenLayerNet);
>       writerOneHiddenLayerBackPropagation->Update();
>      //This writing operation causes a segmentation fault at runtime
>       }
>       {
>       ReaderType::Pointer 
> readerOneHiddenLayerBackPropagation=ReaderType::New();
>       readerOneHiddenLayerBackPropagation->SetFileName( 
> "OneHiddenLayerNet.txt" );
>       readerOneHiddenLayerBackPropagation->SetReadWeightValuesType( 1 );
>       readerOneHiddenLayerBackPropagation->Update();
>       //The following line gives a compiler error
>       //OneHiddenLayerBackPropagationNeuralNetworkType::Pointer 
> OneHiddenLayerNet_ReadIn = readerOneHiddenLayerBackPropagation->GetOutput();
>       //Need some type of comparison here
>       }
>     }
> ==============================================================
> 
> Here is the compiler error:
> /scratch/hjohnson/src/brains2/iplFreeware/unpackdir/Insight/Testing/Code/Review/itkNeuralNetworkIOTest.cxx: 
> In function 'int itkNeuralNetworkIOTest(int, char**)':
> /scratch/hjohnson/src/brains2/iplFreeware/unpackdir/Insight/Testing/Code/Review/itkNeuralNetworkIOTest.cxx:257: 
> error: invalid conversion from 
> 'itk::Statistics::MultilayerNeuralNetworkBase<itkNeuralNetworkIOTest(int, 
> char**)::MeasurementVectorType, itkNeuralNetworkIOTest(int, 
> char**)::TargetVectorType>*' to 
> 'itk::Statistics::OneHiddenLayerBackPropagationNeuralNetwork<itkNeuralNetworkIOTest(int, 
> char**)::MeasurementVectorType, itkNeuralNetworkIOTest(int, 
> char**)::TargetVectorType>*'
> /scratch/hjohnson/src/brains2/iplFreeware/unpackdir/Insight/Testing/Code/Review/itkNeuralNetworkIOTest.cxx:257: 
> error:   initializing argument 1 of 
> 'itk::SmartPointer<TObjectType>::SmartPointer(TObjectType*) [with 
> TObjectType = 
> itk::Statistics::OneHiddenLayerBackPropagationNeuralNetwork<itkNeuralNetworkIOTest(int, 
> char**)::MeasurementVectorType, itkNeuralNetworkIOTest(int, 
> char**)::TargetVectorType>]'
> make[2]: *** 
> [Testing/Code/Review/CMakeFiles/itkReviewTests.dir/itkNeuralNetworkIOTest.o] 
> Error 1
> make[1]: *** [Testing/Code/Review/CMakeFiles/itkReviewTests.dir/all] Error 2
> make: *** [all] Error 2
> 
> With the compiler error line commented out, the program builds, but a 
> segmentation fault occurs during runtime.
> 
> Perhaps this class could be templated over the network type rather than 
> the input and output parameter types?  Or does a special IO mechanism 
> need to be created for each of the Network types?  The 
> OneHiddenLayerBackPropagationNeuralNetwork is just a special case of a 
> Multilayer NeuralNetwork, so I thought that the itkNeuralNetworkIO 
> mechansim should work.
> 
> Any help or advice would be greatly appreciated.
> Thanks,
> Hans
> -- 
> Hans J. Johnson, Ph.D.
> Hans-johnson at uiowa.edu
> 
> 278 GH
> The University of Iowa
> Iowa City, IA 52241
> (319) 353 8587
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list