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