ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkNeuralNetworkFileWriter_h 00019 #define __itkNeuralNetworkFileWriter_h 00020 00021 #include <metaTypes.h> 00022 #include <metaUtils.h> 00023 #include <typeinfo> 00024 00025 #include "itkOneHiddenLayerBackPropagationNeuralNetwork.h" 00026 #include "itkTwoHiddenLayerBackPropagationNeuralNetwork.h" 00027 00028 #include "itkCompletelyConnectedWeightSet.h" 00029 00030 00031 #include "itkSymmetricSigmoidTransferFunction.h" 00032 00033 namespace itk 00034 { 00054 template< class TNetwork > 00055 class NeuralNetworkFileWriter:public Object 00056 { 00057 public: 00058 00060 typedef NeuralNetworkFileWriter Self; 00061 typedef Object Superclass; 00062 typedef SmartPointer< Self > Pointer; 00063 typedef SmartPointer< const Self > ConstPointer; 00064 00066 itkTypeMacro(NeuralNetworkFileWriter, Object); 00067 00069 itkNewMacro(Self); 00070 00071 typedef typename TNetwork::MeasurementVectorType MeasurementVectorType; 00072 typedef typename TNetwork::TargetVectorType TargetVectorType; 00073 00074 typedef Statistics::LayerBase< MeasurementVectorType, TargetVectorType > LayerBaseType; 00075 typedef typename LayerBaseType::Pointer LayerBasePointer; 00076 typedef typename LayerBaseType::ConstPointer LayerBaseConstPointer; 00077 00078 // typedef typename TNetwork::Pointer NetworkPointer; 00079 // typedef typename TNetwork::ConstPointer 00080 // NetworkConstPointer; 00081 00082 // typedef typename TNetwork::LayerType LayerType; 00083 // typedef typename LayerType::Pointer LayerPointer; 00084 // typedef typename LayerType::ConstPointer LayerConstPointer; 00085 // typedef typename LayerType::TransferFunctionType::Pointer 00086 // TransferFunctionPointer; 00087 // typedef typename LayerType::TransferFunctionType::ConstPointer 00088 // TransferFunctionConstPointer; 00089 00090 // typedef typename LayerType::InputFunctionType::Pointer 00091 // InputFunctionPointer; 00092 // typedef typename LayerType::InputFunctionType::ConstPointer 00093 // InputFunctionConstPointer; 00094 00095 // typedef typename LayerType::WeightSetType WeightSetType; 00096 // typedef typename LayerType::WeightSetPointer WeightSetPointer; 00097 // typedef typename LayerType::WeightSetConstPointer 00098 // WeightSetConstPointer; 00099 // typedef typename LayerType::ValueType ValueType; 00100 00102 itkSetStringMacro(FileName); 00103 00105 itkGetStringMacro(FileName); 00106 00108 //Avoiding VS6 compiler error void SetInput( const TNetwork* network ); 00109 void SetInput(TNetwork *network); 00111 00112 const TNetwork * GetInput() const; 00113 00115 void Update(void); 00116 00117 #ifdef IGNORE 00118 #undef IGNORE 00119 #endif 00120 //ASCII only works for very small networks (i.e. less than 256 weights), 00121 //and the MetaIO mechanism is not desigend for the way that this is used 00122 //to write these files out. 00123 // Comment this code out until it can be robustly written. 00124 typedef enum { IGNORE = 0, ASCII = 1, BINARY = 2 } NetworkWriteWeightsType; 00125 itkSetEnumMacro(WriteWeightValuesType, NetworkWriteWeightsType); 00126 itkGetEnumMacro(WriteWeightValuesType, NetworkWriteWeightsType); 00127 protected: 00128 NeuralNetworkFileWriter(); 00129 ~NeuralNetworkFileWriter(); 00130 virtual void PrintSelf(std::ostream & os, Indent indent) const; 00131 00132 private: 00133 void ClearFields(); 00134 00135 typedef std::vector< MET_FieldRecordType * > FieldsContainerType; 00136 00137 //Attempting to avoid VS 6 compiler error typename TNetwork::ConstPointer 00138 // m_Network; 00139 typename TNetwork::Pointer m_Network; 00140 00141 NetworkWriteWeightsType m_WriteWeightValuesType; 00142 00143 std::string m_FileName; 00144 FieldsContainerType m_Fields; 00145 00146 std::ofstream m_OutputFile; 00147 }; 00148 } // namespace itk 00149 00150 #ifndef ITK_MANUAL_INSTANTIATION 00151 #include "itkNeuralNetworkFileWriter.hxx" 00152 #endif 00153 00154 #endif 00155