SuaKIT.h 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. #pragma once
  2. /*
  3. SuaKIT runtime API 2.2.6.3
  4. Copyright (c) 2018 SuaLab, All right reserved.
  5. */
  6. /**
  7. * @file SuaKIT.h
  8. */
  9. #ifndef __GNUC__
  10. #ifdef SUAKIT_CORELIB_DLL
  11. #define SUAKIT_API __declspec(dllexport)
  12. #else
  13. #define SUAKIT_API __declspec(dllimport)
  14. #endif
  15. #else
  16. #define SUAKIT_API __attribute__ ((visibility ("default")))
  17. #define __stdcall
  18. #endif
  19. /*
  20. GetClassName => GetClassLabelName
  21. GetMessage => GetTrainMessage
  22. */
  23. #ifndef GetClassName
  24. #define GetClassName GetClassLabelName
  25. #endif
  26. #ifndef GetMessage
  27. #define GetMessage GetTrainMessage
  28. #endif
  29. typedef int SuaKIT_Int32;
  30. typedef unsigned long long SuaKIT_UInt64;
  31. typedef long long SuaKIT_Int64;
  32. typedef unsigned char uchar;
  33. #ifdef SWIG
  34. %include <typemaps.i>
  35. %apply unsigned char INPUT[]{ uchar *dataPtr }
  36. %apply unsigned char INPUT[]{ uchar *buffer }
  37. %apply float& INOUT{ float& minLoss };
  38. %apply int& INOUT{ SuaKIT_Int32& minIteration };
  39. %apply float& INOUT{ float& recentLoss };
  40. %apply int& INOUT{ SuaKIT_Int32& recentIteration };
  41. %apply long long& INOUT{ SuaKIT_Int32& width };
  42. %apply long long& INOUT{ SuaKIT_Int32& height };
  43. %apply unsigned long long& INOUT{ SuaKIT_UInt64& gpuFreeMemSize };
  44. #endif
  45. namespace SuaKIT {
  46. namespace API {
  47. /** @brief Indicates the status of execution result of SuaKIT API */
  48. enum Status {
  49. SUCCESS = (0), /**< Success */
  50. ERR_INPUT = (1), /**< Input error */
  51. ERR_SYSTEM = (2), /**< System error */
  52. ERR_LOGIC = (3), /**< Logic error */
  53. ERR_PROTECTION = (4), /**< Protection error(check hardware protection dongle key) */
  54. ERR_INITIALIZE = (5), /**< Initialization error */
  55. ERR_TIMEOUT = (6), /**< Timeout */
  56. ERR_NOTIMPL = (7), /**< Not implemented */
  57. ERR_FATAL = (0xFFFE), /**< Fatal system error */
  58. ERR_UNKNOWN = (0xFFFF) /**< Unknown error */
  59. };
  60. /** @brief Indicates the Device type (CPU, GPU) */
  61. enum DeviceKind {
  62. DeviceKind_NON = (0), /**< NONE */
  63. DeviceKind_CPU = (1), /**< CPU */
  64. DeviceKind_GPU = (2) /**< GPU */
  65. };
  66. /** @brief Indicates the depth of the image. Depth is the "precision" of each pixel.*/
  67. enum DepthType {
  68. _8U = (1), /**< unsigned 8bit (Commonly used)*/
  69. _16U = (2) /**< unsigned 16bit */
  70. };
  71. /** @brief Indicates the input type for the SuaKIT network.*/
  72. enum InputDataType {
  73. NON = (0), /**< NONE */
  74. SINGLE = (1), /**< Single Image - Use single image (Commonly used)*/
  75. COMPARISON = (2), /**< Image Comparison - Compare two images*/
  76. MULTIMG = (3) /**< Multiple Image - N images become a unit*/
  77. };
  78. /** @brief Indicates the model type for the SuaKIT network model.*/
  79. enum ModelType {
  80. UNKNOWN_MODEL_TYPE = (0), /**< None */
  81. CLASSIFICATION = (1), /**< Classification */
  82. SEGMENTATION = (2), /**< Segmentation - default(Sensitive)*/
  83. DETECTION = (3), /**< Detection */
  84. ONECLASS_SEGMENTATION = (4), /**< OneClass segmentation */
  85. DETECTION_DOLPHIN = (5), /**< Detection - Dolphin */
  86. DETECTION_DRAGON = (6), /**< Detection - Dragon */
  87. POST_TRAIN = (7), /**< PostTrain */
  88. SEGMENTATION_SENSITIVE = (8), /**< Segmentation - Sensitive */
  89. SEGMENTATION_CONTEXTUAL = (9), /**< Segmentation - Contextual */
  90. };
  91. enum ModelFormatCvt {
  92. CNTKtoSuaKIT = (0),
  93. };
  94. /** @brief Structure containing rectangular information*/
  95. struct SUAKIT_API Rect {
  96. Rect(SuaKIT_UInt64 _x, SuaKIT_UInt64 _y, SuaKIT_UInt64 _width, SuaKIT_UInt64 _height, SuaKIT_UInt64 classNum = 0) : x(_x), y(_y), width(_width), height(_height), classNumber(classNum) {};
  97. Rect() :x(0), y(0), width(0), height(0), classNumber(0) {};
  98. bool IsEmpty() { return x == 0 && y == 0 && width == 0 && height == 0; };
  99. SuaKIT_UInt64 x, y, width, height, classNumber;
  100. };
  101. /** @brief Structure containing rectangular information for detection.*/
  102. struct SUAKIT_API DetectionRect {
  103. SuaKIT_UInt64 x, y, width, height;
  104. SuaKIT_UInt64 classNumber;
  105. float prob;
  106. float uncertainty;
  107. };
  108. /**
  109. * @brief Class regarding image data.
  110. * @details Used to send and receive image data when using the SuaKIT Runtime API. Depending on constructor options, resources are managed through reference counting.
  111. * @author ⓒSualab SuaKIT Team
  112. */
  113. class SUAKIT_API ImageData {
  114. public:
  115. /** @brief As the default constructor that is used when receiving output image data, it is used to create an image data variable that will receive the output.*/
  116. __stdcall ImageData();
  117. __stdcall ~ImageData();
  118. #ifndef SWIG
  119. /**
  120. * @brief Takes in an image pointer to create an ImageData instance.
  121. * @param dataPtr Input for the starting memory address of the image. The image data referenced by this memory address must be continuous.
  122. * @param step Input for the memory size for one line of the image. Normally, it is a width * channel value.
  123. * @param width Input for the width of the image as an integer. The width value must be 96 or greater, and it is highly recommended to use a multiple of 4.
  124. * @param height Input for the height of the image as an integer. The height value must be 96 or greater.
  125. * @param channel Input for the number of channels for the image as an integer. Currently, only 1 channel images, 3 channel images in BGR format, or 4 channel images in BGRA format are supported.
  126. * @param copyOption The ImageData resource management policy is set through the copyOption parameter.
  127. #1 copyOption: When true, a memory copy operation is carried out by the constructor, and resources are managed by reference counting.
  128. #2 copyOption: When false, memory is not copied and the data is accessed through the buffer address inputted by the user. In this case, the user is responsible for memory resources.
  129. * @param roi Specifies the roi area of the image. For an empty Rect, which is the default value, the value is ignored.
  130. * @param depth Indicates the depth of the image. Depth is the "precision" of each pixel. _8U (unsigned 8bit) is commonly used.
  131. */
  132. __stdcall ImageData(uchar* dataPtr,
  133. SuaKIT_UInt64 step,
  134. SuaKIT_UInt64 width,
  135. SuaKIT_UInt64 height,
  136. SuaKIT_UInt64 channel,
  137. bool copyOption,
  138. Rect roi = Rect(),
  139. DepthType depth = DepthType::_8U
  140. );
  141. #endif
  142. /**
  143. * @brief Takes in an image pointer to create an ImageData instance.
  144. * @param dataPtr Input for the starting memory address of the image. The image data referenced by this memory address must be continuous.
  145. * @param step Input for the memory size for one line of the image. Normally, it is a width * channel value.
  146. * @param width Input for the width of the image as an integer. The width value must be 96 or greater, and it is highly recommended to use a multiple of 4.
  147. * @param height Input for the height of the image as an integer. The height value must be 96 or greater.
  148. * @param channel Input for the number of channels for the image as an integer. Currently, only 1 channel images, 3 channel images in BGR format, or 4 channel images in BGRA format are supported.
  149. * @param roi Specifies the roi area of the image. For an empty Rect, which is the default value, the value is ignored.
  150. * @param depth Indicates the depth of the image. Depth is the "precision" of each pixel. _8U (unsigned 8bit) is commonly used.
  151. */
  152. __stdcall ImageData(uchar* dataPtr,
  153. SuaKIT_UInt64 step,
  154. SuaKIT_UInt64 width,
  155. SuaKIT_UInt64 height,
  156. SuaKIT_UInt64 channel,
  157. Rect roi = Rect(),
  158. DepthType depth = DepthType::_8U
  159. );
  160. /**
  161. * @brief Takes in an image file path to create an ImageData instance.
  162. * @param paths Input for the paths of image file. When using Image Comparison or MultiImage Type models, each image in an ImageData Separate by newline then pushed in this. In this case, you do not need to use the PushImage method.
  163. * @param roi Specifies the roi area of the image. For an empty Rect, which is the default value, the value is ignored.
  164. * @param channel Input for the number of channels for the image as an integer. Currently, only 1 channel images, 3 channel images in BGR format, or 4 channel images in BGRA format are supported.
  165. * @param depth Indicates the depth of the image. Depth is the "precision" of each pixel. _8U (unsigned 8bit) is commonly used.
  166. */
  167. __stdcall ImageData(const wchar_t * paths, Rect roi = Rect(), SuaKIT_UInt64 channel = 0, DepthType depth = DepthType::_8U);
  168. /**
  169. * @brief Creates a blank image of the input size.
  170. * @param step Input for the memory size for one line of the image. Normally, it is a width * channel value.
  171. * @param width Input for the width of the image as an integer. The width value must be 96 or greater, and it is highly recommended to use a multiple of 4.
  172. * @param height Input for the height of the image as an integer. The height value must be 96 or greater.
  173. * @param channel Input for the number of channels for the image as an integer. Currently, only 1 channel images, 3 channel images in BGR format, or 4 channel images in BGRA format are supported.
  174. * @param depth Indicates the depth of the image. Depth is the "precision" of each pixel. _8U (unsigned 8bit) is commonly used.
  175. */
  176. __stdcall ImageData(
  177. SuaKIT_UInt64 step,
  178. SuaKIT_UInt64 width,
  179. SuaKIT_UInt64 height,
  180. SuaKIT_UInt64 channel,
  181. DepthType depth = DepthType::_8U
  182. );
  183. /**
  184. * @brief Push image for MultiImage or Image Comparison. When using Image Comparison or MultiImage type models, use this method to push each image in an ImageData.
  185. The size values of the images that are pushed into an ImageData object must all be the same. Otherwise, the method fails.
  186. * @param dataPtr Pointer to the address containing the actual image pixel data, such as `data` member of `cv::Mat`.
  187. * @param step Input for the memory size for one line of the image. Normally, if width is a multiple of 4, it is a width * channel value.
  188. * @param width Input for the width of the image as an integer. The width value must be 96 or greater, and it is highly recommended to use a multiple of 4.
  189. * @param height Input for the height of the image as an integer. The height value must be 96 or greater.
  190. * @param channel Input for the number of channels for the image as an integer. Currently, only 1 channel images, 3 channel images in BGR format, or 4 channel images in BGRA format are supported.
  191. * @param copyOption The ImageData resource management policy is set through the copyOption parameter.
  192. #1 copyOption: When true, a memory copy operation is carried out by the constructor, and resources are managed by reference counting.
  193. #2 copyOption: When false, memory is not copied and the data is accessed through the buffer address inputted by the user. In this case, the user is responsible for memory resources.
  194. * @param depth Indicates the depth of the image. Depth is the "precision" of each pixel. _8U (unsigned 8bit) is commonly used.
  195. * @return Returns Status. The size values of the images that are pushed into an ImageData object must all be the same. Otherwise, the method fails.
  196. */
  197. Status __stdcall PushImage(uchar* dataPtr,
  198. SuaKIT_UInt64 step,
  199. SuaKIT_UInt64 width,
  200. SuaKIT_UInt64 height,
  201. SuaKIT_UInt64 channel,
  202. bool copyOption,
  203. DepthType depth = DepthType::_8U
  204. );
  205. /**
  206. * @brief Copies the image data to the user buffer.
  207. * @param buffer The address of the user buffer.
  208. * @param bufferByteSize The size of the user buffer in bytes.
  209. * @param index Indicates the index of each image in the ImageData object (0-based) when using Image Comparison or MultiImage type models.
  210. */
  211. Status __stdcall CopyToBuffer(uchar* buffer, SuaKIT_UInt64 bufferByteSize, SuaKIT_Int32 index = 0);
  212. #ifndef SWIG
  213. /** @brief Undocumented method*/
  214. uchar* __stdcall GetDataPtr(SuaKIT_Int32 index = 0) const;
  215. #endif
  216. /** @brief Set Image ROI*/
  217. Status __stdcall SetRoi(Rect roi);
  218. /** @brief Returns the step value for the image. */
  219. SuaKIT_UInt64 GetStep() const { return m_step; };
  220. /** @brief Returns the width value for the image.*/
  221. SuaKIT_UInt64 GetWidth() const { return m_width; };
  222. /** @brief Returns the height value for the image. */
  223. SuaKIT_UInt64 GetHeight() const { return m_height; };
  224. /** @brief Returns the channel value for the image. */
  225. SuaKIT_UInt64 GetChannel() const { return m_channel; };
  226. /** @brief Returns the depth value for the image. */
  227. DepthType GetDepth() const { return m_depth; };
  228. /** @brief Returns the roi value for the image. */
  229. Rect GetRoi() const { return m_roi; };
  230. /** @brief Returns the object’s status code. If the object was instantiated normally, will return SUCCESS.*/
  231. Status GetStatus() const { return m_status; };
  232. /** @brief Returns the object’s copy option. */
  233. bool GetCopyOption() const { return m_copyOption; };
  234. /** @brief Returns whether the given ImageData is empty.*/
  235. bool __stdcall Empty();
  236. /** @brief This method Returns the number of images pushed to an ImageData object.
  237. (If you use an Image Comparison or MultiImage type model, you will push two or more images into an ImageData object.)
  238. */
  239. SuaKIT_Int32 __stdcall GetImageCount() const;
  240. __stdcall ImageData(const ImageData &src);
  241. ImageData& __stdcall operator=(const ImageData& rhs);
  242. #ifndef SWIG
  243. /** @brief Undocumented method*/
  244. void* GetInternal() const { return internal; };
  245. #endif
  246. /** @brief Undocumented method*/
  247. static ImageData CreateMaskImageFromJson(SuaKIT_UInt64 width, SuaKIT_UInt64 height, const wchar_t* json, Rect roi = Rect()); //Undocumented methods
  248. /** @brief Undocumented method*/
  249. void __stdcall Save(const char * paths, SuaKIT_Int32 idx = 0);
  250. private:
  251. bool __stdcall memberValueCheck();
  252. SuaKIT_UInt64 m_step;
  253. SuaKIT_UInt64 m_width;
  254. SuaKIT_UInt64 m_height;
  255. SuaKIT_UInt64 m_channel;
  256. DepthType m_depth;
  257. Rect m_roi;
  258. void* internal;
  259. Status m_status;
  260. bool m_copyOption;
  261. };
  262. /**
  263. * @brief An array wrapper class for a type (integer, float, Rect, DeviceDescriptor, Size) that is trivially copyable.
  264. * @details
  265. * @author ⓒSualab SuaKIT Team
  266. */
  267. template<typename VAL_TYPE>
  268. class DataArray {
  269. public:
  270. /** @brief As the default constructor that is used when receiving multiple pieces of output data, it is used to create an array that will receive the output. */
  271. DataArray() : m_startp(0), m_capacity(0), m_byteSize(0) { }
  272. /**
  273. * @brief Creates an array with the number of elements corresponding to size.
  274. * @param size Input for the size of the array to be created.
  275. */
  276. DataArray(SuaKIT_UInt64 size);
  277. ~DataArray();
  278. /** @brief Get the item value(reference) at any location. */
  279. const VAL_TYPE& GetAt(SuaKIT_UInt64 idx) const;
  280. /** @brief Get the item value at any location. */
  281. VAL_TYPE GetValue(SuaKIT_UInt64 idx) const;
  282. /** @brief Returns the byte size of the Array. */
  283. SuaKIT_UInt64 GetByteSize() const;
  284. /** @brief Returns the total number of items within the array.*/
  285. SuaKIT_UInt64 GetLength() const;
  286. /**
  287. * @brief Sets the input item at the idx position of the array.
  288. * @param idx Index position where the image data is to be set.
  289. * @param item The item to be set.
  290. */
  291. Status SetAt(SuaKIT_UInt64 idx, const VAL_TYPE& item);
  292. #ifndef SWIG
  293. /** @brief Undocumented method*/
  294. VAL_TYPE* GetDataPtr();
  295. /** @brief Undocumented method*/
  296. const VAL_TYPE* GetDataPtr() const;
  297. #endif
  298. /** @brief Undocumented method*/
  299. void _resize(SuaKIT_UInt64 size);
  300. private:
  301. DataArray(const DataArray & src); //=delete;
  302. DataArray& operator=(const DataArray& rhs); //=delete;
  303. SuaKIT_Int64 m_capacity;
  304. SuaKIT_Int64 m_byteSize;
  305. void* m_startp;
  306. void* internal;
  307. };
  308. /**
  309. * @brief An array wrapper class for ImageData. Copy constructors and assignment operators are forbidden.
  310. * @details
  311. * @author ⓒSualab SuaKIT Team
  312. */
  313. class SUAKIT_API ImageArray {
  314. public:
  315. /** @brief As the default constructor that is used when receiving multiple pieces of output image data, it is used to create an image data array that will receive the output. */
  316. __stdcall ImageArray();
  317. /**
  318. * @brief Creates an array for the ImageData corresponding to the inputted size value.
  319. * @param size Input for the size of the array to be created.
  320. */
  321. __stdcall ImageArray(SuaKIT_UInt64 size);
  322. __stdcall ~ImageArray();
  323. /** @brief Gets the ImageData at position idx. */
  324. const ImageData& __stdcall GetAt(SuaKIT_UInt64 idx) const;
  325. /** @brief Returns the total number of ImageData objects within the array. */
  326. SuaKIT_UInt64 GetLength() const { return m_length; }
  327. /**
  328. * @brief Sets the input item at the idx position of the array.
  329. * @param idx Index position where the image data is to be set.
  330. * @param item The item to be set.
  331. */
  332. Status __stdcall SetAt(SuaKIT_UInt64 idx, const ImageData& item);
  333. #ifndef SWIG
  334. /** @brief Undocumented method*/
  335. Status __stdcall SetAt(
  336. SuaKIT_UInt64 idx,
  337. uchar* dataPtr,
  338. SuaKIT_UInt64 step,
  339. SuaKIT_UInt64 width,
  340. SuaKIT_UInt64 height,
  341. SuaKIT_UInt64 channel,
  342. bool copyOption = true
  343. );
  344. /** @brief Undocumented method*/
  345. void __stdcall _resize(SuaKIT_UInt64 size);
  346. #endif
  347. private:
  348. ImageArray(const ImageArray & src); //=delete;
  349. ImageArray& operator=(const ImageArray& rhs); //=delete;
  350. SuaKIT_Int64 m_capacity;
  351. SuaKIT_Int64 m_length;
  352. ImageData* m_startp;
  353. void* internal;
  354. };
  355. /**
  356. * @brief Two-dimensional array wrapper to hold DetectionRect. Copy constructors and assignment operators are forbidden.
  357. * @details
  358. * @author ⓒSualab SuaKIT Team
  359. */
  360. class SUAKIT_API DetRectArrayOfArray
  361. {
  362. public:
  363. __stdcall DetRectArrayOfArray();
  364. __stdcall ~DetRectArrayOfArray();
  365. /** @brief Returns the number of DetRectArray Items in DetRectArrayOfArray.*/
  366. SuaKIT_UInt64 __stdcall GetLength() const;
  367. /** @brief Returns the number of DetectionRect Items in the DetRectArray at idx_first.*/
  368. SuaKIT_UInt64 __stdcall GetLength(SuaKIT_UInt64 idx_first) const;
  369. /** @brief Retrieves the Item at the [idx_first][idx_second] position. */
  370. const DetectionRect& __stdcall GetAt(SuaKIT_UInt64 idx_first, SuaKIT_UInt64 idx_second) const;
  371. /** @brief Removes the Item at [idx_first][idx_second] position. */
  372. Status __stdcall Remove(SuaKIT_UInt64 idx_first, SuaKIT_UInt64 idx_second);
  373. /**
  374. * @brief Sets the length of the array of arrays.
  375. * @param len_first Length of the array of arrays.
  376. */
  377. Status __stdcall SetLength(SuaKIT_UInt64 len_first);
  378. /**
  379. * @brief Sets the length of the array at the idx_first position.
  380. * @param idx_first Index of the array whose length is set.
  381. * @param len_second Length of the idx_first-th array.
  382. */
  383. Status __stdcall SetLength(SuaKIT_UInt64 idx_first, SuaKIT_UInt64 len_second);
  384. /**
  385. * @brief Sets the input item at the idx position of the array. ([idx_first][idx_second] = item)
  386. * @param idx_first Index position where the image data is to be set.
  387. * @param idx_second Index position where the image data is to be set.
  388. * @param item The item to be set.
  389. */
  390. Status __stdcall SetAt(SuaKIT_UInt64 idx_first, SuaKIT_UInt64 idx_second, const DetectionRect& item);
  391. private:
  392. DetRectArrayOfArray(const DetRectArrayOfArray& src); //=delete;
  393. DetRectArrayOfArray& operator=(const DetRectArrayOfArray& rhs); //=delete;
  394. void* internal;
  395. };
  396. /** @brief Structure for image size */
  397. struct Size { SuaKIT_UInt64 width, height; };
  398. class DeviceDescriptor;
  399. typedef DataArray<SuaKIT_Int64> Int64Array;
  400. typedef DataArray<SuaKIT_Int32> Int32Array;
  401. typedef DataArray<float> FloatArray;
  402. typedef DataArray<Rect> RectArray;
  403. typedef DataArray<DeviceDescriptor> DeviceDescriptorArray;
  404. typedef DataArray<Size> SizeArray;
  405. typedef DataArray<bool> BoolArray;
  406. #if SWIG
  407. %template(Int64Array)DataArray<SuaKIT_Int64>;
  408. %template(Int32Array)DataArray<int>;
  409. %template(FloatArray)DataArray<float>;
  410. %template(RectArray)DataArray<Rect>;
  411. %template(DeviceDescriptorArray)DataArray<DeviceDescriptor>;
  412. %template(SizeArray)DataArray<Size>;
  413. %template(BoolArray)DataArray<bool>;
  414. #endif
  415. /**
  416. * @brief This is a configuration of augmentation in training time.
  417. * @details It is used as data augmentation setting parameter for Trainer classes.
  418. * @author ⓒSualab SuaKIT Team
  419. */
  420. struct AugmentationConfig {
  421. AugmentationConfig() : m_lrFlip(false), m_udFlip(false), m_rotation90(false), m_contrast(false), m_brightness(false),
  422. m_zoomIn(false), m_sharpen(false), m_blur(false), m_colorwise(false), m_gradation(false),
  423. m_distortion(false), m_rotation(false), m_noise(false),
  424. m_brightnessMin(-3), m_brightnessMax(+3),
  425. m_sharpenKernelMin(0.1), m_sharpenKernelMax(0.8),
  426. m_gaussianBlurSigmaMin(0.4), m_gaussianBlurSigmaMax(1.5),
  427. m_constrastMin(0.7), m_constrastMax(1.3),
  428. m_noiseIntensity(0.1),
  429. m_occlusion(false)
  430. {};
  431. /**
  432. * @brief This is a constructor of the AugmentationConfig structure.
  433. * @param lrFlip Input parameter for left/right flip data augmentation option.
  434. * @param udFlip Input parameter for up/down flip data augmentation option.
  435. * @param rotation90 Input parameter for rotate 90 degree data augmentation option.
  436. * @param contrast Input parameter for contrast variation data augmentation option.
  437. * @param brightness Input parameter for brightness data augmentation option.
  438. * @param zoomIn Input parameter for zoomIn(cropping and resizing) data augmentation option.
  439. * @param sharpen Input parameter for sharpness data augmentation option.
  440. * @param blur Input parameter for blur(gaussian) data augmentation option.
  441. * @param colorwise Input parameter for colorwise data augmentation option.
  442. * @param gradation Input parameter for gradation data augmentation option.
  443. * @param distortion Input parameter for distortion data augmentation option.
  444. * @param rotation Input parameter for rotate random (0-45] degree data augmentation option.
  445. * @param noise Input parameter for noise data augmentation option.
  446. * @param brightnessMin Input parameter for brightness parameter min value. Recommended min value is -3
  447. * @param brightnessMax Input parameter for brightness parameter max value. Recommended min value is +3
  448. * @param sharpenKernelMin Input parameter for sharpen kernel parameter min value. Recommended min value is 0.1
  449. * @param sharpenKernelMax Input parameter for sharpen kernel parameter max value. Recommended min value is 0.8
  450. * @param gaussianBlurKernelMin Input parameter for gaussian kernel parameter min value. Recommended min value is 0.4
  451. * @param gaussianBlurKernelMax Input parameter for gaussian kernel parameter max value. Recommended min value is 1.5
  452. * @param contrastMin Input parameter for noise contrast parameter max value. Recommended min value is 0.7
  453. * @param contrastMax Input parameter for noise contrast parameter max value. Recommended min value is 1.3
  454. * @param noiseIntensity Input parameter for noise augmentation parameter max value. Recommended min value is 0.1
  455. * @param occlusion Input parameter for occlusion data augmentation option.
  456. */
  457. AugmentationConfig(
  458. bool lrFlip, bool udFlip, bool rotation90, bool contrast, bool brightness,
  459. bool zoomIn, bool sharpen, bool blur, bool colorwise, bool gradation,
  460. bool distortion, bool rotation, bool noise, int brightnessMin = -3, int brightnessMax = 3, double sharpenKernelMin = 0.1, double sharpenKernelMax = 0.8,
  461. double gaussianBlurKernelMin = 0.4, double gaussianBlurKernelMax = 1.5,
  462. double contrastMin = 0.7, double contrastMax = 1.3,
  463. double noiseIntensity = 0.1,
  464. bool occlusion = false)
  465. : m_lrFlip(lrFlip), m_udFlip(udFlip), m_rotation90(rotation90), m_contrast(contrast), m_brightness(brightness),
  466. m_zoomIn(zoomIn), m_sharpen(sharpen), m_blur(blur), m_colorwise(colorwise), m_gradation(gradation),
  467. m_distortion(distortion), m_rotation(rotation), m_noise(noise),
  468. m_brightnessMin(brightnessMin), m_brightnessMax(brightnessMax),
  469. m_sharpenKernelMin(sharpenKernelMin), m_sharpenKernelMax(sharpenKernelMax),
  470. m_gaussianBlurSigmaMin(gaussianBlurKernelMin), m_gaussianBlurSigmaMax(gaussianBlurKernelMax),
  471. m_constrastMin(contrastMin), m_constrastMax(contrastMax),
  472. m_noiseIntensity(noiseIntensity),
  473. m_occlusion(occlusion)
  474. {};
  475. bool m_lrFlip, m_udFlip, m_rotation90, m_contrast, m_brightness, m_zoomIn, m_sharpen, m_blur;
  476. bool m_colorwise, m_gradation, m_distortion, m_rotation, m_noise, m_reserve1, m_reserve2, m_reserve3;
  477. int m_brightnessMin, m_brightnessMax;
  478. double m_sharpenKernelMin, m_sharpenKernelMax;
  479. double m_gaussianBlurSigmaMin, m_gaussianBlurSigmaMax;
  480. double m_constrastMin, m_constrastMax;
  481. double m_noiseIntensity;
  482. bool m_occlusion;
  483. };
  484. /**
  485. * @brief Wrapper for string messages.
  486. * @details
  487. * @author ⓒSualab SuaKIT Team
  488. */
  489. struct SUAKIT_API Message {
  490. /** @brief MessageType */
  491. enum MessageType {
  492. MSG_UNKNOWN = 0,
  493. MSG_GENERAL = 1,
  494. MSG_TRAIN_VALIDATIONLOSS = 2,
  495. MSG_TRAIN_MODELSAVE = 3,
  496. MSG_ERR = 4,
  497. };
  498. __stdcall Message();
  499. __stdcall Message(const wchar_t * data, SuaKIT_Int64 size, MessageType msgt);
  500. __stdcall ~Message();
  501. /**
  502. * @brief Returns the message string. The corresponding string buffer space is destroyed when this object is destroyed.
  503. * In the C ++ API, this method returns the c style wide character string type.
  504. */
  505. const wchar_t* GetData() const { return m_data; }
  506. /** @brief Returns the length of a string containing null characters.*/
  507. SuaKIT_Int64 GetSize() const { return m_size; };
  508. /** @brief
  509. Returns the MessageType value of the current object.
  510. */
  511. MessageType GetMsgType() const { return m_msgtype; }
  512. /** @brief
  513. If this object is a message of type MSG_TRAIN_MODELSAVE, the file path setting of the training result is returned.
  514. This function returns the value normally only when the return value of GetMsgType () is MSG_TRAIN_MODELSAVE.
  515. */
  516. const wchar_t* __stdcall GetModelFilePath();
  517. /** @brief
  518. If this object is a message of MSG_TRAIN_VALIDATIONLOSS type, it outputs the current validation result information to the variable passed as a reference argument.
  519. This function works normally only when the return value of GetMsgType() is MSG_TRAIN_VALIDATIONLOSS.
  520. * @param minLoss The minimum value of the loss values ​​measured so far
  521. * @param minIteration Iteration value when the minimum value of the loss value is measured
  522. * @param recentLoss The most recently measured loss value
  523. * @param recentIteration Iteration value when measuring the most recently measured loss value
  524. */
  525. void __stdcall GetValidationInfo(float& minLoss, SuaKIT_Int32& minIteration, float& recentLoss, SuaKIT_Int32& recentIteration);
  526. __stdcall Message(const Message& src);
  527. Message& __stdcall operator=(const Message& rhs);
  528. private:
  529. wchar_t * m_data;
  530. SuaKIT_Int64 m_size;
  531. wchar_t * m_dataEx;
  532. SuaKIT_Int64 m_sizeEx;
  533. MessageType m_msgtype;
  534. };
  535. /**
  536. * @brief Structure containing model information of trained model.
  537. * @details Each parameters are the same as TrainConfig parameters.
  538. * @author ⓒSualab SuaKIT Team
  539. */
  540. struct SUAKIT_API TrainedModelInfo
  541. {
  542. AugmentationConfig augmentationConfig; /**< Augmentation parameters set at training.*/
  543. Int32Array dataRatio; /**< The dataRatio value set in the TrainConfig object at the training. See the dataRatio description in each TrainConfig for details.*/
  544. FloatArray epochForLossGraph; /**< Epoch values ​​for the Loss graph. The loss value corresponding to each epoch is stored in the same position in lossForLossGraph.*/
  545. FloatArray lossForLossGraph; /**< The loss value of the loss graph. The epoch values ​​for each loss are stored in the same location in epochForLossGraph.*/
  546. FloatArray anchors; /**< The anchors value set in the DetectionTrainConfig object at the training.This value is valid only on the Detection model.See the anchors description in DetectionTrainConfig for details.*/
  547. float minimumEpoch; /**< The minimumEpoch value set in the TrainConfig object at the training. See the minimumEpoch description in each TrainConfig for details.*/
  548. float savedModelEpoch; /**< The training epoch value at the time the current model is saved.*/
  549. float minLoss; /**< The minimum loss value in the training period of the current model*/
  550. float endEpoch; /**< Epoch at the end of training.*/
  551. SuaKIT_UInt64 multiImgCount; /**< The multiImgCount value set in the TrainConfig object at the training. See the multiImgCount description in each TrainConfig for details.*/
  552. SuaKIT_UInt64 numberOfClasses; /**< The numberOfClasses value set in the TrainConfig object at the training. See the numberOfClasses description in each TrainConfig for details.*/
  553. SuaKIT_UInt64 imageHeight; /**< The imageHeight value set in the TrainConfig object at the training. In the case of segmentation, it indicates the patch size. See the imageHeight or patchSize description in each TrainConfig for details.*/
  554. SuaKIT_UInt64 imageWidth; /**< The imageWidth value set in the TrainConfig object at the training. In the case of segmentation, it indicates the patch size. See the imageWidth or patchSize description in each TrainConfig for details.*/
  555. SuaKIT_UInt64 imageChannel; /**< The imageChannel value set in the TrainConfig object at the training. See the imageChannel description in each TrainConfig for details.*/
  556. SuaKIT_UInt64 validationRatio; /**< The validationRatio value set in the TrainConfig object at the training. See the validationRatio description in each TrainConfig for details.*/
  557. SuaKIT_UInt64 epochs; /**< The epochs value set in the TrainConfig object at the training. See the epochs description in each TrainConfig for details.*/
  558. SuaKIT_UInt64 modelCapacity; /**< The modelCapacity value set in the TrainConfig object at the training. See the modelCapacity description in each TrainConfig for details.*/
  559. SuaKIT_UInt64 numModelSelection; /**< The numModelSelection value set in the TrainConfig object at the training. See the numModelSelection description in each TrainConfig for details.*/
  560. SuaKIT_UInt64 patchSize; /**< The patchSize value set in the SegmentationTrainConfig object at the training. See the patchSize description in SegmentationTrainConfig for details. This value is only valid for the segmentation model.*/
  561. SuaKIT_UInt64 strideRatio; /**< The strideRatio value set in the TrainConfig object at the training. See the strideRatio description in each TrainConfig for details.*/
  562. SuaKIT_UInt64 unlabeledRatio; /**< The unlabeledRatio value set in the SegmentationTrainConfig object at the training. See the unlabeledRatio description in SegmentationTrainConfig for details. This value is only valid for the segmentation model.*/
  563. SuaKIT_UInt64 numTrainImage; /**< Number of images used in the training set.*/
  564. SuaKIT_UInt64 numValidationImage; /**< Number of images used in the validation set.*/
  565. SuaKIT_Int64 patience; /**< The patience value set in the TrainConfig object at the training. See the patience description in each TrainConfig for details.*/
  566. static const uchar BUFF_SIZE = 32;
  567. char trainElapsedTime[BUFF_SIZE]; /**< A time value string that indicates how long the training has been. "dd, hh:mm:ss" format*/
  568. char modelSavedTime[BUFF_SIZE]; /**< Indicates the time the model finished training and saved as a file. "mm-dd-yyyy hh:mm" format*/
  569. char modelVersion[BUFF_SIZE]; /**< Indicates the SuaKIT version from which the current model was trained.*/
  570. ModelType modelType; /**< Represents the ModelType of the current model. See ModelType description for details.*/
  571. InputDataType inputDataType; /**< The inputDataType value set in the TrainConfig object at the training. See the inputDataType description in each TrainConfig for details.*/
  572. DepthType imageDepth; /**< The imageDepth value set in the TrainConfig object at the training. See the imageDepth description in each TrainConfig for details.*/
  573. };
  574. /**
  575. * @brief Structure containing version of SuaKIT.
  576. * @author ⓒSualab SuaKIT Team
  577. */
  578. struct SUAKIT_API SuaKIT_Version {
  579. SuaKIT_Int32 majorVersion;
  580. SuaKIT_Int32 minorVersion;
  581. SuaKIT_Int32 patchVersion;
  582. SuaKIT_Int32 buildNumber;
  583. };
  584. /**
  585. * @brief Class containing several unit functions.
  586. * @details All members are static method.
  587. * @author ⓒSualab SuaKIT Team
  588. */
  589. class SUAKIT_API UnitFunction {
  590. public:
  591. /** @brief If the result status value of the SuaKIT API is not SUCCESS, it returns a message about the cause of the error. */
  592. static const char* __stdcall GetErrorMessage();
  593. /** @brief Resizes the image.
  594. *
  595. * This function resizes the internal image data of \p src and stores the result in \p dst.
  596. * The channel and depth values are not changed by this function, whereas the step value may change.
  597. * If there are more than one image in this ImageData, every image is resized.
  598. * Below is an example code describing how to use this function.
  599. *
  600. * @code
  601. * ImageData src(L"path/to/256x256/image", Rect(), 1); // Load 256x256 1-channel image
  602. * ImageData dst(128, 128, 512, 1); // An empty 128x512 1-channel image
  603. * ResizeImage(src, dst); // Resizes src to 128x512
  604. * @endcode
  605. *
  606. * @note If roi was set on the \p src image data, the roi is also resized on the \p dst,
  607. * and the resize ratio is proportional to the image resize ratio. For example,
  608. * if an 128x128 image had roi set with (x=0, y=0, width=64, height=64) and the image is resized
  609. * to 256x256, the roi of the resized image becomes (x=0, y=0, width=128, height=128).
  610. *
  611. * @param src Original image data.
  612. * @param dst Resized image data.
  613. *
  614. * @author ⓒSualab SuaKIT Team
  615. */
  616. static Status __stdcall ResizeImage(const ImageData& src, ImageData& dst);
  617. /** @brief Resize the image size.
  618. * @param src Original image data.
  619. * @param dst Resized image. When you input an empty imageData object, the resized image is saved to the object. If it is not a empty imageData object, the existing image data object is destroyed then replaced with the resized image.
  620. * @param width Size of resized Image width
  621. * @param height Size of resized Image height
  622. */
  623. static Status __stdcall ResizeImage(const ImageData& src, ImageData& dst, SuaKIT_UInt64 width, SuaKIT_UInt64 height);
  624. /** @brief Crop the image.
  625. * @param src Original image data.
  626. * @param dst Cropped image. When you input an empty imageData object, the cropped image is saved to the object. If it is not a empty imageData object, the existing image data object is destroyed then replaced with the cropped image.
  627. * @param roi area to crop
  628. */
  629. static Status __stdcall CropImage(const ImageData& src, ImageData& dst, Rect roi);
  630. /** @brief Undocumented function*/
  631. static Status GetFrequencyDistribution(const FloatArray& inputArr, SuaKIT_UInt64 classN, float minVal, float maxVal, SuaKIT_UInt64 ranks, Int64Array& resultFreqDist);
  632. /** @brief Undocumented function*/
  633. static Status GetMaxScore(const FloatArray & inputArr, const SuaKIT_UInt64 classN, const SuaKIT_UInt64 totalClassN, Int64Array& resultMaxScore);
  634. /** @brief Undocumented function*/
  635. static Status __stdcall TurnOnLogger();
  636. /** @brief Undocumented function*/
  637. static Status __stdcall TurnOnConsoleLogger();
  638. /** @brief Undocumented function*/
  639. static Status __stdcall SuaKIT_ExtraFacilitiesInit();
  640. /** @brief Undocumented function*/
  641. static Status __stdcall isImportableModel(ModelType modelType, SuaKIT_Int32 imgCnt, SuaKIT_Int32 numberOfClasses, const wchar_t *modelPath);
  642. /**
  643. * @brief Returns the version of SuaKIT.
  644. * @author ⓒSualab SuaKIT Team
  645. */
  646. static SuaKIT_Version __stdcall SuaKIT_GetVersion();
  647. /**
  648. * @brief Get the information of trained model.
  649. * @param trainedModelInfo Information of trained model.
  650. * @param modelPath The trained model path for executing GetTrainedModelInfo.
  651. * @return Returns Status.
  652. * @author ⓒSualab SuaKIT Team
  653. */
  654. static Status __stdcall GetTrainedModelInfo(TrainedModelInfo& trainedModelInfo, const wchar_t* modelPath);
  655. /**
  656. * @brief Get the information of trained model.
  657. * @param modelPath The trained model path
  658. * @return Message objects holding class names. You can get the wchar_t pointer of the string of the class names using Getdata method of returned object.
  659. The string is a json list. Each entry in the json list represents the name of the class and is represented sequentially from class 0.
  660. * @code Message msg = UnitFunction::GetAllClassNames(L"./model.net");
  661. const wchar_t* wstr = msg.Getdata();
  662. std::wstring classNames(wstr); // ["className1","className2","className3"] json list format
  663. @endcode
  664. * @author ⓒSualab SuaKIT Team
  665. */
  666. static Message __stdcall GetAllClassNames(const wchar_t* modelPath);
  667. /**
  668. * @brief Get the maximum image size information
  669. * @param gpuFreeMemSize GPU free memory size returned by GetGpuFreeMemorySize() API.
  670. * @param modelType This parameter is used to configure model type. Set it to one of {ModelType::CLASSIFICATION, ModelType::DETECTION, ModelType::DETECTION_DRAGON, ModelType::DETECTION_DOLPHIN, }
  671. * @param inputDataType This parameter is used to configure input type of neural network. For now, just set it to ModelType::CLASSIFICATION.
  672. * @param imgCnt The number of images for Evaluator, depends on inputDataType parameter.
  673. - In case of InputDataType::SINGLE, multiImgCount parameter needs to initialized with 1.
  674. - In case of InputDataType::COMPARISON, multiImgCount parameter needs to initialized with 2.
  675. - In case of InputDataType::MULTIMG, multiImgCount parameter needs to initialized with imageNum >= 2.
  676. * @param numClass The number of classes to train.
  677. * @param modelCapacity The base (pre-defined) model capacity for executing ClassificationTrainer. {0, 1, 2, 3}.
  678. - 0 means small model capacity.
  679. - 1 means normal model capacity.
  680. - 2 means large model capacity.
  681. - 3 means extra large model capacity.
  682. * @param widthHeightRatio The ratio of width to height of images in train set. It affects the return value width and height.
  683. * @param width It returns the width of the maximum network size.
  684. * @param height It returns the height of the maximum network size.
  685. * @return Returns Status.
  686. * @code .
  687. * @endcode
  688. * @author ⓒSualab SuaKIT Team
  689. */
  690. static Status __stdcall GetMaxNetworkSize(SuaKIT_UInt64 gpuFreeMemSize, ModelType modelType, InputDataType inputDataType, SuaKIT_Int32 imgCnt, SuaKIT_Int32 numClass, SuaKIT_Int32 modelCapacity, float widthHeightRatio, SuaKIT_Int32& width, SuaKIT_Int32& height);
  691. /**
  692. * @brief Get free memory size in byte of a GPU
  693. * @param devDesc Specifies the device on which the trainer will operate.
  694. * @param gpuFreeMemSize It returns the free GPU memory size of the GPU specified by devDesc in bytes.
  695. * @return Returns Status.
  696. * @code .
  697. * @endcode
  698. * @author ⓒSualab SuaKIT Team
  699. */
  700. static Status __stdcall GetGpuFreeMemorySize(DeviceDescriptor devDesc, SuaKIT_UInt64& gpuFreeMemSize);
  701. /**
  702. * @brief You can check whether this model is possible to continue training or not.
  703. * @param modelType Model type for continue training mode.
  704. Currently, ModelType::CLASSIFICATION is supported only.
  705. * @param imgCnt The number of images for continue training mode, depends on inputDataType.
  706. - In case of InputDataType::SINGLE, imgCnt parameter needs to be initialized with 1.
  707. - In case of InputDataType::COMPARISON, imgCnt parameter needs to be initialized with 2.
  708. - In case of InputDataType::MULTIMG, imgCnt parameter needs to be initialized with imgCnt >= 2.
  709. * @param numberOfClasses The number of classes to continue training mode.
  710. * @param modelPath The trained model path for executing isContinueTrainableBaseModel.
  711. * @return Returns Status.
  712. * @author ⓒSualab SuaKIT Team
  713. */
  714. static Status __stdcall isContinueTrainableBaseModel(ModelType modelType, SuaKIT_Int32 imgCnt, SuaKIT_Int32 numberOfClasses, const wchar_t *modelPath);
  715. private:
  716. UnitFunction();
  717. UnitFunction(const UnitFunction & src);
  718. UnitFunction& operator=(const UnitFunction& rhs);
  719. };
  720. /**
  721. * @brief This class manages the information for the device to be used by the SuaKIT engine. The static functions return information regarding the usable devices on the PC, and each object is allocated one device.
  722. * @details
  723. * @author ⓒSualab SuaKIT Team
  724. */
  725. class SUAKIT_API DeviceDescriptor {
  726. public:
  727. DeviceDescriptor();
  728. /**
  729. * @brief Allocates a specific device to an object.
  730. * @param deviceId Input for the ID index integer for the device to be allocated to the object.
  731. * @param deviceKind Input for the type of device to be allocated to the object.
  732. */
  733. DeviceDescriptor(SuaKIT_UInt64 deviceId, DeviceKind deviceKind);
  734. /** @brief Returns the CPU DeviceDescriptor.*/
  735. static DeviceDescriptor __stdcall GetCPUDevice();
  736. /** @brief Put all GPU Descriptors in the devDescArray argument.*/
  737. static Status __stdcall GetAllGPUDevices(DeviceDescriptorArray& devDescArray);
  738. /** @brief Put Available GPU Descriptors in the devDescArray argument.*/
  739. static Status __stdcall GetAvailableGPUDevices(DeviceDescriptorArray& devDescArray);
  740. /** @brief Returns the Default DeviceDescriptor.*/
  741. static DeviceDescriptor __stdcall GetDefaultDevice();
  742. /** @brief Returns the Device name.*/
  743. Message __stdcall GetDeviceName() const;
  744. /** @brief Undocumented function*/
  745. bool __stdcall isLocked();
  746. /** @brief Returns the device id integer for the current object.*/
  747. SuaKIT_UInt64 GetDeviceId() const;
  748. /** @brief Returns the device type for the current object.*/
  749. DeviceKind GetDeviceKind() const;
  750. /** @brief Returns the device type for the current object in string.*/
  751. Message __stdcall GetDeviceKindStr() const;
  752. /**
  753. * @brief Returns the amount of free GPU memory in bytes.
  754. *
  755. * This function is useful only when the device is SuaKIT::API::DeviceKind_GPU.
  756. *
  757. * @return The amount of free memory on this device in bytes.
  758. * Returns 0 if the device is not SuaKIT::API::DeviceKind_GPU.
  759. */
  760. SuaKIT_UInt64 GetFreeGpuMem() const;
  761. private:
  762. SuaKIT_UInt64 m_deviceId;
  763. DeviceKind m_deviceKind;
  764. };
  765. /**
  766. * @brief Undocumented class.
  767. * @author ⓒSualab SuaKIT Team
  768. */
  769. class SUAKIT_API Internal {
  770. public:
  771. /** @brief Undocumented function*/
  772. static void* __stdcall SuaKIT_Malloc(SuaKIT_UInt64 byteSize);
  773. /** @brief Undocumented function*/
  774. static void __stdcall SuaKIT_Free(void* m_startp);
  775. private:
  776. Internal();
  777. Internal(const Internal & src);
  778. Internal& operator=(const Internal& rhs);
  779. };
  780. /**
  781. * @brief Classes for kmeans calculations. It is used to determine the value of an anchor box in DetectionTrainConfig based on training data.
  782. * @details
  783. * @author ⓒSualab SuaKIT Team
  784. */
  785. class SUAKIT_API kmeans2d {
  786. public:
  787. enum ResultOpt{
  788. NON = 0,
  789. CLUSTOR_PRIOR = 1, /**< Set cluster value alignment to cluster priority ex: (X1,Y1), (X2,Y2), (X3,Y3) */
  790. DIM_PRIOR = 2 /**< Set cluster value alignment to dimension priority ex: (X1,X2,X3), (Y1,Y2,Y3)*/
  791. };
  792. __stdcall kmeans2d();
  793. __stdcall ~kmeans2d();
  794. SuaKIT_UInt64 __stdcall GetItemLength() const;
  795. /** @brief Input data for kmeans */
  796. void __stdcall Push2dItem(const float x, const float y);
  797. /** @brief Run kmeans calculations. The center coordinates of the clusters are returned in resultCenters.*/
  798. Status __stdcall CalcKmeans(const SuaKIT_UInt64 clusterCnt, FloatArray& resultCenters, ResultOpt resOpt = ResultOpt::NON);
  799. private:
  800. kmeans2d(const kmeans2d & src); //=delete;
  801. kmeans2d& operator=(const kmeans2d& rhs); //=delete;
  802. void *internal;
  803. };
  804. template<typename VAL_TYPE>
  805. inline DataArray<VAL_TYPE>::DataArray(SuaKIT_UInt64 size)
  806. {
  807. m_startp = Internal::SuaKIT_Malloc(size * sizeof(VAL_TYPE));
  808. m_byteSize = size * sizeof(VAL_TYPE);
  809. m_capacity = size * sizeof(VAL_TYPE);
  810. }
  811. template<typename VAL_TYPE>
  812. inline DataArray<VAL_TYPE>::~DataArray()
  813. {
  814. Internal::SuaKIT_Free(m_startp);
  815. }
  816. template<typename VAL_TYPE>
  817. inline const VAL_TYPE & DataArray<VAL_TYPE>::GetAt(SuaKIT_UInt64 idx) const
  818. {
  819. return (reinterpret_cast<VAL_TYPE*>(m_startp))[idx];
  820. }
  821. template<typename VAL_TYPE>
  822. inline VAL_TYPE DataArray<VAL_TYPE>::GetValue(SuaKIT_UInt64 idx) const
  823. {
  824. return (reinterpret_cast<VAL_TYPE*>(m_startp))[idx];
  825. }
  826. template<typename VAL_TYPE>
  827. inline SuaKIT_UInt64 DataArray<VAL_TYPE>::GetByteSize() const
  828. {
  829. return m_byteSize;
  830. }
  831. template<typename VAL_TYPE>
  832. inline SuaKIT_UInt64 DataArray<VAL_TYPE>::GetLength() const
  833. {
  834. return m_byteSize / sizeof(VAL_TYPE);
  835. }
  836. template<typename VAL_TYPE>
  837. inline VAL_TYPE * DataArray<VAL_TYPE>::GetDataPtr()
  838. {
  839. return reinterpret_cast<VAL_TYPE*>(m_startp);
  840. }
  841. template<typename VAL_TYPE>
  842. inline const VAL_TYPE * DataArray<VAL_TYPE>::GetDataPtr() const
  843. {
  844. return reinterpret_cast<VAL_TYPE*>(m_startp);
  845. }
  846. template<typename VAL_TYPE>
  847. inline Status DataArray<VAL_TYPE>::SetAt(SuaKIT_UInt64 idx, const VAL_TYPE & item)
  848. {
  849. if (idx >= (m_byteSize / sizeof(VAL_TYPE)))
  850. return SuaKIT::API::Status::ERR_INPUT;
  851. (reinterpret_cast<VAL_TYPE*>(m_startp))[idx] = item;
  852. return SuaKIT::API::Status::SUCCESS;
  853. }
  854. inline DeviceDescriptor::DeviceDescriptor()
  855. : m_deviceId(0), m_deviceKind(DeviceKind::DeviceKind_NON)
  856. {
  857. }
  858. inline DeviceDescriptor::DeviceDescriptor(SuaKIT_UInt64 deviceId, DeviceKind deviceKind)
  859. : m_deviceId(deviceId), m_deviceKind(deviceKind)
  860. {
  861. }
  862. inline SuaKIT_UInt64 DeviceDescriptor::GetDeviceId() const
  863. {
  864. return m_deviceId;
  865. }
  866. inline DeviceKind DeviceDescriptor::GetDeviceKind() const
  867. {
  868. return m_deviceKind;
  869. }
  870. template<typename VAL_TYPE>
  871. inline void DataArray<VAL_TYPE>::_resize(SuaKIT_UInt64 size)
  872. {
  873. if (static_cast<SuaKIT_UInt64>(m_capacity) < (size * sizeof(VAL_TYPE))) {
  874. Internal::SuaKIT_Free(m_startp);
  875. m_startp = Internal::SuaKIT_Malloc(size * sizeof(VAL_TYPE));
  876. m_byteSize = size * sizeof(VAL_TYPE);
  877. m_capacity = m_byteSize;
  878. }
  879. m_byteSize = size * sizeof(VAL_TYPE);
  880. }
  881. }
  882. }