darknet.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. #ifndef DARKNET_API
  2. #define DARKNET_API
  3. #if defined(_MSC_VER) && _MSC_VER < 1900
  4. #define inline __inline
  5. #endif
  6. #if defined(DEBUG) && !defined(_CRTDBG_MAP_ALLOC)
  7. #define _CRTDBG_MAP_ALLOC
  8. #endif
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdint.h>
  13. #include <assert.h>
  14. #include <pthread.h>
  15. #ifndef LIB_API
  16. #ifdef LIB_EXPORTS
  17. #if defined(_MSC_VER)
  18. #define LIB_API __declspec(dllexport)
  19. #else
  20. #define LIB_API __attribute__((visibility("default")))
  21. #endif
  22. #else
  23. #if defined(_MSC_VER)
  24. #define LIB_API
  25. #else
  26. #define LIB_API
  27. #endif
  28. #endif
  29. #endif
  30. #define SECRET_NUM -1234
  31. #ifdef GPU
  32. #include <cuda_runtime.h>
  33. #include <curand.h>
  34. #include <cublas_v2.h>
  35. #ifdef CUDNN
  36. #include <cudnn.h>
  37. #endif
  38. #endif
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. struct network;
  43. typedef struct network network;
  44. struct network_state;
  45. typedef struct network_state network_state;
  46. struct layer;
  47. typedef struct layer layer;
  48. struct image;
  49. typedef struct image image;
  50. struct detection;
  51. typedef struct detection detection;
  52. struct load_args;
  53. typedef struct load_args load_args;
  54. struct data;
  55. typedef struct data data;
  56. struct metadata;
  57. typedef struct metadata metadata;
  58. struct tree;
  59. typedef struct tree tree;
  60. extern int gpu_index;
  61. // option_list.h
  62. typedef struct metadata {
  63. int classes;
  64. char **names;
  65. } metadata;
  66. // tree.h
  67. typedef struct tree {
  68. int *leaf;
  69. int n;
  70. int *parent;
  71. int *child;
  72. int *group;
  73. char **name;
  74. int groups;
  75. int *group_size;
  76. int *group_offset;
  77. } tree;
  78. // activations.h
  79. typedef enum {
  80. LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN, SELU, SWISH, MISH, NORM_CHAN, NORM_CHAN_SOFTMAX
  81. }ACTIVATION;
  82. // parser.h
  83. typedef enum {
  84. IOU, GIOU, MSE, DIOU, CIOU
  85. } IOU_LOSS;
  86. // parser.h
  87. typedef enum {
  88. DEFAULT_NMS, GREEDY_NMS, DIOU_NMS, CORNERS_NMS
  89. } NMS_KIND;
  90. // parser.h
  91. typedef enum {
  92. YOLO_CENTER = 1 << 0, YOLO_LEFT_TOP = 1 << 1, YOLO_RIGHT_BOTTOM = 1 << 2
  93. } YOLO_POINT;
  94. // parser.h
  95. typedef enum {
  96. NO_WEIGHTS, PER_FEATURE, PER_CHANNEL
  97. } WEIGHTS_TYPE_T;
  98. // parser.h
  99. typedef enum {
  100. NO_NORMALIZATION, RELU_NORMALIZATION, SOFTMAX_NORMALIZATION
  101. } WEIGHTS_NORMALIZATION_T;
  102. // image.h
  103. typedef enum{
  104. PNG, BMP, TGA, JPG
  105. } IMTYPE;
  106. // activations.h
  107. typedef enum{
  108. MULT, ADD, SUB, DIV
  109. } BINARY_ACTIVATION;
  110. // layer.h
  111. typedef enum {
  112. CONVOLUTIONAL,
  113. DECONVOLUTIONAL,
  114. CONNECTED,
  115. MAXPOOL,
  116. LOCAL_AVGPOOL,
  117. SOFTMAX,
  118. DETECTION,
  119. DROPOUT,
  120. CROP,
  121. ROUTE,
  122. COST,
  123. NORMALIZATION,
  124. AVGPOOL,
  125. LOCAL,
  126. SHORTCUT,
  127. SCALE_CHANNELS,
  128. SAM,
  129. ACTIVE,
  130. RNN,
  131. GRU,
  132. LSTM,
  133. CONV_LSTM,
  134. CRNN,
  135. BATCHNORM,
  136. NETWORK,
  137. XNOR,
  138. REGION,
  139. YOLO,
  140. GAUSSIAN_YOLO,
  141. ISEG,
  142. REORG,
  143. REORG_OLD,
  144. UPSAMPLE,
  145. LOGXENT,
  146. L2NORM,
  147. EMPTY,
  148. BLANK
  149. } LAYER_TYPE;
  150. // layer.h
  151. typedef enum{
  152. SSE, MASKED, L1, SEG, SMOOTH,WGAN
  153. } COST_TYPE;
  154. // layer.h
  155. typedef struct update_args {
  156. int batch;
  157. float learning_rate;
  158. float momentum;
  159. float decay;
  160. int adam;
  161. float B1;
  162. float B2;
  163. float eps;
  164. int t;
  165. } update_args;
  166. // layer.h
  167. struct layer {
  168. LAYER_TYPE type;
  169. ACTIVATION activation;
  170. COST_TYPE cost_type;
  171. void(*forward) (struct layer, struct network_state);
  172. void(*backward) (struct layer, struct network_state);
  173. void(*update) (struct layer, int, float, float, float);
  174. void(*forward_gpu) (struct layer, struct network_state);
  175. void(*backward_gpu) (struct layer, struct network_state);
  176. void(*update_gpu) (struct layer, int, float, float, float);
  177. layer *share_layer;
  178. int train;
  179. int avgpool;
  180. int batch_normalize;
  181. int shortcut;
  182. int batch;
  183. int forced;
  184. int flipped;
  185. int inputs;
  186. int outputs;
  187. int nweights;
  188. int nbiases;
  189. int extra;
  190. int truths;
  191. int h, w, c;
  192. int out_h, out_w, out_c;
  193. int n;
  194. int max_boxes;
  195. int groups;
  196. int group_id;
  197. int size;
  198. int side;
  199. int stride;
  200. int stride_x;
  201. int stride_y;
  202. int dilation;
  203. int antialiasing;
  204. int maxpool_depth;
  205. int out_channels;
  206. int reverse;
  207. int flatten;
  208. int spatial;
  209. int pad;
  210. int sqrt;
  211. int flip;
  212. int index;
  213. int scale_wh;
  214. int binary;
  215. int xnor;
  216. int peephole;
  217. int use_bin_output;
  218. int keep_delta_gpu;
  219. int optimized_memory;
  220. int steps;
  221. int state_constrain;
  222. int hidden;
  223. int truth;
  224. float smooth;
  225. float dot;
  226. int deform;
  227. int sway;
  228. int rotate;
  229. int stretch;
  230. int stretch_sway;
  231. float angle;
  232. float jitter;
  233. float saturation;
  234. float exposure;
  235. float shift;
  236. float ratio;
  237. float learning_rate_scale;
  238. float clip;
  239. int focal_loss;
  240. float *classes_multipliers;
  241. float label_smooth_eps;
  242. int noloss;
  243. int softmax;
  244. int classes;
  245. int coords;
  246. int background;
  247. int rescore;
  248. int objectness;
  249. int does_cost;
  250. int joint;
  251. int noadjust;
  252. int reorg;
  253. int log;
  254. int tanh;
  255. int *mask;
  256. int total;
  257. float bflops;
  258. int adam;
  259. float B1;
  260. float B2;
  261. float eps;
  262. int t;
  263. float alpha;
  264. float beta;
  265. float kappa;
  266. float coord_scale;
  267. float object_scale;
  268. float noobject_scale;
  269. float mask_scale;
  270. float class_scale;
  271. int bias_match;
  272. float random;
  273. float ignore_thresh;
  274. float truth_thresh;
  275. float iou_thresh;
  276. float thresh;
  277. float focus;
  278. int classfix;
  279. int absolute;
  280. int assisted_excitation;
  281. int onlyforward;
  282. int stopbackward;
  283. int dontload;
  284. int dontsave;
  285. int dontloadscales;
  286. int numload;
  287. float temperature;
  288. float probability;
  289. float dropblock_size_rel;
  290. int dropblock_size_abs;
  291. int dropblock;
  292. float scale;
  293. char * cweights;
  294. int * indexes;
  295. int * input_layers;
  296. int * input_sizes;
  297. float **layers_output;
  298. float **layers_delta;
  299. WEIGHTS_TYPE_T weights_type;
  300. WEIGHTS_NORMALIZATION_T weights_normalizion;
  301. int * map;
  302. int * counts;
  303. float ** sums;
  304. float * rand;
  305. float * cost;
  306. float * state;
  307. float * prev_state;
  308. float * forgot_state;
  309. float * forgot_delta;
  310. float * state_delta;
  311. float * combine_cpu;
  312. float * combine_delta_cpu;
  313. float *concat;
  314. float *concat_delta;
  315. float *binary_weights;
  316. float *biases;
  317. float *bias_updates;
  318. float *scales;
  319. float *scale_updates;
  320. float *weights;
  321. float *weight_updates;
  322. float scale_x_y;
  323. float uc_normalizer;
  324. float iou_normalizer;
  325. float cls_normalizer;
  326. IOU_LOSS iou_loss;
  327. NMS_KIND nms_kind;
  328. float beta_nms;
  329. YOLO_POINT yolo_point;
  330. char *align_bit_weights_gpu;
  331. float *mean_arr_gpu;
  332. float *align_workspace_gpu;
  333. float *transposed_align_workspace_gpu;
  334. int align_workspace_size;
  335. char *align_bit_weights;
  336. float *mean_arr;
  337. int align_bit_weights_size;
  338. int lda_align;
  339. int new_lda;
  340. int bit_align;
  341. float *col_image;
  342. float * delta;
  343. float * output;
  344. float * activation_input;
  345. int delta_pinned;
  346. int output_pinned;
  347. float * loss;
  348. float * squared;
  349. float * norms;
  350. float * spatial_mean;
  351. float * mean;
  352. float * variance;
  353. float * mean_delta;
  354. float * variance_delta;
  355. float * rolling_mean;
  356. float * rolling_variance;
  357. float * x;
  358. float * x_norm;
  359. float * m;
  360. float * v;
  361. float * bias_m;
  362. float * bias_v;
  363. float * scale_m;
  364. float * scale_v;
  365. float *z_cpu;
  366. float *r_cpu;
  367. float *h_cpu;
  368. float *stored_h_cpu;
  369. float * prev_state_cpu;
  370. float *temp_cpu;
  371. float *temp2_cpu;
  372. float *temp3_cpu;
  373. float *dh_cpu;
  374. float *hh_cpu;
  375. float *prev_cell_cpu;
  376. float *cell_cpu;
  377. float *f_cpu;
  378. float *i_cpu;
  379. float *g_cpu;
  380. float *o_cpu;
  381. float *c_cpu;
  382. float *stored_c_cpu;
  383. float *dc_cpu;
  384. float *binary_input;
  385. uint32_t *bin_re_packed_input;
  386. char *t_bit_input;
  387. struct layer *input_layer;
  388. struct layer *self_layer;
  389. struct layer *output_layer;
  390. struct layer *reset_layer;
  391. struct layer *update_layer;
  392. struct layer *state_layer;
  393. struct layer *input_gate_layer;
  394. struct layer *state_gate_layer;
  395. struct layer *input_save_layer;
  396. struct layer *state_save_layer;
  397. struct layer *input_state_layer;
  398. struct layer *state_state_layer;
  399. struct layer *input_z_layer;
  400. struct layer *state_z_layer;
  401. struct layer *input_r_layer;
  402. struct layer *state_r_layer;
  403. struct layer *input_h_layer;
  404. struct layer *state_h_layer;
  405. struct layer *wz;
  406. struct layer *uz;
  407. struct layer *wr;
  408. struct layer *ur;
  409. struct layer *wh;
  410. struct layer *uh;
  411. struct layer *uo;
  412. struct layer *wo;
  413. struct layer *vo;
  414. struct layer *uf;
  415. struct layer *wf;
  416. struct layer *vf;
  417. struct layer *ui;
  418. struct layer *wi;
  419. struct layer *vi;
  420. struct layer *ug;
  421. struct layer *wg;
  422. tree *softmax_tree;
  423. size_t workspace_size;
  424. #ifdef GPU
  425. int *indexes_gpu;
  426. float *z_gpu;
  427. float *r_gpu;
  428. float *h_gpu;
  429. float *stored_h_gpu;
  430. float *temp_gpu;
  431. float *temp2_gpu;
  432. float *temp3_gpu;
  433. float *dh_gpu;
  434. float *hh_gpu;
  435. float *prev_cell_gpu;
  436. float *prev_state_gpu;
  437. float *last_prev_state_gpu;
  438. float *last_prev_cell_gpu;
  439. float *cell_gpu;
  440. float *f_gpu;
  441. float *i_gpu;
  442. float *g_gpu;
  443. float *o_gpu;
  444. float *c_gpu;
  445. float *stored_c_gpu;
  446. float *dc_gpu;
  447. // adam
  448. float *m_gpu;
  449. float *v_gpu;
  450. float *bias_m_gpu;
  451. float *scale_m_gpu;
  452. float *bias_v_gpu;
  453. float *scale_v_gpu;
  454. float * combine_gpu;
  455. float * combine_delta_gpu;
  456. float * forgot_state_gpu;
  457. float * forgot_delta_gpu;
  458. float * state_gpu;
  459. float * state_delta_gpu;
  460. float * gate_gpu;
  461. float * gate_delta_gpu;
  462. float * save_gpu;
  463. float * save_delta_gpu;
  464. float * concat_gpu;
  465. float * concat_delta_gpu;
  466. float *binary_input_gpu;
  467. float *binary_weights_gpu;
  468. float *bin_conv_shortcut_in_gpu;
  469. float *bin_conv_shortcut_out_gpu;
  470. float * mean_gpu;
  471. float * variance_gpu;
  472. float * rolling_mean_gpu;
  473. float * rolling_variance_gpu;
  474. float * variance_delta_gpu;
  475. float * mean_delta_gpu;
  476. float * col_image_gpu;
  477. float * x_gpu;
  478. float * x_norm_gpu;
  479. float * weights_gpu;
  480. float * weight_updates_gpu;
  481. float * weight_deform_gpu;
  482. float * weight_change_gpu;
  483. float * weights_gpu16;
  484. float * weight_updates_gpu16;
  485. float * biases_gpu;
  486. float * bias_updates_gpu;
  487. float * bias_change_gpu;
  488. float * scales_gpu;
  489. float * scale_updates_gpu;
  490. float * scale_change_gpu;
  491. float * input_antialiasing_gpu;
  492. float * output_gpu;
  493. float * activation_input_gpu;
  494. float * loss_gpu;
  495. float * delta_gpu;
  496. float * rand_gpu;
  497. float * squared_gpu;
  498. float * norms_gpu;
  499. float *gt_gpu;
  500. float *a_avg_gpu;
  501. int *input_sizes_gpu;
  502. float **layers_output_gpu;
  503. float **layers_delta_gpu;
  504. #ifdef CUDNN
  505. cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc;
  506. cudnnTensorDescriptor_t srcTensorDesc16, dstTensorDesc16;
  507. cudnnTensorDescriptor_t dsrcTensorDesc, ddstTensorDesc;
  508. cudnnTensorDescriptor_t dsrcTensorDesc16, ddstTensorDesc16;
  509. cudnnTensorDescriptor_t normTensorDesc, normDstTensorDesc, normDstTensorDescF16;
  510. cudnnFilterDescriptor_t weightDesc, weightDesc16;
  511. cudnnFilterDescriptor_t dweightDesc, dweightDesc16;
  512. cudnnConvolutionDescriptor_t convDesc;
  513. cudnnConvolutionFwdAlgo_t fw_algo, fw_algo16;
  514. cudnnConvolutionBwdDataAlgo_t bd_algo, bd_algo16;
  515. cudnnConvolutionBwdFilterAlgo_t bf_algo, bf_algo16;
  516. cudnnPoolingDescriptor_t poolingDesc;
  517. #endif // CUDNN
  518. #endif // GPU
  519. };
  520. // network.h
  521. typedef enum {
  522. CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM, SGDR
  523. } learning_rate_policy;
  524. // network.h
  525. typedef struct network {
  526. int n;
  527. int batch;
  528. uint64_t *seen;
  529. int *t;
  530. float epoch;
  531. int subdivisions;
  532. layer *layers;
  533. float *output;
  534. learning_rate_policy policy;
  535. int benchmark_layers;
  536. float learning_rate;
  537. float learning_rate_min;
  538. float learning_rate_max;
  539. int batches_per_cycle;
  540. int batches_cycle_mult;
  541. float momentum;
  542. float decay;
  543. float gamma;
  544. float scale;
  545. float power;
  546. int time_steps;
  547. int step;
  548. int max_batches;
  549. int num_boxes;
  550. int train_images_num;
  551. float *seq_scales;
  552. float *scales;
  553. int *steps;
  554. int num_steps;
  555. int burn_in;
  556. int cudnn_half;
  557. int adam;
  558. float B1;
  559. float B2;
  560. float eps;
  561. int inputs;
  562. int outputs;
  563. int truths;
  564. int notruth;
  565. int h, w, c;
  566. int max_crop;
  567. int min_crop;
  568. float max_ratio;
  569. float min_ratio;
  570. int center;
  571. int flip; // horizontal flip 50% probability augmentaiont for classifier training (default = 1)
  572. int blur;
  573. int mixup;
  574. float label_smooth_eps;
  575. int resize_step;
  576. int letter_box;
  577. float angle;
  578. float aspect;
  579. float exposure;
  580. float saturation;
  581. float hue;
  582. int random;
  583. int track;
  584. int augment_speed;
  585. int sequential_subdivisions;
  586. int init_sequential_subdivisions;
  587. int current_subdivision;
  588. int try_fix_nan;
  589. int gpu_index;
  590. tree *hierarchy;
  591. float *input;
  592. float *truth;
  593. float *delta;
  594. float *workspace;
  595. int train;
  596. int index;
  597. float *cost;
  598. float clip;
  599. #ifdef GPU
  600. //float *input_gpu;
  601. //float *truth_gpu;
  602. float *delta_gpu;
  603. float *output_gpu;
  604. float *input_state_gpu;
  605. float *input_pinned_cpu;
  606. int input_pinned_cpu_flag;
  607. float **input_gpu;
  608. float **truth_gpu;
  609. float **input16_gpu;
  610. float **output16_gpu;
  611. size_t *max_input16_size;
  612. size_t *max_output16_size;
  613. int wait_stream;
  614. float *global_delta_gpu;
  615. float *state_delta_gpu;
  616. size_t max_delta_gpu_size;
  617. #endif
  618. int optimized_memory;
  619. size_t workspace_size_limit;
  620. } network;
  621. // network.h
  622. typedef struct network_state {
  623. float *truth;
  624. float *input;
  625. float *delta;
  626. float *workspace;
  627. int train;
  628. int index;
  629. network net;
  630. } network_state;
  631. //typedef struct {
  632. // int w;
  633. // int h;
  634. // float scale;
  635. // float rad;
  636. // float dx;
  637. // float dy;
  638. // float aspect;
  639. //} augment_args;
  640. // image.h
  641. typedef struct image {
  642. int w;
  643. int h;
  644. int c;
  645. float *data;
  646. } image;
  647. //typedef struct {
  648. // int w;
  649. // int h;
  650. // int c;
  651. // float *data;
  652. //} image;
  653. // box.h
  654. typedef struct box {
  655. float x, y, w, h;
  656. } box;
  657. // box.h
  658. typedef struct boxabs {
  659. float left, right, top, bot;
  660. } boxabs;
  661. // box.h
  662. typedef struct dxrep {
  663. float dt, db, dl, dr;
  664. } dxrep;
  665. // box.h
  666. typedef struct ious {
  667. float iou, giou, diou, ciou;
  668. dxrep dx_iou;
  669. dxrep dx_giou;
  670. } ious;
  671. // box.h
  672. typedef struct detection{
  673. box bbox;
  674. int classes;
  675. float *prob;
  676. float *mask;
  677. float objectness;
  678. int sort_class;
  679. float *uc; // Gaussian_YOLOv3 - tx,ty,tw,th uncertainty
  680. int points; // bit-0 - center, bit-1 - top-left-corner, bit-2 - bottom-right-corner
  681. } detection;
  682. // matrix.h
  683. typedef struct matrix {
  684. int rows, cols;
  685. float **vals;
  686. } matrix;
  687. // data.h
  688. typedef struct data {
  689. int w, h;
  690. matrix X;
  691. matrix y;
  692. int shallow;
  693. int *num_boxes;
  694. box **boxes;
  695. } data;
  696. // data.h
  697. typedef enum {
  698. CLASSIFICATION_DATA, DETECTION_DATA, CAPTCHA_DATA, REGION_DATA, IMAGE_DATA, COMPARE_DATA, WRITING_DATA, SWAG_DATA, TAG_DATA, OLD_CLASSIFICATION_DATA, STUDY_DATA, DET_DATA, SUPER_DATA, LETTERBOX_DATA, REGRESSION_DATA, SEGMENTATION_DATA, INSTANCE_DATA, ISEG_DATA
  699. } data_type;
  700. // data.h
  701. typedef struct load_args {
  702. int threads;
  703. char **paths;
  704. char *path;
  705. int n;
  706. int m;
  707. char **labels;
  708. int h;
  709. int w;
  710. int c; // color depth
  711. int out_w;
  712. int out_h;
  713. int nh;
  714. int nw;
  715. int num_boxes;
  716. int min, max, size;
  717. int classes;
  718. int background;
  719. int scale;
  720. int center;
  721. int coords;
  722. int mini_batch;
  723. int track;
  724. int augment_speed;
  725. int letter_box;
  726. int show_imgs;
  727. int dontuse_opencv;
  728. float jitter;
  729. int flip;
  730. int blur;
  731. int mixup;
  732. float label_smooth_eps;
  733. float angle;
  734. float aspect;
  735. float saturation;
  736. float exposure;
  737. float hue;
  738. data *d;
  739. image *im;
  740. image *resized;
  741. data_type type;
  742. tree *hierarchy;
  743. } load_args;
  744. // data.h
  745. typedef struct box_label {
  746. int id;
  747. float x, y, w, h;
  748. float left, right, top, bottom;
  749. } box_label;
  750. // list.h
  751. //typedef struct node {
  752. // void *val;
  753. // struct node *next;
  754. // struct node *prev;
  755. //} node;
  756. // list.h
  757. //typedef struct list {
  758. // int size;
  759. // node *front;
  760. // node *back;
  761. //} list;
  762. // -----------------------------------------------------
  763. // parser.c
  764. LIB_API network *load_network(char *cfg, char *weights, int clear);
  765. LIB_API network *load_network_custom(char *cfg, char *weights, int clear, int batch);
  766. LIB_API network *load_network(char *cfg, char *weights, int clear);
  767. LIB_API void free_network(network net);
  768. // network.c
  769. LIB_API load_args get_base_args(network *net);
  770. // box.h
  771. LIB_API void do_nms_sort(detection *dets, int total, int classes, float thresh);
  772. LIB_API void do_nms_obj(detection *dets, int total, int classes, float thresh);
  773. LIB_API void diounms_sort(detection *dets, int total, int classes, float thresh, NMS_KIND nms_kind, float beta1);
  774. // network.h
  775. LIB_API float *network_predict(network net, float *input);
  776. LIB_API float *network_predict_ptr(network *net, float *input);
  777. LIB_API detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num, int letter);
  778. LIB_API void free_detections(detection *dets, int n);
  779. LIB_API void fuse_conv_batchnorm(network net);
  780. LIB_API void calculate_binary_weights(network net);
  781. LIB_API char *detection_to_json(detection *dets, int nboxes, int classes, char **names, long long int frame_id, char *filename);
  782. LIB_API layer* get_network_layer(network* net, int i);
  783. //LIB_API detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num, int letter);
  784. LIB_API detection *make_network_boxes(network *net, float thresh, int *num);
  785. LIB_API void reset_rnn(network *net);
  786. LIB_API float *network_predict_image(network *net, image im);
  787. LIB_API float *network_predict_image_letterbox(network *net, image im);
  788. LIB_API float validate_detector_map(char *datacfg, char *cfgfile, char *weightfile, float thresh_calc_avg_iou, const float iou_thresh, const int map_points, int letter_box, network *existing_net);
  789. LIB_API void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear, int dont_show, int calc_map, int mjpeg_port, int show_imgs, int benchmark_layers);
  790. LIB_API void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh,
  791. float hier_thresh, int dont_show, int ext_output, int save_labels, char *outfile, int letter_box, int benchmark_layers);
  792. LIB_API int network_width(network *net);
  793. LIB_API int network_height(network *net);
  794. LIB_API void optimize_picture(network *net, image orig, int max_layer, float scale, float rate, float thresh, int norm);
  795. // image.h
  796. LIB_API image resize_image(image im, int w, int h);
  797. LIB_API void copy_image_from_bytes(image im, char *pdata);
  798. LIB_API image letterbox_image(image im, int w, int h);
  799. LIB_API void rgbgr_image(image im);
  800. LIB_API image make_image(int w, int h, int c);
  801. LIB_API image load_image_color(char *filename, int w, int h);
  802. LIB_API void free_image(image m);
  803. // layer.h
  804. LIB_API void free_layer_custom(layer l, int keep_cudnn_desc);
  805. LIB_API void free_layer(layer l);
  806. // data.c
  807. LIB_API void free_data(data d);
  808. LIB_API pthread_t load_data(load_args args);
  809. LIB_API pthread_t load_data_in_thread(load_args args);
  810. LIB_API void *load_thread(void *ptr);
  811. // dark_cuda.h
  812. LIB_API void cuda_pull_array(float *x_gpu, float *x, size_t n);
  813. LIB_API void cuda_pull_array_async(float *x_gpu, float *x, size_t n);
  814. LIB_API void cuda_set_device(int n);
  815. LIB_API void *cuda_get_context();
  816. // utils.h
  817. LIB_API void free_ptrs(void **ptrs, int n);
  818. LIB_API void top_k(float *a, int n, int k, int *index);
  819. // tree.h
  820. LIB_API tree *read_tree(char *filename);
  821. // option_list.h
  822. LIB_API metadata get_metadata(char *file);
  823. // http_stream.h
  824. LIB_API void delete_json_sender();
  825. LIB_API void send_json_custom(char const* send_buf, int port, int timeout);
  826. LIB_API double get_time_point();
  827. void start_timer();
  828. void stop_timer();
  829. double get_time();
  830. void stop_timer_and_show();
  831. void stop_timer_and_show_name(char *name);
  832. void show_total_time();
  833. // gemm.h
  834. LIB_API void init_cpu();
  835. #ifdef __cplusplus
  836. }
  837. #endif // __cplusplus
  838. #endif // DARKNET_API