HClassMlp.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /***********************************************************
  2. * File generated by the HALCON-Compiler hcomp version 20.11
  3. * Usage: Interface to C++
  4. *
  5. * Software by: MVTec Software GmbH, www.mvtec.com
  6. ***********************************************************/
  7. #ifndef HCPP_HCLASSMLP
  8. #define HCPP_HCLASSMLP
  9. namespace HalconCpp
  10. {
  11. // Represents an instance of a multilayer perceptron.
  12. class LIntExport HClassMlp : public HHandle
  13. {
  14. public:
  15. // Create an uninitialized instance
  16. HClassMlp():HHandle() {}
  17. // Copy constructor
  18. HClassMlp(const HClassMlp& source) : HHandle(source) {}
  19. // Copy constructor
  20. HClassMlp(const HHandle& handle);
  21. // Create HClassMlp from handle, taking ownership
  22. explicit HClassMlp(Hlong handle);
  23. bool operator==(const HHandle& obj) const
  24. {
  25. return HHandleBase::operator==(obj);
  26. }
  27. bool operator!=(const HHandle& obj) const
  28. {
  29. return HHandleBase::operator!=(obj);
  30. }
  31. protected:
  32. // Verify matching semantic type ('class_mlp')!
  33. virtual void AssertType(Hphandle handle) const;
  34. public:
  35. // Deep copy of all data represented by this object instance
  36. HClassMlp Clone() const;
  37. /*****************************************************************************
  38. * Operator-based class constructors
  39. *****************************************************************************/
  40. // read_class_mlp: Read a multilayer perceptron from a file.
  41. explicit HClassMlp(const HString& FileName);
  42. // read_class_mlp: Read a multilayer perceptron from a file.
  43. explicit HClassMlp(const char* FileName);
  44. #ifdef _WIN32
  45. // read_class_mlp: Read a multilayer perceptron from a file.
  46. explicit HClassMlp(const wchar_t* FileName);
  47. #endif
  48. // create_class_mlp: Create a multilayer perceptron for classification or regression.
  49. explicit HClassMlp(Hlong NumInput, Hlong NumHidden, Hlong NumOutput, const HString& OutputFunction, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed);
  50. // create_class_mlp: Create a multilayer perceptron for classification or regression.
  51. explicit HClassMlp(Hlong NumInput, Hlong NumHidden, Hlong NumOutput, const char* OutputFunction, const char* Preprocessing, Hlong NumComponents, Hlong RandSeed);
  52. #ifdef _WIN32
  53. // create_class_mlp: Create a multilayer perceptron for classification or regression.
  54. explicit HClassMlp(Hlong NumInput, Hlong NumHidden, Hlong NumOutput, const wchar_t* OutputFunction, const wchar_t* Preprocessing, Hlong NumComponents, Hlong RandSeed);
  55. #endif
  56. /***************************************************************************
  57. * Operators *
  58. ***************************************************************************/
  59. // Classify an image with a multilayer perceptron.
  60. HRegion ClassifyImageClassMlp(const HImage& Image, double RejectionThreshold) const;
  61. // Add training samples from an image to the training data of a multilayer perceptron.
  62. void AddSamplesImageClassMlp(const HImage& Image, const HRegion& ClassRegions) const;
  63. // Get the training data of a multilayer perceptron (MLP).
  64. HClassTrainData GetClassTrainDataMlp() const;
  65. // Add training data to a multilayer perceptron (MLP).
  66. void AddClassTrainDataMlp(const HClassTrainData& ClassTrainDataHandle) const;
  67. // Selects an optimal combination of features to classify the provided data.
  68. HTuple SelectFeatureSetMlp(const HClassTrainData& ClassTrainDataHandle, const HString& SelectionMethod, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* Score);
  69. // Selects an optimal combination of features to classify the provided data.
  70. HTuple SelectFeatureSetMlp(const HClassTrainData& ClassTrainDataHandle, const HString& SelectionMethod, const HString& GenParamName, double GenParamValue, HTuple* Score);
  71. // Selects an optimal combination of features to classify the provided data.
  72. HTuple SelectFeatureSetMlp(const HClassTrainData& ClassTrainDataHandle, const char* SelectionMethod, const char* GenParamName, double GenParamValue, HTuple* Score);
  73. #ifdef _WIN32
  74. // Selects an optimal combination of features to classify the provided data.
  75. HTuple SelectFeatureSetMlp(const HClassTrainData& ClassTrainDataHandle, const wchar_t* SelectionMethod, const wchar_t* GenParamName, double GenParamValue, HTuple* Score);
  76. #endif
  77. // Create a look-up table using a multi-layer perceptron to classify byte images.
  78. HClassLUT CreateClassLutMlp(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  79. // Clear a multilayer perceptron.
  80. static void ClearClassMlp(const HClassMlpArray& MLPHandle);
  81. // Clear a multilayer perceptron.
  82. void ClearClassMlp() const;
  83. // Clear the training data of a multilayer perceptron.
  84. static void ClearSamplesClassMlp(const HClassMlpArray& MLPHandle);
  85. // Clear the training data of a multilayer perceptron.
  86. void ClearSamplesClassMlp() const;
  87. // Deserialize a serialized multilayer perceptron.
  88. void DeserializeClassMlp(const HSerializedItem& SerializedItemHandle);
  89. // Serialize a multilayer perceptron (MLP).
  90. HSerializedItem SerializeClassMlp() const;
  91. // Read a multilayer perceptron from a file.
  92. void ReadClassMlp(const HString& FileName);
  93. // Read a multilayer perceptron from a file.
  94. void ReadClassMlp(const char* FileName);
  95. #ifdef _WIN32
  96. // Read a multilayer perceptron from a file.
  97. void ReadClassMlp(const wchar_t* FileName);
  98. #endif
  99. // Write a multilayer perceptron to a file.
  100. void WriteClassMlp(const HString& FileName) const;
  101. // Write a multilayer perceptron to a file.
  102. void WriteClassMlp(const char* FileName) const;
  103. #ifdef _WIN32
  104. // Write a multilayer perceptron to a file.
  105. void WriteClassMlp(const wchar_t* FileName) const;
  106. #endif
  107. // Read the training data of a multilayer perceptron from a file.
  108. void ReadSamplesClassMlp(const HString& FileName) const;
  109. // Read the training data of a multilayer perceptron from a file.
  110. void ReadSamplesClassMlp(const char* FileName) const;
  111. #ifdef _WIN32
  112. // Read the training data of a multilayer perceptron from a file.
  113. void ReadSamplesClassMlp(const wchar_t* FileName) const;
  114. #endif
  115. // Write the training data of a multilayer perceptron to a file.
  116. void WriteSamplesClassMlp(const HString& FileName) const;
  117. // Write the training data of a multilayer perceptron to a file.
  118. void WriteSamplesClassMlp(const char* FileName) const;
  119. #ifdef _WIN32
  120. // Write the training data of a multilayer perceptron to a file.
  121. void WriteSamplesClassMlp(const wchar_t* FileName) const;
  122. #endif
  123. // Calculate the class of a feature vector by a multilayer perceptron.
  124. HTuple ClassifyClassMlp(const HTuple& Features, const HTuple& Num, HTuple* Confidence) const;
  125. // Calculate the class of a feature vector by a multilayer perceptron.
  126. Hlong ClassifyClassMlp(const HTuple& Features, const HTuple& Num, double* Confidence) const;
  127. // Calculate the evaluation of a feature vector by a multilayer perceptron.
  128. HTuple EvaluateClassMlp(const HTuple& Features) const;
  129. // Train a multilayer perceptron.
  130. double TrainClassMlp(Hlong MaxIterations, double WeightTolerance, double ErrorTolerance, HTuple* ErrorLog) const;
  131. // Compute the information content of the preprocessed feature vectors of a multilayer perceptron.
  132. HTuple GetPrepInfoClassMlp(const HString& Preprocessing, HTuple* CumInformationCont) const;
  133. // Compute the information content of the preprocessed feature vectors of a multilayer perceptron.
  134. HTuple GetPrepInfoClassMlp(const char* Preprocessing, HTuple* CumInformationCont) const;
  135. #ifdef _WIN32
  136. // Compute the information content of the preprocessed feature vectors of a multilayer perceptron.
  137. HTuple GetPrepInfoClassMlp(const wchar_t* Preprocessing, HTuple* CumInformationCont) const;
  138. #endif
  139. // Return the number of training samples stored in the training data of a multilayer perceptron.
  140. Hlong GetSampleNumClassMlp() const;
  141. // Return a training sample from the training data of a multilayer perceptron.
  142. HTuple GetSampleClassMlp(Hlong IndexSample, HTuple* Target) const;
  143. // Get the parameters of a rejection class.
  144. HTuple GetRejectionParamsClassMlp(const HTuple& GenParamName) const;
  145. // Get the parameters of a rejection class.
  146. HTuple GetRejectionParamsClassMlp(const HString& GenParamName) const;
  147. // Get the parameters of a rejection class.
  148. HTuple GetRejectionParamsClassMlp(const char* GenParamName) const;
  149. #ifdef _WIN32
  150. // Get the parameters of a rejection class.
  151. HTuple GetRejectionParamsClassMlp(const wchar_t* GenParamName) const;
  152. #endif
  153. // Set the parameters of a rejection class.
  154. void SetRejectionParamsClassMlp(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  155. // Set the parameters of a rejection class.
  156. void SetRejectionParamsClassMlp(const HString& GenParamName, const HString& GenParamValue) const;
  157. // Set the parameters of a rejection class.
  158. void SetRejectionParamsClassMlp(const char* GenParamName, const char* GenParamValue) const;
  159. #ifdef _WIN32
  160. // Set the parameters of a rejection class.
  161. void SetRejectionParamsClassMlp(const wchar_t* GenParamName, const wchar_t* GenParamValue) const;
  162. #endif
  163. // Add a training sample to the training data of a multilayer perceptron.
  164. void AddSampleClassMlp(const HTuple& Features, const HTuple& Target) const;
  165. // Add a training sample to the training data of a multilayer perceptron.
  166. void AddSampleClassMlp(const HTuple& Features, Hlong Target) const;
  167. // Return the regularization parameters of a multilayer perceptron.
  168. HTuple GetRegularizationParamsClassMlp(const HString& GenParamName) const;
  169. // Return the regularization parameters of a multilayer perceptron.
  170. HTuple GetRegularizationParamsClassMlp(const char* GenParamName) const;
  171. #ifdef _WIN32
  172. // Return the regularization parameters of a multilayer perceptron.
  173. HTuple GetRegularizationParamsClassMlp(const wchar_t* GenParamName) const;
  174. #endif
  175. // Set the regularization parameters of a multilayer perceptron.
  176. void SetRegularizationParamsClassMlp(const HString& GenParamName, const HTuple& GenParamValue) const;
  177. // Set the regularization parameters of a multilayer perceptron.
  178. void SetRegularizationParamsClassMlp(const HString& GenParamName, double GenParamValue) const;
  179. // Set the regularization parameters of a multilayer perceptron.
  180. void SetRegularizationParamsClassMlp(const char* GenParamName, double GenParamValue) const;
  181. #ifdef _WIN32
  182. // Set the regularization parameters of a multilayer perceptron.
  183. void SetRegularizationParamsClassMlp(const wchar_t* GenParamName, double GenParamValue) const;
  184. #endif
  185. // Return the parameters of a multilayer perceptron.
  186. Hlong GetParamsClassMlp(Hlong* NumHidden, Hlong* NumOutput, HString* OutputFunction, HString* Preprocessing, Hlong* NumComponents) const;
  187. // Create a multilayer perceptron for classification or regression.
  188. void CreateClassMlp(Hlong NumInput, Hlong NumHidden, Hlong NumOutput, const HString& OutputFunction, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed);
  189. // Create a multilayer perceptron for classification or regression.
  190. void CreateClassMlp(Hlong NumInput, Hlong NumHidden, Hlong NumOutput, const char* OutputFunction, const char* Preprocessing, Hlong NumComponents, Hlong RandSeed);
  191. #ifdef _WIN32
  192. // Create a multilayer perceptron for classification or regression.
  193. void CreateClassMlp(Hlong NumInput, Hlong NumHidden, Hlong NumOutput, const wchar_t* OutputFunction, const wchar_t* Preprocessing, Hlong NumComponents, Hlong RandSeed);
  194. #endif
  195. };
  196. // forward declarations and types for internal array implementation
  197. template<class T> class HSmartPtr;
  198. template<class T> class HHandleBaseArrayRef;
  199. typedef HHandleBaseArrayRef<HClassMlp> HClassMlpArrayRef;
  200. typedef HSmartPtr< HClassMlpArrayRef > HClassMlpArrayPtr;
  201. // Represents multiple tool instances
  202. class LIntExport HClassMlpArray : public HHandleBaseArray
  203. {
  204. public:
  205. // Create empty array
  206. HClassMlpArray();
  207. // Create array from native array of tool instances
  208. HClassMlpArray(HClassMlp* classes, Hlong length);
  209. // Copy constructor
  210. HClassMlpArray(const HClassMlpArray &tool_array);
  211. // Destructor
  212. virtual ~HClassMlpArray();
  213. // Assignment operator
  214. HClassMlpArray &operator=(const HClassMlpArray &tool_array);
  215. // Clears array and all tool instances
  216. virtual void Clear();
  217. // Get array of native tool instances
  218. const HClassMlp* Tools() const;
  219. // Get number of tools
  220. virtual Hlong Length() const;
  221. // Create tool array from tuple of handles
  222. virtual void SetFromTuple(const HTuple& handles);
  223. // Get tuple of handles for tool array
  224. virtual HTuple ConvertToTuple() const;
  225. protected:
  226. // Smart pointer to internal data container
  227. HClassMlpArrayPtr *mArrayPtr;
  228. };
  229. }
  230. #endif