HDlModel.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /***********************************************************
  2. * File generated by the HALCON-Compiler hcomp version 20.05
  3. * Usage: Interface to C++
  4. *
  5. * Software by: MVTec Software GmbH, www.mvtec.com
  6. ***********************************************************/
  7. #ifndef HCPP_HDLMODEL
  8. #define HCPP_HDLMODEL
  9. namespace HalconCpp
  10. {
  11. // Represents an instance of a Deep Neural Network.
  12. class LIntExport HDlModel : public HHandle
  13. {
  14. public:
  15. // Create an uninitialized instance
  16. HDlModel():HHandle() {}
  17. // Copy constructor
  18. HDlModel(const HDlModel& source) : HHandle(source) {}
  19. // Copy constructor
  20. HDlModel(const HHandle& handle);
  21. // Create HDlModel from handle, taking ownership
  22. explicit HDlModel(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 ('dl_model')!
  33. virtual void AssertType(Hphandle handle) const;
  34. public:
  35. // Deep copy of all data represented by this object instance
  36. HDlModel Clone() const;
  37. /*****************************************************************************
  38. * Operator-based class constructors
  39. *****************************************************************************/
  40. // create_dl_model_detection: Create a deep learning network for object detection.
  41. explicit HDlModel(const HString& Backbone, Hlong NumClasses, const HDict& DLModelDetectionParam);
  42. // create_dl_model_detection: Create a deep learning network for object detection.
  43. explicit HDlModel(const char* Backbone, Hlong NumClasses, const HDict& DLModelDetectionParam);
  44. #ifdef _WIN32
  45. // create_dl_model_detection: Create a deep learning network for object detection.
  46. explicit HDlModel(const wchar_t* Backbone, Hlong NumClasses, const HDict& DLModelDetectionParam);
  47. #endif
  48. // read_dl_model: Read a deep learning model from a file.
  49. explicit HDlModel(const HString& FileName);
  50. // read_dl_model: Read a deep learning model from a file.
  51. explicit HDlModel(const char* FileName);
  52. #ifdef _WIN32
  53. // read_dl_model: Read a deep learning model from a file.
  54. explicit HDlModel(const wchar_t* FileName);
  55. #endif
  56. /***************************************************************************
  57. * Operators *
  58. ***************************************************************************/
  59. // Apply a deep-learning-based network on a set of images for inference.
  60. HDictArray ApplyDlModel(const HDictArray& DLSampleBatch, const HTuple& Outputs) const;
  61. // Clear a deep learning model.
  62. static void ClearDlModel(const HDlModelArray& DLModelHandle);
  63. // Clear a deep learning model.
  64. void ClearDlModel() const;
  65. // Create a deep learning network for object detection.
  66. void CreateDlModelDetection(const HString& Backbone, Hlong NumClasses, const HDict& DLModelDetectionParam);
  67. // Create a deep learning network for object detection.
  68. void CreateDlModelDetection(const char* Backbone, Hlong NumClasses, const HDict& DLModelDetectionParam);
  69. #ifdef _WIN32
  70. // Create a deep learning network for object detection.
  71. void CreateDlModelDetection(const wchar_t* Backbone, Hlong NumClasses, const HDict& DLModelDetectionParam);
  72. #endif
  73. // Deserialize a deep learning model.
  74. void DeserializeDlModel(const HSerializedItem& SerializedItemHandle);
  75. // Return the parameters of a deep learning model.
  76. HTuple GetDlModelParam(const HString& GenParamName) const;
  77. // Return the parameters of a deep learning model.
  78. HTuple GetDlModelParam(const char* GenParamName) const;
  79. #ifdef _WIN32
  80. // Return the parameters of a deep learning model.
  81. HTuple GetDlModelParam(const wchar_t* GenParamName) const;
  82. #endif
  83. // Read a deep learning model from a file.
  84. void ReadDlModel(const HString& FileName);
  85. // Read a deep learning model from a file.
  86. void ReadDlModel(const char* FileName);
  87. #ifdef _WIN32
  88. // Read a deep learning model from a file.
  89. void ReadDlModel(const wchar_t* FileName);
  90. #endif
  91. // Serialize a deep learning model.
  92. HSerializedItem SerializeDlModel() const;
  93. // Set the parameters of a deep learning model.
  94. void SetDlModelParam(const HString& GenParamName, const HTuple& GenParamValue) const;
  95. // Set the parameters of a deep learning model.
  96. void SetDlModelParam(const HString& GenParamName, double GenParamValue) const;
  97. // Set the parameters of a deep learning model.
  98. void SetDlModelParam(const char* GenParamName, double GenParamValue) const;
  99. #ifdef _WIN32
  100. // Set the parameters of a deep learning model.
  101. void SetDlModelParam(const wchar_t* GenParamName, double GenParamValue) const;
  102. #endif
  103. // Train a deep learning model.
  104. HDict TrainDlModelBatch(const HDictArray& DLSampleBatch) const;
  105. // Write a deep learning model in a file.
  106. void WriteDlModel(const HString& FileName) const;
  107. // Write a deep learning model in a file.
  108. void WriteDlModel(const char* FileName) const;
  109. #ifdef _WIN32
  110. // Write a deep learning model in a file.
  111. void WriteDlModel(const wchar_t* FileName) const;
  112. #endif
  113. // Infer the sample and generate a heatmap.
  114. HDictArray GenDlModelHeatmap(const HDictArray& DLSample, const HString& HeatmapMethod, const HTuple& TargetClasses, const HDict& GenParam) const;
  115. // Infer the sample and generate a heatmap.
  116. HDictArray GenDlModelHeatmap(const HDictArray& DLSample, const char* HeatmapMethod, const HTuple& TargetClasses, const HDict& GenParam) const;
  117. #ifdef _WIN32
  118. // Infer the sample and generate a heatmap.
  119. HDictArray GenDlModelHeatmap(const HDictArray& DLSample, const wchar_t* HeatmapMethod, const HTuple& TargetClasses, const HDict& GenParam) const;
  120. #endif
  121. // Train a deep learning model for anomaly detection.
  122. HDict TrainDlModelAnomalyDataset(const HDictArray& DLSamples, const HDict& DLTrainParam) const;
  123. };
  124. // forward declarations and types for internal array implementation
  125. template<class T> class HSmartPtr;
  126. template<class T> class HHandleBaseArrayRef;
  127. typedef HHandleBaseArrayRef<HDlModel> HDlModelArrayRef;
  128. typedef HSmartPtr< HDlModelArrayRef > HDlModelArrayPtr;
  129. // Represents multiple tool instances
  130. class LIntExport HDlModelArray : public HHandleBaseArray
  131. {
  132. public:
  133. // Create empty array
  134. HDlModelArray();
  135. // Create array from native array of tool instances
  136. HDlModelArray(HDlModel* classes, Hlong length);
  137. // Copy constructor
  138. HDlModelArray(const HDlModelArray &tool_array);
  139. // Destructor
  140. virtual ~HDlModelArray();
  141. // Assignment operator
  142. HDlModelArray &operator=(const HDlModelArray &tool_array);
  143. // Clears array and all tool instances
  144. virtual void Clear();
  145. // Get array of native tool instances
  146. const HDlModel* Tools() const;
  147. // Get number of tools
  148. virtual Hlong Length() const;
  149. // Create tool array from tuple of handles
  150. virtual void SetFromTuple(const HTuple& handles);
  151. // Get tuple of handles for tool array
  152. virtual HTuple ConvertToTuple() const;
  153. protected:
  154. // Smart pointer to internal data container
  155. HDlModelArrayPtr *mArrayPtr;
  156. };
  157. }
  158. #endif